Browse Source

Make CI credentials requirement lenient when building RestTemplate

Fixes gh-18901
pull/19101/head
Madhura Bhave 6 years ago
parent
commit
8d3df1b4b8
  1. 8
      ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java
  2. 5
      ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java
  3. 10
      ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java

8
ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/artifactory/ArtifactoryService.java

@ -30,6 +30,7 @@ import org.springframework.http.MediaType; @@ -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 { @@ -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();
}

5
ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/bintray/BintrayService.java

@ -31,6 +31,7 @@ import org.springframework.http.HttpStatus; @@ -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 { @@ -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();
}

10
ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java

@ -23,6 +23,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder; @@ -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 { @@ -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();
}

Loading…
Cancel
Save