Skip to content

Commit

Permalink
feat(artifacts): Add a "no auth" http artifact account where needed (#…
Browse files Browse the repository at this point in the history
lwander authored Mar 9, 2018
1 parent afb5ca5 commit 3a06e8b
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -18,9 +18,11 @@
package com.netflix.spinnaker.clouddriver.artifacts.http;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netflix.spinnaker.clouddriver.artifacts.config.ArtifactAccount;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

@EqualsAndHashCode(callSuper = true)
@Data
@@ -34,4 +36,9 @@ public class HttpArtifactAccount extends ArtifactAccount {
private String username;
private String password;
private String usernamePasswordFile;

@JsonIgnore
public boolean usesAuth() {
return !(StringUtils.isEmpty(username) && StringUtils.isEmpty(password) && StringUtils.isEmpty(usernamePasswordFile));
}
}
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ OkHttpClient httpOkHttpClient() {

@Bean
List<? extends HttpArtifactCredentials> httpArtifactCredentials() {
return httpArtifactProviderProperties.getAccounts()
List<HttpArtifactCredentials> result = httpArtifactProviderProperties.getAccounts()
.stream()
.map(a -> {
try {
@@ -75,5 +75,15 @@ List<? extends HttpArtifactCredentials> httpArtifactCredentials() {
})
.filter(Objects::nonNull)
.collect(Collectors.toList());

if (httpArtifactProviderProperties.getAccounts().stream().noneMatch(HttpArtifactAccount::usesAuth)) {
HttpArtifactAccount noAuthAccount = new HttpArtifactAccount()
.setName("no-auth-http-account");
HttpArtifactCredentials noAuthCredentials = new HttpArtifactCredentials(noAuthAccount, httpOkHttpClient);

result.add(noAuthCredentials);
}

return result;
}
}

0 comments on commit 3a06e8b

Please sign in to comment.