forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configurations for allowed protocols for HTTP and HDFS inputSourc…
…es/firehoses (apache#10830) * Allow only HTTP and HTTPS protocols for the HTTP inputSource * rename * Update core/src/main/java/org/apache/druid/data/input/impl/HttpInputSource.java Co-authored-by: Abhishek Agarwal <[email protected]> * fix http firehose and update doc * HDFS inputSource * add configs for allowed protocols * fix checkstyle and doc * more checkstyle * remove stale doc * remove more doc * Apply doc suggestions from code review Co-authored-by: Charles Smith <[email protected]> * update hdfs address in docs * fix test Co-authored-by: Abhishek Agarwal <[email protected]> Co-authored-by: Charles Smith <[email protected]>
- Loading branch information
1 parent
bddacbb
commit 9946306
Showing
18 changed files
with
878 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/src/main/java/org/apache/druid/data/input/impl/HttpInputSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.data.input.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableSet; | ||
import org.apache.druid.java.util.common.StringUtils; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class HttpInputSourceConfig | ||
{ | ||
@VisibleForTesting | ||
public static final Set<String> DEFAULT_ALLOWED_PROTOCOLS = ImmutableSet.of("http", "https"); | ||
|
||
@JsonProperty | ||
private final Set<String> allowedProtocols; | ||
|
||
@JsonCreator | ||
public HttpInputSourceConfig( | ||
@JsonProperty("allowedProtocols") @Nullable Set<String> allowedProtocols | ||
) | ||
{ | ||
this.allowedProtocols = allowedProtocols == null || allowedProtocols.isEmpty() | ||
? DEFAULT_ALLOWED_PROTOCOLS | ||
: allowedProtocols.stream().map(StringUtils::toLowerCase).collect(Collectors.toSet()); | ||
} | ||
|
||
public Set<String> getAllowedProtocols() | ||
{ | ||
return allowedProtocols; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
HttpInputSourceConfig that = (HttpInputSourceConfig) o; | ||
return Objects.equals(allowedProtocols, that.allowedProtocols); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(allowedProtocols); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "HttpInputSourceConfig{" + | ||
", allowedProtocols=" + allowedProtocols + | ||
'}'; | ||
} | ||
} | ||
|
56 changes: 56 additions & 0 deletions
56
core/src/test/java/org/apache/druid/data/input/impl/HttpInputSourceConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.data.input.impl; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class HttpInputSourceConfigTest | ||
{ | ||
|
||
@Test | ||
public void testEquals() | ||
{ | ||
EqualsVerifier.forClass(HttpInputSourceConfig.class).usingGetClass().verify(); | ||
} | ||
|
||
@Test | ||
public void testNullAllowedProtocolsUseDefault() | ||
{ | ||
HttpInputSourceConfig config = new HttpInputSourceConfig(null); | ||
Assert.assertEquals(HttpInputSourceConfig.DEFAULT_ALLOWED_PROTOCOLS, config.getAllowedProtocols()); | ||
} | ||
|
||
@Test | ||
public void testEmptyAllowedProtocolsUseDefault() | ||
{ | ||
HttpInputSourceConfig config = new HttpInputSourceConfig(ImmutableSet.of()); | ||
Assert.assertEquals(HttpInputSourceConfig.DEFAULT_ALLOWED_PROTOCOLS, config.getAllowedProtocols()); | ||
} | ||
|
||
@Test | ||
public void testCustomAllowedProtocols() | ||
{ | ||
HttpInputSourceConfig config = new HttpInputSourceConfig(ImmutableSet.of("druid")); | ||
Assert.assertEquals(ImmutableSet.of("druid"), config.getAllowedProtocols()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.