Add https-proxy param + fix proxy authorization header (#888)

Co-authored-by: dotasek <david.otasek@smilecdr.com>
This commit is contained in:
dotasek 2022-11-17 11:27:21 -05:00 committed by GitHub
parent bb8775bfdb
commit 82972d5216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 48 deletions

View File

@ -13,6 +13,7 @@ import org.hl7.fhir.dstu3.utils.client.EFhirClientException;
import org.hl7.fhir.dstu3.utils.client.ResourceFormat; import org.hl7.fhir.dstu3.utils.client.ResourceFormat;
import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.ToolingClientLogger;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -153,12 +154,7 @@ public class FhirRequestBuilder {
okHttpClient = new OkHttpClient(); okHttpClient = new OkHttpClient();
} }
Authenticator proxyAuthenticator = (route, response) -> { Authenticator proxyAuthenticator = getAuthenticator();
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
};
return okHttpClient.newBuilder() return okHttpClient.newBuilder()
.addInterceptor(new RetryInterceptor(retryCount)) .addInterceptor(new RetryInterceptor(retryCount))
@ -169,6 +165,21 @@ public class FhirRequestBuilder {
.build(); .build();
} }
@Nonnull
private static Authenticator getAuthenticator() {
return (route, response) -> {
final String httpProxyUser = System.getProperty(HTTP_PROXY_USER);
final String httpProxyPass = System.getProperty(HTTP_PROXY_PASS);
if (httpProxyUser != null && httpProxyPass != null) {
String credential = Credentials.basic(httpProxyUser, httpProxyPass);
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
}
return response.request().newBuilder().build();
};
}
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
this.resourceFormat = resourceFormat; this.resourceFormat = resourceFormat;
return this; return this;

View File

@ -12,6 +12,7 @@ import org.hl7.fhir.r4.utils.ResourceUtilities;
import org.hl7.fhir.r4.utils.client.EFhirClientException; import org.hl7.fhir.r4.utils.client.EFhirClientException;
import org.hl7.fhir.r4.utils.client.ResourceFormat; import org.hl7.fhir.r4.utils.client.ResourceFormat;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -151,12 +152,7 @@ public class FhirRequestBuilder {
okHttpClient = new OkHttpClient(); okHttpClient = new OkHttpClient();
} }
Authenticator proxyAuthenticator = (route, response) -> { Authenticator proxyAuthenticator = getAuthenticator();
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
};
OkHttpClient.Builder builder = okHttpClient.newBuilder(); OkHttpClient.Builder builder = okHttpClient.newBuilder();
if (logger != null) builder.addInterceptor(logger); if (logger != null) builder.addInterceptor(logger);
@ -171,6 +167,21 @@ public class FhirRequestBuilder {
.build(); .build();
} }
@Nonnull
private static Authenticator getAuthenticator() {
return (route, response) -> {
final String httpProxyUser = System.getProperty(HTTP_PROXY_USER);
final String httpProxyPass = System.getProperty(HTTP_PROXY_PASS);
if (httpProxyUser != null && httpProxyPass != null) {
String credential = Credentials.basic(httpProxyUser, httpProxyPass);
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
}
return response.request().newBuilder().build();
};
}
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
this.resourceFormat = resourceFormat; this.resourceFormat = resourceFormat;
return this; return this;

View File

@ -13,6 +13,7 @@ import org.hl7.fhir.r4b.utils.client.EFhirClientException;
import org.hl7.fhir.r4b.utils.client.ResourceFormat; import org.hl7.fhir.r4b.utils.client.ResourceFormat;
import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.ToolingClientLogger;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -154,12 +155,7 @@ public class FhirRequestBuilder {
okHttpClient = new OkHttpClient(); okHttpClient = new OkHttpClient();
} }
Authenticator proxyAuthenticator = (route, response) -> { Authenticator proxyAuthenticator = getAuthenticator();
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
};
OkHttpClient.Builder builder = okHttpClient.newBuilder(); OkHttpClient.Builder builder = okHttpClient.newBuilder();
if (logger != null) builder.addInterceptor(logger); if (logger != null) builder.addInterceptor(logger);
@ -172,6 +168,21 @@ public class FhirRequestBuilder {
.build(); .build();
} }
@Nonnull
private static Authenticator getAuthenticator() {
return (route, response) -> {
final String httpProxyUser = System.getProperty(HTTP_PROXY_USER);
final String httpProxyPass = System.getProperty(HTTP_PROXY_PASS);
if (httpProxyUser != null && httpProxyPass != null) {
String credential = Credentials.basic(httpProxyUser, httpProxyPass);
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
}
return response.request().newBuilder().build();
};
}
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
this.resourceFormat = resourceFormat; this.resourceFormat = resourceFormat;
return this; return this;

