Skip to content

Commit

Permalink
feat: map providers' user setting to request header for authentication
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Grinberg <zgrinber@redhat.com>
  • Loading branch information
zvigrinberg committed Nov 22, 2023
1 parent 727217f commit c67d6c0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/redhat/exhort/impl/ExhortApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ String getVarName() {
return String.format("EXHORT_%s_TOKEN", this);
}

String getUserVarName() {
return String.format("EXHORT_%s_USER", this);
}
/**
* Get the expected request header name.
* @return i.e. ex-snyk-token
*/
String getHeaderName() {
return String.format("ex-%s-token", this.toString().replace("_","-").toLowerCase());
}

String getUserHeaderName() {
return String.format("ex-%s-user", this.toString().replace("_","-").toLowerCase());
}
}

private final HttpClient client;
Expand Down Expand Up @@ -344,6 +351,16 @@ private HttpRequest buildRequest(
request.setHeader(p.getHeaderName(), propToken);
}
}
var envUser = System.getenv(p.getUserHeaderName());
if (Objects.nonNull(envUser)) {
request.setHeader(p.getUserHeaderName(), envUser);
} else {
var propUser = System.getProperty(p.getUserVarName());
if (Objects.nonNull(propUser)) {
request.setHeader(p.getUserHeaderName(), propUser);
}
}

});
//set rhda-token
// Environment variable/property name = RHDA_TOKEN
Expand Down

0 comments on commit c67d6c0

Please sign in to comment.