Add https-proxy param + fix proxy authorization header (#888)
Co-authored-by: dotasek <david.otasek@smilecdr.com>
This commit is contained in:
parent
bb8775bfdb
commit
82972d5216
|
@ -13,6 +13,7 @@ import org.hl7.fhir.dstu3.utils.client.EFhirClientException;
|
|||
import org.hl7.fhir.dstu3.utils.client.ResourceFormat;
|
||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -153,12 +154,7 @@ public class FhirRequestBuilder {
|
|||
okHttpClient = new OkHttpClient();
|
||||
}
|
||||
|
||||
Authenticator proxyAuthenticator = (route, response) -> {
|
||||
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
|
||||
return response.request().newBuilder()
|
||||
.header(HEADER_PROXY_AUTH, credential)
|
||||
.build();
|
||||
};
|
||||
Authenticator proxyAuthenticator = getAuthenticator();
|
||||
|
||||
return okHttpClient.newBuilder()
|
||||
.addInterceptor(new RetryInterceptor(retryCount))
|
||||
|
@ -169,6 +165,21 @@ public class FhirRequestBuilder {
|
|||
.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) {
|
||||
this.resourceFormat = resourceFormat;
|
||||
return this;
|
||||
|
|
|
@ -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.ResourceFormat;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -151,12 +152,7 @@ public class FhirRequestBuilder {
|
|||
okHttpClient = new OkHttpClient();
|
||||
}
|
||||
|
||||
Authenticator proxyAuthenticator = (route, response) -> {
|
||||
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
|
||||
return response.request().newBuilder()
|
||||
.header(HEADER_PROXY_AUTH, credential)
|
||||
.build();
|
||||
};
|
||||
Authenticator proxyAuthenticator = getAuthenticator();
|
||||
|
||||
OkHttpClient.Builder builder = okHttpClient.newBuilder();
|
||||
if (logger != null) builder.addInterceptor(logger);
|
||||
|
@ -171,6 +167,21 @@ public class FhirRequestBuilder {
|
|||
.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) {
|
||||
this.resourceFormat = resourceFormat;
|
||||
return this;
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.hl7.fhir.r4b.utils.client.EFhirClientException;
|
|||
import org.hl7.fhir.r4b.utils.client.ResourceFormat;
|
||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -154,12 +155,7 @@ public class FhirRequestBuilder {
|
|||
okHttpClient = new OkHttpClient();
|
||||
}
|
||||
|
||||
Authenticator proxyAuthenticator = (route, response) -> {
|
||||
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
|
||||
return response.request().newBuilder()
|
||||
.header(HEADER_PROXY_AUTH, credential)
|
||||
.build();
|
||||
};
|
||||
Authenticator proxyAuthenticator = getAuthenticator();
|
||||
|
||||
OkHttpClient.Builder builder = okHttpClient.newBuilder();
|
||||
if (logger != null) builder.addInterceptor(logger);
|
||||
|
@ -172,6 +168,21 @@ public class FhirRequestBuilder {
|
|||
.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) {
|
||||
this.resourceFormat = resourceFormat;
|
||||
return this;
|
||||
|
|
|
@ -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.ResourceFormat;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -151,12 +152,7 @@ public class FhirRequestBuilder {
|
|||
okHttpClient = new OkHttpClient();
|
||||
}
|
||||
|
||||
Authenticator proxyAuthenticator = (route, response) -> {
|
||||
String credential = Credentials.basic(System.getProperty(HTTP_PROXY_USER), System.getProperty(HTTP_PROXY_PASS));
|
||||
return response.request().newBuilder()
|
||||
.header(HEADER_PROXY_AUTH, credential)
|
||||
.build();
|
||||
};
|
||||
Authenticator proxyAuthenticator = getAuthenticator();
|
||||
|
||||
OkHttpClient.Builder builder = okHttpClient.newBuilder();
|
||||
if (logger != null) builder.addInterceptor(logger);
|
||||
|
@ -168,6 +164,21 @@ public class FhirRequestBuilder {
|
|||
.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) {
|
||||
this.resourceFormat = resourceFormat;
|
||||
return this;
|
||||
|
|
|
@ -99,6 +99,10 @@ public class ValidatorCli {
|
|||
|
||||
public static final String HTTP_PROXY_HOST = "http.proxyHost";
|
||||
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_PASS = "http.proxyPassword";
|
||||
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.Session tts = tt.start("Loading");
|
||||
|
||||
args = preProcessArgs(args);
|
||||
|
||||
args = addAdditionalParamsForIpsParam(args);
|
||||
setJavaSystemProxyParamsFromParams(args);
|
||||
|
||||
Display.displayVersion();
|
||||
Display.displaySystemInfo();
|
||||
|
||||
if (Params.hasParam(args, Params.PROXY)) {
|
||||
assert Params.getParam(args, Params.PROXY) != null : "PROXY arg passed in was NULL";
|
||||
String[] p = Params.getParam(args, Params.PROXY).split(":");
|
||||
System.setProperty(HTTP_PROXY_HOST, p[0]);
|
||||
System.setProperty(HTTP_PROXY_PORT, p[1]);
|
||||
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);
|
||||
}
|
||||
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)) {
|
||||
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_PROXY_SCHEMES, "");
|
||||
}
|
||||
}
|
||||
|
||||
CliContext cliContext = Params.loadCliContext(args);
|
||||
private static void setJavaSystemProxyHostFromParams(String[] args, String proxyParam, String proxyHostProperty, String proxyPortProperty) {
|
||||
if (Params.hasParam(args, proxyParam)) {
|
||||
assert Params.getParam(args, proxyParam) != null : "PROXY arg passed in was NULL";
|
||||
String[] p = Params.getParam(args, proxyParam).split(":");
|
||||
|
||||
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);
|
||||
}
|
||||
else {
|
||||
Display.printCliArgumentsAndInfo(args);
|
||||
doValidation(tt, tts, cliContext);
|
||||
System.setProperty(proxyHostProperty, p[0]);
|
||||
System.setProperty(proxyPortProperty, p[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +203,7 @@ public class ValidatorCli {
|
|||
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
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String a : args) {
|
||||
|
|
|
@ -20,6 +20,8 @@ public class Params {
|
|||
public static final String LEVEL = "-level";
|
||||
public static final String HTML_OUTPUT = "-html-output";
|
||||
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 PROFILE = "-profile";
|
||||
public static final String BUNDLE = "-bundle";
|
||||
|
@ -136,7 +138,10 @@ public class Params {
|
|||
i++; // ignore next parameter
|
||||
} else if (args[i].equals(PROXY_AUTH)) {
|
||||
i++;
|
||||
} else if (args[i].equals(PROFILE)) {
|
||||
} else if (args[i].equals(HTTPS_PROXY)) {
|
||||
i++;
|
||||
}
|
||||
else if (args[i].equals(PROFILE)) {
|
||||
String p = null;
|
||||
if (i + 1 == args.length) {
|
||||
throw new Error("Specified -profile without indicating profile source");
|
||||
|
|
Loading…
Reference in New Issue