View File

@ -12,6 +12,7 @@ import org.hl7.fhir.r5.utils.ResourceUtilities;
import org.hl7.fhir.r5.utils.client.EFhirClientException; import org.hl7.fhir.r5.utils.client.EFhirClientException;
import org.hl7.fhir.r5.utils.client.ResourceFormat; import org.hl7.fhir.r5.utils.client.ResourceFormat;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -151,12 +152,7 @@ public class FhirRequestBuilder {
okHttpClient = new OkHttpClient(); okHttpClient = new OkHttpClient();
} }
Authenticator proxyAuthenticator = (route, response) -> { Authenticator proxyAuthenticator = getAuthenticator();
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
};
OkHttpClient.Builder builder = okHttpClient.newBuilder(); OkHttpClient.Builder builder = okHttpClient.newBuilder();
if (logger != null) builder.addInterceptor(logger); if (logger != null) builder.addInterceptor(logger);
@ -168,6 +164,21 @@ public class FhirRequestBuilder {
.build(); .build();
} }
@Nonnull
private static Authenticator getAuthenticator() {
return (route, response) -> {
final String httpProxyUser = System.getProperty(HTTP_PROXY_USER);
final String httpProxyPass = System.getProperty(HTTP_PROXY_PASS);
if (httpProxyUser != null && httpProxyPass != null) {
String credential = Credentials.basic(httpProxyUser, httpProxyPass);
return response.request().newBuilder()
.header(HEADER_PROXY_AUTH, credential)
.build();
}
return response.request().newBuilder().build();
};
}
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
this.resourceFormat = resourceFormat; this.resourceFormat = resourceFormat;
return this; return this;

View File

