Merge pull request #2783 from hapifhir/2777-hapi-fhir-cli-Add-option-to-pass-request-headers-to-target-server

Add changelog. Address MR comments.
This commit is contained in:
Tadgh 2021-07-09 09:35:56 -04:00 committed by GitHub
commit 0a27b08aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 64 deletions

View File

@ -83,15 +83,15 @@ public class ValidationResult {
StringBuilder b = new StringBuilder(100 * myMessages.size()); StringBuilder b = new StringBuilder(100 * myMessages.size());
int shownMsgQty = Math.min(myErrorDisplayLimit, myMessages.size()); int shownMsgQty = Math.min(myErrorDisplayLimit, myMessages.size());
if (shownMsgQty < myMessages.size()) {
b.append("(showing first ").append(shownMsgQty).append(" messages out of ")
.append(myMessages.size()).append(" total)").append(ourNewLine);
}
for (int i = 0; i < shownMsgQty; i++) { for (int i = 0; i < shownMsgQty; i++) {
SingleValidationMessage nextMsg = myMessages.get(i); SingleValidationMessage nextMsg = myMessages.get(i);
b.append(ourNewLine); b.append(ourNewLine);
if (i == 0) {
if (shownMsgQty < myMessages.size()) {
b.append("(showing first ").append(shownMsgQty).append(" messages out of ")
.append(myMessages.size()).append(" total)").append(ourNewLine);
}
}
if (nextMsg.getSeverity() != null) { if (nextMsg.getSeverity() != null) {
b.append(nextMsg.getSeverity().name()); b.append(nextMsg.getSeverity().name());
b.append(" - "); b.append(" - ");

View File

@ -115,7 +115,7 @@ public abstract class BaseRequestGeneratingCommand extends BaseCommand {
/** /**
* @return Returns the optional pass-through header name and value * @return Returns the optional pass-through header name and value
*/ */
protected Map<String, List<String>> getAndParseOptionHeadersPassthrough( private Map<String, List<String>> getAndParseOptionHeadersPassthrough(
CommandLine theCommandLine, String theOptionName) throws ParseException { CommandLine theCommandLine, String theOptionName) throws ParseException {
if (! theCommandLine.hasOption(theOptionName)) { if (! theCommandLine.hasOption(theOptionName)) {

View File

@ -1,23 +1,33 @@
package ca.uhn.fhir.cli; package ca.uhn.fhir.cli;
import ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import java.security.InvalidParameterException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASIC_AUTH;
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH;
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION;
import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class BaseRequestGeneratingCommandTest { class BaseRequestGeneratingCommandTest {
private final BaseRequestGeneratingCommand tested = new BaseRequestGeneratingCommandChild(); private final BaseRequestGeneratingCommand tested = new BaseRequestGeneratingCommandChild();
private final List<BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions> allOptions = private final List<BaseRequestGeneratingCommandOptions> allOptions =
Arrays.asList(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values()); Arrays.asList(values());
@Test @Test
void getOptions() { void getOptions() {
@ -31,70 +41,59 @@ class BaseRequestGeneratingCommandTest {
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
} }
@Test @ParameterizedTest(name = "Excluding {0}")
void getSomeOptionsNoVersion() { @EnumSource(value = BaseRequestGeneratingCommandOptions.class,
Options options = tested.getSomeOptions( names = {"VERSION", "BASE_URL", "BASIC_AUTH", "VERBOSE_LOGGING", "HEADER_PASSTHROUGH"})
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION)); void getSomeOptionsExcludingOne(BaseRequestGeneratingCommandOptions excludedOption) {
assertEquals(5, options.getOptions().size()); Collection<BaseRequestGeneratingCommandOptions> excludeOptions = Collections.singleton(excludedOption);
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); Options options = tested.getSomeOptions(excludeOptions);
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME));
assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM)); // BASIC_AUTH exclusion excludes 2 options
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); int expectedSize = excludedOption == BASIC_AUTH ? 4 : 5;
assertEquals(expectedSize, options.getOptions().size());
assertFalse(options.hasShortOption(getOptionForExcludedOption(excludedOption)));
if (excludedOption == BASIC_AUTH) {
assertFalse(options.hasLongOption(BaseCommand.BEARER_TOKEN_PARAM_LONGOPT));
}
Arrays.stream(values())
.filter(excludeOptValue -> ! excludeOptValue.equals(excludedOption))
.forEach(excludeOptValue -> {
assertTrue(options.hasShortOption(getOptionForExcludedOption(excludeOptValue)));
// BASIC_AUTH option carries additional BEARER_TOKEN option
if (excludedOption != BASIC_AUTH) {
assertTrue(options.hasLongOption(BaseCommand.BEARER_TOKEN_PARAM_LONGOPT));
}
});
} }
@Test
void getSomeOptionsNoBaseUrl() {
Options options = tested.getSomeOptions(
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASE_URL));
assertEquals(5, options.getOptions().size());
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME));
assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM));
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
}
@Test private String getOptionForExcludedOption(BaseRequestGeneratingCommandOptions excludeOption) {
void getSomeOptionsNoBasicAuth() { switch (excludeOption) {
Options options = tested.getSomeOptions( case VERSION:
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASIC_AUTH)); return BaseCommand.FHIR_VERSION_PARAM;
assertEquals(4, options.getOptions().size());
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM));
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
}
@Test case BASE_URL:
void getSomeOptionsNoVerboseLogging() { return BaseCommand.BASE_URL_PARAM;
Options options = tested.getSomeOptions(
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERBOSE_LOGGING));
assertEquals(5, options.getOptions().size());
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME));
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
}
@Test case BASIC_AUTH:
void getSomeOptionsNoHeaderPassthrough() { return BaseCommand.BASIC_AUTH_PARAM;
Options options = tested.getSomeOptions(
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH)); case VERBOSE_LOGGING:
assertEquals(5, options.getOptions().size()); return BaseCommand.VERBOSE_LOGGING_PARAM;
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); case HEADER_PASSTHROUGH:
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); return BaseRequestGeneratingCommand.HEADER_PASSTHROUGH;
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME)); }
assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM)); throw new InvalidParameterException("unexpected exclude option " + excludeOption);
} }
@Test @Test
void getSomeOptionsExcludeTwo() { void getSomeOptionsExcludeTwo() {
Options options = tested.getSomeOptions(Lists.newArrayList( Options options = tested.getSomeOptions(Lists.newArrayList(VERSION, HEADER_PASSTHROUGH));
BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION,
BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH));
assertEquals(4, options.getOptions().size()); assertEquals(4, options.getOptions().size());
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));

View File

@ -0,0 +1,7 @@
---
type: add
issue: 2777
title: "Support for multiple header-passthrough option using <b>-hp</b> or <b>--header-passthrough</b>
parameter has been added to hapi-fhir-cli commands: <b>example-data-uploader</b>, <b>export-conceptmap-to-csv</b>,
<b>import-csv-to-conceptmap</b> and <b>upload-terminology</b>"