Skip to content

Commit

Permalink
Fix test and set up apiKey for package client servers
Browse files Browse the repository at this point in the history
  • Loading branch information
dotasek committed Nov 11, 2024
1 parent 36142f4 commit a155475
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ private InputStream fetchUrl(String source, String accept) throws IOException {
webAccessor.withToken(server.getToken());
} else if (server.getAuthenticationMode() == HTTPAuthenticationMode.BASIC) {
webAccessor.withBasicAuth(server.getUsername(), server.getPassword());
} else if (server.getAuthenticationMode() == HTTPAuthenticationMode.APIKEY) {
webAccessor.withApiKey(server.getApiKey());
}
HTTPResult res = webAccessor.get(source, accept);
res.checkThrowException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.annotation.Nullable;

import org.hl7.fhir.utilities.http.HTTPAuthenticationMode;
import org.hl7.fhir.utilities.http.SimpleHTTPClient;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.utilities.settings.ServerDetailsPOJO;

Expand All @@ -27,10 +26,11 @@ public PackageServer(String url) {
serverType = PackageServerType.FHIR;
}

@Getter
private String url;

@Getter
private HTTPAuthenticationMode authenticationMode;
private HTTPAuthenticationMode authenticationMode;

@Getter
private PackageServerType serverType;
Expand All @@ -43,9 +43,11 @@ public PackageServer(String url) {

@Getter
private String token;
public String getUrl() {
return url;
}

@Getter
private String apiKey;



public static final String PRIMARY_SERVER = "https://packages.fhir.org";
public static final String SECONDARY_SERVER = "https://packages2.fhir.org/packages";
Expand Down Expand Up @@ -73,7 +75,9 @@ public static PackageServer getPackageServerFromPOJO(ServerDetailsPOJO pojo) {
)
.withUsername(pojo.getUsername())
.withPassword(pojo.getPassword())
.withToken(pojo.getToken());
.withToken(pojo.getToken())
.withApiKey(pojo.getApikey());

}

private static boolean isPackageServer(String serverType) {
Expand Down Expand Up @@ -129,6 +133,7 @@ public PackageServer copy() {
packageServer.username = this.username;
packageServer.password = this.password;
packageServer.token = this.token;
packageServer.apiKey = this.apiKey;
return packageServer;
}

Expand Down Expand Up @@ -161,4 +166,10 @@ public PackageServer withToken(String token) {
packageServer.token = token;
return packageServer;
}

public PackageServer withApiKey(String apiKey) {
PackageServer packageServer = this.copy();
packageServer.apiKey = apiKey;
return packageServer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private ServerDetailsPOJO getBasicAuthServerPojo() {
return new ServerDetailsPOJO(
server.url("").toString(),
"basic",
"dummyServerType",
"fhir",
DUMMY_USERNAME,
DUMMY_PASSWORD,
null, null);
Expand All @@ -183,7 +183,7 @@ private ServerDetailsPOJO getTokenAuthServerPojo() {
return new ServerDetailsPOJO(
server.url("").toString(),
"token",
"dummyServerType",
"fhir",
null,
null,
DUMMY_TOKEN, null);
Expand All @@ -202,7 +202,7 @@ private ServerDetailsPOJO getApiKeyAuthServerPojo() {
return new ServerDetailsPOJO(
server.url("").toString(),
"apikey",
"dummyServerType",
"fhir",
null,
null,
null, DUMMY_API_KEY);
Expand Down

0 comments on commit a155475

Please sign in to comment.