@ -99,6 +99,10 @@ public class ValidatorCli {
public static final String HTTP_PROXY_HOST = "http.proxyHost"; public static final String HTTP_PROXY_HOST = "http.proxyHost";
public static final String HTTP_PROXY_PORT = "http.proxyPort"; public static final String HTTP_PROXY_PORT = "http.proxyPort";
public static final String HTTPS_PROXY_HOST = "https.proxyHost";
public static final String HTTPS_PROXY_PORT = "https.proxyPort";
public static final String HTTP_PROXY_USER = "http.proxyUser"; public static final String HTTP_PROXY_USER = "http.proxyUser";
public static final String HTTP_PROXY_PASS = "http.proxyPassword"; public static final String HTTP_PROXY_PASS = "http.proxyPassword";
public static final String JAVA_DISABLED_TUNNELING_SCHEMES = "jdk.http.auth.tunneling.disabledSchemes"; public static final String JAVA_DISABLED_TUNNELING_SCHEMES = "jdk.http.auth.tunneling.disabledSchemes";
@ -111,17 +115,34 @@ public class ValidatorCli {
TimeTracker tt = new TimeTracker(); TimeTracker tt = new TimeTracker();
TimeTracker.Session tts = tt.start("Loading"); TimeTracker.Session tts = tt.start("Loading");
args = preProcessArgs(args); args = addAdditionalParamsForIpsParam(args);
setJavaSystemProxyParamsFromParams(args);
Display.displayVersion(); Display.displayVersion();
Display.displaySystemInfo(); Display.displaySystemInfo();
if (Params.hasParam(args, Params.PROXY)) { CliContext cliContext = Params.loadCliContext(args);
assert Params.getParam(args, Params.PROXY) != null : "PROXY arg passed in was NULL"; FileFormat.checkCharsetAndWarnIfNotUTF8(System.out);
String[] p = Params.getParam(args, Params.PROXY).split(":");
System.setProperty(HTTP_PROXY_HOST, p[0]); if (shouldDisplayHelpToUser(args)) {
System.setProperty(HTTP_PROXY_PORT, p[1]); Display.displayHelpDetails();
} else if (Params.hasParam(args, Params.COMPARE)) {
if (destinationDirectoryValid(Params.getParam(args, Params.DESTINATION))) {
doLeftRightComparison(args, cliContext, tt);
} }
} else if (Params.hasParam(args, Params.TEST)) {
parseTestParamsAndExecute(args);
}
else {
Display.printCliArgumentsAndInfo(args);
doValidation(tt, tts, cliContext);
}
}
private static void setJavaSystemProxyParamsFromParams(String[] args) {
setJavaSystemProxyHostFromParams(args, Params.PROXY, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
setJavaSystemProxyHostFromParams(args, Params.HTTPS_PROXY, HTTPS_PROXY_HOST, HTTPS_PROXY_PORT);
if (Params.hasParam(args, Params.PROXY_AUTH)) { if (Params.hasParam(args, Params.PROXY_AUTH)) {
assert Params.getParam(args, Params.PROXY) != null : "Cannot set PROXY_AUTH without setting PROXY..."; assert Params.getParam(args, Params.PROXY) != null : "Cannot set PROXY_AUTH without setting PROXY...";
@ -155,23 +176,15 @@ public class ValidatorCli {
System.setProperty(JAVA_DISABLED_TUNNELING_SCHEMES, ""); System.setProperty(JAVA_DISABLED_TUNNELING_SCHEMES, "");
System.setProperty(JAVA_DISABLED_PROXY_SCHEMES, ""); System.setProperty(JAVA_DISABLED_PROXY_SCHEMES, "");
} }
CliContext cliContext = Params.loadCliContext(args);
FileFormat.checkCharsetAndWarnIfNotUTF8(System.out);
if (shouldDisplayHelpToUser(args)) {
Display.displayHelpDetails();
} else if (Params.hasParam(args, Params.COMPARE)) {
if (destinationDirectoryValid(Params.getParam(args, Params.DESTINATION))) {
doLeftRightComparison(args, cliContext, tt);
} }
} else if (Params.hasParam(args, Params.TEST)) {
parseTestParamsAndExecute(args); private static void setJavaSystemProxyHostFromParams(String[] args, String proxyParam, String proxyHostProperty, String proxyPortProperty) {
} if (Params.hasParam(args, proxyParam)) {
else { assert Params.getParam(args, proxyParam) != null : "PROXY arg passed in was NULL";
Display.printCliArgumentsAndInfo(args); String[] p = Params.getParam(args, proxyParam).split(":");
doValidation(tt, tts, cliContext);
System.setProperty(proxyHostProperty, p[0]);
System.setProperty(proxyPortProperty, p[1]);
} }
} }
@ -190,7 +203,7 @@ public class ValidatorCli {
System.exit(0); System.exit(0);
} }
private static String[] preProcessArgs(String[] args) { private static String[] addAdditionalParamsForIpsParam(String[] args) {
// ips$branch --> -version 4.0 -ig hl7.fhir.uv.ips#current$connectathon-2 -profile http://hl7.org/fhir/uv/ips/StructureDefinition/Bundle-uv-ips // ips$branch --> -version 4.0 -ig hl7.fhir.uv.ips#current$connectathon-2 -profile http://hl7.org/fhir/uv/ips/StructureDefinition/Bundle-uv-ips
List<String> res = new ArrayList<>(); List<String> res = new ArrayList<>();
for (String a : args) { for (String a : args) {

View File

@ -20,6 +20,8 @@ public class Params {
public static final String LEVEL = "-level"; public static final String LEVEL = "-level";
public static final String HTML_OUTPUT = "-html-output"; public static final String HTML_OUTPUT = "-html-output";
public static final String PROXY = "-proxy"; public static final String PROXY = "-proxy";
public static final String HTTPS_PROXY = "-https-proxy";
public static final String PROXY_AUTH = "-auth"; public static final String PROXY_AUTH = "-auth";
public static final String PROFILE = "-profile"; public static final String PROFILE = "-profile";
public static final String BUNDLE = "-bundle"; public static final String BUNDLE = "-bundle";
@ -136,7 +138,10 @@ public class Params {
i++; // ignore next parameter i++; // ignore next parameter
} else if (args[i].equals(PROXY_AUTH)) { } else if (args[i].equals(PROXY_AUTH)) {
i++; i++;
} else if (args[i].equals(PROFILE)) { } else if (args[i].equals(HTTPS_PROXY)) {
i++;
}
else if (args[i].equals(PROFILE)) {
String p = null; String p = null;
if (i + 1 == args.length) { if (i + 1 == args.length) {
throw new Error("Specified -profile without indicating profile source"); throw new Error("Specified -profile without indicating profile source");