Make CI credentials requirement lenient when building RestTemplate

Fixes gh-18901
This commit is contained in:
Madhura Bhave 2019-11-06 11:12:20 -08:00
parent 891c7120ef
commit 8d3df1b4b8
3 changed files with 13 additions and 10 deletions

View File

@ -30,6 +30,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
@ -53,19 +54,18 @@ public class ArtifactoryService {
private final RestTemplate restTemplate;
private final ArtifactoryProperties artifactoryProperties;
private final BintrayService bintrayService;
private static final ConsoleLogger console = new ConsoleLogger();
public ArtifactoryService(RestTemplateBuilder builder, ArtifactoryProperties artifactoryProperties,
BintrayService bintrayService) {
this.artifactoryProperties = artifactoryProperties;
this.bintrayService = bintrayService;
String username = artifactoryProperties.getUsername();
String password = artifactoryProperties.getPassword();
builder = builder.basicAuthentication(username, password);
if (StringUtils.hasLength(username)) {
builder = builder.basicAuthentication(username, password);
}
this.restTemplate = builder.build();
}

View File

@ -31,6 +31,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
@ -65,7 +66,9 @@ public class BintrayService {
this.sonatypeService = sonatypeService;
String username = bintrayProperties.getUsername();
String apiKey = bintrayProperties.getApiKey();
builder = builder.basicAuthentication(username, apiKey);
if (StringUtils.hasLength(username)) {
builder = builder.basicAuthentication(username, apiKey);
}
this.restTemplate = builder.build();
}

View File

@ -23,6 +23,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
@ -38,15 +39,14 @@ public class SonatypeService {
private final RestTemplate restTemplate;
private final SonatypeProperties sonatypeProperties;
private static final ConsoleLogger console = new ConsoleLogger();
public SonatypeService(RestTemplateBuilder builder, SonatypeProperties sonatypeProperties) {
this.sonatypeProperties = sonatypeProperties;
String username = sonatypeProperties.getUserToken();
String apiKey = sonatypeProperties.getPasswordToken();
builder = builder.basicAuthentication(username, apiKey);
String password = sonatypeProperties.getPasswordToken();
if (StringUtils.hasLength(username)) {
builder = builder.basicAuthentication(username, password);
}
this.restTemplate = builder.build();
}