-
Notifications
You must be signed in to change notification settings - Fork 30
Add HttpProxy option #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc610f5
Add HttpProxy config unit
muga 60380e9
Use HttpProxy
muga 5fea602
Minor fix HttpProxy
muga db7dd87
Add unit tests for HttpProxy
muga d4bbee7
Rename several methods for HttpProxy
muga 326407e
Fix HttpProxy: not parse and create HttpProxy from environment variab…
muga dd8bb78
Rename http_proxy.use_ssl option with https
muga 5d5b883
Remove HttpProxy.createHttpProxyFromEnv
muga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
60 changes: 60 additions & 0 deletions
60
embulk-input-s3/src/main/java/org/embulk/input/s3/HttpProxy.java
This file contains hidden or 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,60 @@ | ||
| package org.embulk.input.s3; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Optional; | ||
|
|
||
| /** | ||
| * HttpProxy is config unit for Input/Output plugins' configs. | ||
| * | ||
| * TODO | ||
| * This unit will be moved to embulk/embulk-plugin-units.git. | ||
| */ | ||
| public class HttpProxy | ||
| { | ||
| private final String host; | ||
| private final Optional<Integer> port; | ||
| private final boolean https; | ||
| private final Optional<String> user; | ||
| private final Optional<String> password; // TODO use SecretString | ||
|
|
||
| @JsonCreator | ||
| public HttpProxy( | ||
| @JsonProperty("host") String host, | ||
| @JsonProperty("port") Optional<Integer> port, | ||
| @JsonProperty("https") boolean https, | ||
| @JsonProperty("user") Optional<String> user, | ||
| @JsonProperty("password") Optional<String> password) | ||
| { | ||
| this.host = host; | ||
| this.port = port; | ||
| this.https = https; | ||
| this.user = user; | ||
| this.password = password; | ||
| } | ||
|
|
||
| public String getHost() | ||
| { | ||
| return host; | ||
| } | ||
|
|
||
| public Optional<Integer> getPort() | ||
| { | ||
| return port; | ||
| } | ||
|
|
||
| public boolean useHttps() | ||
| { | ||
| return https; | ||
| } | ||
|
|
||
| public Optional<String> getUser() | ||
| { | ||
| return user; | ||
| } | ||
|
|
||
| public Optional<String> getPassword() | ||
| { | ||
| return password; | ||
| } | ||
| } |
112 changes: 112 additions & 0 deletions
112
embulk-input-s3/src/test/java/org/embulk/input/s3/TestHttpProxy.java
This file contains hidden or 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,112 @@ | ||
| package org.embulk.input.s3; | ||
|
|
||
| import com.google.common.base.Optional; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import org.embulk.EmbulkTestRuntime; | ||
| import org.embulk.config.ConfigSource; | ||
| import org.embulk.input.s3.S3FileInputPlugin.S3PluginTask; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
||
| import java.net.URISyntaxException; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| public class TestHttpProxy | ||
| { | ||
| @Rule | ||
| public EmbulkTestRuntime runtime = new EmbulkTestRuntime(); | ||
|
|
||
| private ConfigSource config; | ||
|
|
||
| @Before | ||
| public void createResources() | ||
| { | ||
| config = runtime.getExec().newConfigSource(); | ||
| setupS3Config(config); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkDefaultHttpProxy() | ||
| { | ||
| ConfigSource conf = config.deepCopy(); | ||
| setupS3Config(conf); | ||
| S3PluginTask task = conf.loadConfig(S3PluginTask.class); | ||
| assertTrue(!task.getHttpProxy().isPresent()); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkHttpProxy() | ||
| { | ||
| { // specify host | ||
| String host = "my_host"; | ||
| Map<String, Object> httpProxyMap = ImmutableMap.<String, Object>of("host", host); | ||
| ConfigSource conf = config.deepCopy().set("http_proxy", httpProxyMap); | ||
| S3PluginTask task = conf.loadConfig(S3PluginTask.class); | ||
|
|
||
| assertHttpProxy(new HttpProxy(host, Optional.<Integer>absent(), false, Optional.<String>absent(), Optional.<String>absent()), | ||
| task.getHttpProxy().get()); | ||
| } | ||
|
|
||
| { // specify host, port, use_ssl | ||
| String host = "my_host"; | ||
| int port = 8080; | ||
| boolean useSsl = true; | ||
| Map<String, Object> httpProxyMap = ImmutableMap.<String, Object>of( | ||
| "host", host, | ||
| "port", 8080, | ||
| "https", true); | ||
| ConfigSource conf = config.deepCopy().set("http_proxy", httpProxyMap); | ||
| S3PluginTask task = conf.loadConfig(S3PluginTask.class); | ||
|
|
||
| assertHttpProxy(new HttpProxy(host, Optional.of(port), true, Optional.<String>absent(), Optional.<String>absent()), | ||
| task.getHttpProxy().get()); | ||
| } | ||
|
|
||
| { // specify host, port, use_ssl, user, password | ||
| String host = "my_host"; | ||
| int port = 8080; | ||
| boolean useSsl = true; | ||
| String user = "my_user"; | ||
| String password = "my_pass"; | ||
| Map<String, Object> httpProxyMap = ImmutableMap.<String, Object>of( | ||
| "host", host, | ||
| "port", 8080, | ||
| "https", true, | ||
| "user", user, | ||
| "password", password); | ||
| ConfigSource conf = config.deepCopy().set("http_proxy", httpProxyMap); | ||
| S3PluginTask task = conf.loadConfig(S3PluginTask.class); | ||
|
|
||
| assertHttpProxy(new HttpProxy(host, Optional.of(port), true, Optional.of(user), Optional.of(password)), | ||
| task.getHttpProxy().get()); | ||
| } | ||
| } | ||
|
|
||
| private static void setupS3Config(ConfigSource config) | ||
| { | ||
| config.set("bucket", "my_bucket").set("path_prefix", "my_path_prefix"); | ||
| } | ||
|
|
||
| private static void assertHttpProxy(HttpProxy expected, HttpProxy actual) | ||
| { | ||
| assertEquals(expected.getHost(), actual.getHost()); | ||
| assertEquals(expected.getPort().isPresent(), actual.getPort().isPresent()); | ||
| if (expected.getPort().isPresent()) { | ||
| assertEquals(expected.getPort().get(), actual.getPort().get()); | ||
| } | ||
| assertEquals(expected.useHttps(), actual.useHttps()); | ||
| assertEquals(expected.getUser().isPresent(), actual.getUser().isPresent()); | ||
| if (expected.getUser().isPresent()) { | ||
| assertEquals(expected.getUser().get(), actual.getUser().get()); | ||
| } | ||
| assertEquals(expected.getPassword().isPresent(), actual.getPassword().isPresent()); | ||
| if (expected.getPassword().isPresent()) { | ||
| assertEquals(expected.getPassword().get(), actual.getPassword().get()); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question: How users should configure when they don't want any HTTP proxy for Embulk while the env
HTTP_PROXYis set?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR doesn't support it. If they want, they need to unset env
HTTP_PROXYfor Embulk and embulk-input-s3 for now.I think that we could take one of the following approaches.
HTTP_PROXYHttpProxyfrom env variables specified by usersHttpProxyfrom env variables.1st one was OK for me. I'm not confident that such requests are really minor but, how about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried that it can be a kind of compatibility issue. If a user has been setting the HTTP_PROXY env so far, this change may break their behavior.
I thought the best option can be eventually 2. What do you think about taking 3 for the time being, and implementing 2 later?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I will fix this by 3rd one.
As another idea, how about introducing new
EMBULK_HTTP_PROXYenv? If users can configure http proxy for Embulk as this en. The name is reasonable for us. Because we don't need to care of the compatibility issues so much. If no problem, I will care of this when this HttpProxy is moved to embulk/embulk-util-config.git.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 326407e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should introduce new standards in environment variables. No one will get benefits with the new env.
It's still a design choice we should have a kind of "default" envs to use. I'm personally -1 on defaults. My idea is just to receive a new
envconfiguration such as :Even if it has a kind of default like below, the benefit of users are very small. Users save just ~10 key types in making a configuration. Is it really a benefit?
I believe users achieve more benefits by the proxy configuration is always explicit and clear. They won't be confused any implicit configurations they're unaware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your thoughts. I think that it's good to have both of your env option and default env. The default
envis helped for the following use cases.in:andout:. It's better to separate the configuration from others.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so to be honest. If users are typing their configurations every runtime, it may be useful to skip typing such
envconfigurations. But, it's just per making configurations. Does this really matter? Users can utilize Liquid templates as well.I agree that the benefits are not zero, but I think the risk is larger by that default proxy configuration.
HttpProxyclass for many plugins, but our encourage will not cover all.HttpProxyis just a tooling. Implicit configurations may cause confusions especially when used with third-party non-HttpProxyplugins.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I changed my mind. Because my suggestion is not very good for this layer. I will introduce
envoption but, not on this PR. It will be implemented on https://github.com/embulk/embulk-util-config