Skip to content
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

adding proxy setting support from env to be more like other cli's #370

Merged
merged 1 commit into from
Aug 7, 2015

Conversation

jdamick
Copy link
Contributor

@jdamick jdamick commented Aug 4, 2015

didn't added authenticated proxy support since that would be a much more intrusive change..
also i started to add a unit test, but there's no good way (that i know of) to modify the env from java without some extensive hackery - i'm open to suggestions though.

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #135 SUCCESS
This pull request looks good

@codefromthecrypt
Copy link
Contributor

was thinking about http://stefanbirkner.github.io/system-rules/ as a possibility..

@@ -426,6 +427,44 @@ void overrideFromEnv(Map<String, String> env) {
}
}

static void setProxyFromEnv() {
String envHttpProxy = System.getenv("HTTP_PROXY");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks refactorable.. I think CLI has guava (implicitly), so you can use default parsing in HostAndPort. Next, I think it is worth parameterizing the 's' so that the logic isn't completely copy/paste.

ex.

setProxyHostAndPort("http", System.getenv("HTTP_PROXY"));
setProxyHostAndPort("https", System.getenv("HTTPS_PROXY"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes will do, forgot that guava is on the cli..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codefromthecrypt
Copy link
Contributor

Thanks for giving a go! NP if my shotgun advice is a rathole :)

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #136 SUCCESS
This pull request looks good

@jdamick
Copy link
Contributor Author

jdamick commented Aug 4, 2015

refactored, but i dont think HostAndPort would really make it any more concise in this situation.. i like the system rules (going to use that in the future), but there's no help for System.getenv or setting the env unfortunately.


static void setProtocolProxyFromEnv(String proto) {
String lowerProto = Ascii.toLowerCase(proto);
String envProxy = System.getenv(Ascii.toUpperCase(proto) + "_PROXY");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you move this to a parameter, then you don't use System.getenv inside this method. That makes it testable with system rules!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ex.
Advice on test.

the happy path test asserts that System.getProperty returns valid host and port, and host and default port

the failure test asserts that System.exit was called and that System.err message logged.

http://stefanbirkner.github.io/system-rules/

// use this to reset the system rules.
@Rule
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();

// Use this to make sure the message logged
@Rule
public final SystemErrRule systemErrRule = new SystemErrRule().enableLog();

// use this to test exit occurred on malformed
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good idea, will fix

@codefromthecrypt
Copy link
Contributor

lemme know if testing is too much a bear.. I can refactor and help out if so.

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #137 SUCCESS
This pull request looks good

@jdamick
Copy link
Contributor Author

jdamick commented Aug 5, 2015

that framework is great, thanks for suggestion

setProtocolProxyFromEnv("https");
}

void setProtocolProxyFromEnv(String proto) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this static and life gets sooo easy. just call it directly!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like..

private static void setProxyFromEnv() { // static cause not needed to be not-static :P
  setProtocolProxy("http", System.getEnv("HTTP_PROXY"));
  setProtocolProxy("https", System.getEnv("HTTPS_PROXY"));
}

// call DenominatorCmd.setProtocolProxy("https", "https://10.0.0.1:8989") directly in tests
// visible for testing
static void setProtocolProxy(String scheme, nullableUrl) {

@codefromthecrypt
Copy link
Contributor

I like the idea of end-to-end, but I think the subclassing thing makes it harder to understand the key change. How about just calling the static method and verifying behavior with the rules you've already got?

@jdamick
Copy link
Contributor Author

jdamick commented Aug 6, 2015

I can revert back to how it was before but I do like the fact it is fully tested now. If I make it static I can't fake the env properties easily.

@jdamick
Copy link
Contributor Author

jdamick commented Aug 6, 2015

Ok I think I misread one of the comments..

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Aug 6, 2015 via email

@jdamick
Copy link
Contributor Author

jdamick commented Aug 7, 2015

sorry i fixed it right away, just had limited connectivity..

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #138 SUCCESS
This pull request looks good

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #139 SUCCESS
This pull request looks good

@@ -80,12 +34,27 @@
import denominator.ultradns.UltraDNSProvider;
import feign.Logger;
import feign.Logger.Level;
import io.airlift.airline.Cli;
import io.airlift.airline.*;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aww, jeez intelij

@jdamick
Copy link
Contributor Author

jdamick commented Aug 7, 2015

intelij messed up imports, should be right now.

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #140 SUCCESS
This pull request looks good

@codefromthecrypt
Copy link
Contributor

sorry to say it, but imports are still the majority of this change :P

along with unit tests
didn't added authenticated proxy support since that would be a much more intrusive change..
@codefromthecrypt
Copy link
Contributor

coolio! Thanks tons, Jeff. Will merge on green.

@cloudbees-pull-request-builder

NetflixOSS » denominator » denominator-pull-requests #141 SUCCESS
This pull request looks good

codefromthecrypt pushed a commit that referenced this pull request Aug 7, 2015
adding proxy setting support from env to be more like other cli's
@codefromthecrypt codefromthecrypt merged commit 92a77df into Netflix:master Aug 7, 2015
@codefromthecrypt codefromthecrypt added this to the 4.7.0 milestone Aug 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants