From 2e8d26150b08b42f1c3667dc4215fb5b1d567d8f Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 10 Dec 2020 10:33:00 -0800 Subject: [PATCH 1/3] Add git-repo as input to sdkman --- ci/tasks/publish-to-sdkman.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/tasks/publish-to-sdkman.yml b/ci/tasks/publish-to-sdkman.yml index bd27eea664..f9a07566ea 100755 --- a/ci/tasks/publish-to-sdkman.yml +++ b/ci/tasks/publish-to-sdkman.yml @@ -2,6 +2,7 @@ platform: linux inputs: - name: artifactory-repo + - name: git-repo params: RELEASE_TYPE: BRANCH: From 5da22b5bff26ea3967dc313b073d9508049dddf8 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 10 Dec 2020 10:42:12 -0800 Subject: [PATCH 2/3] Fix syntax in bash script --- ci/scripts/publish-to-sdkman.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/scripts/publish-to-sdkman.sh b/ci/scripts/publish-to-sdkman.sh index bbbb1e80ae..7373a4baa8 100755 --- a/ci/scripts/publish-to-sdkman.sh +++ b/ci/scripts/publish-to-sdkman.sh @@ -4,6 +4,6 @@ source $(dirname $0)/common.sh version=$( cat artifactory-repo/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/.*:.*:\(.*\)/\1/' ) -java -jar /spring-boot-release-scripts.jar publishToSdkman $RELEASE_TYPE $version $BRANCH || {exit 1;} +java -jar /spring-boot-release-scripts.jar publishToSdkman $RELEASE_TYPE $version $BRANCH || { exit 1; } echo "Push to SDKMAN complete" From 5cab547fe40a6a614463dc345d035a5daf967f7e Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 10 Dec 2020 12:36:22 -0800 Subject: [PATCH 3/3] Fix SDKMAN automation --- .../command/PublishToSdkmanCommand.java | 7 +++++++ .../releasescripts/sdkman/SdkmanService.java | 19 +++++++++++++------ .../sdkman/SdkmanServiceTests.java | 7 ++----- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishToSdkmanCommand.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishToSdkmanCommand.java index 5118b59b39..61130106d5 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishToSdkmanCommand.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/command/PublishToSdkmanCommand.java @@ -37,12 +37,19 @@ public class PublishToSdkmanCommand implements Command { private static final Logger logger = LoggerFactory.getLogger(PublishToSdkmanCommand.class); + private static final String PUBLISH_TO_SDKMAN_COMMAND = "publishToSdkman"; + private final SdkmanService service; public PublishToSdkmanCommand(SdkmanService service) { this.service = service; } + @Override + public String getName() { + return PUBLISH_TO_SDKMAN_COMMAND; + } + @Override public void run(ApplicationArguments args) throws Exception { logger.debug("Running 'push to SDKMAN' command"); diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sdkman/SdkmanService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sdkman/SdkmanService.java index 2f6823535c..099737353b 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sdkman/SdkmanService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sdkman/SdkmanService.java @@ -25,7 +25,6 @@ import org.springframework.boot.web.client.RestTemplateBuilder; 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.RestTemplate; /** @@ -47,13 +46,15 @@ public class SdkmanService { private final RestTemplate restTemplate; + private final SdkmanProperties properties; + + private final String CONSUMER_KEY_HEADER = "Consumer-Key"; + + private final String CONSUMER_TOKEN_HEADER = "Consumer-Token"; + public SdkmanService(RestTemplateBuilder builder, SdkmanProperties properties) { - String consumerKey = properties.getConsumerKey(); - String consumerToken = properties.getConsumerToken(); - if (StringUtils.hasLength(consumerKey)) { - builder = builder.basicAuthentication(consumerKey, consumerToken); - } this.restTemplate = builder.build(); + this.properties = properties; } public void publish(String version, boolean makeDefault) { @@ -67,6 +68,8 @@ public class SdkmanService { private void broadcast(String version) { BroadcastRequest broadcastRequest = new BroadcastRequest(version); RequestEntity broadcastEntity = RequestEntity.post(URI.create(SDKMAN_URL + "announce/struct")) + .header(CONSUMER_KEY_HEADER, this.properties.getConsumerKey()) + .header(CONSUMER_TOKEN_HEADER, this.properties.getConsumerToken()) .contentType(MediaType.APPLICATION_JSON).body(broadcastRequest); this.restTemplate.exchange(broadcastEntity, String.class); logger.debug("Broadcast complete"); @@ -76,6 +79,8 @@ public class SdkmanService { logger.debug("Making this version the default"); Request request = new Request(version); RequestEntity requestEntity = RequestEntity.post(URI.create(SDKMAN_URL + "default")) + .header(CONSUMER_KEY_HEADER, this.properties.getConsumerKey()) + .header(CONSUMER_TOKEN_HEADER, this.properties.getConsumerToken()) .contentType(MediaType.APPLICATION_JSON).body(request); this.restTemplate.exchange(requestEntity, String.class); logger.debug("Make default complete"); @@ -84,6 +89,8 @@ public class SdkmanService { private void release(String version) { ReleaseRequest releaseRequest = new ReleaseRequest(version, String.format(DOWNLOAD_URL, version, version)); RequestEntity releaseEntity = RequestEntity.post(URI.create(SDKMAN_URL + "release")) + .header(CONSUMER_KEY_HEADER, this.properties.getConsumerKey()) + .header(CONSUMER_TOKEN_HEADER, this.properties.getConsumerToken()) .contentType(MediaType.APPLICATION_JSON).body(releaseRequest); this.restTemplate.exchange(releaseEntity, String.class); logger.debug("Release complete"); diff --git a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sdkman/SdkmanServiceTests.java b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sdkman/SdkmanServiceTests.java index ee4ff2bcfe..4b78555143 100644 --- a/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sdkman/SdkmanServiceTests.java +++ b/ci/images/releasescripts/src/test/java/io/spring/concourse/releasescripts/sdkman/SdkmanServiceTests.java @@ -25,7 +25,6 @@ import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.util.Base64Utils; import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; import static org.springframework.test.web.client.match.MockRestRequestMatchers.header; @@ -80,10 +79,8 @@ class SdkmanServiceTests { private void setupExpectation(String url, String body) { this.server.expect(requestTo(url)).andExpect(method(HttpMethod.POST)).andExpect(content().json(body)) - .andExpect(header("Authorization", - "Basic " + Base64Utils.encodeToString(String - .format("%s:%s", this.properties.getConsumerKey(), this.properties.getConsumerToken()) - .getBytes()))) + .andExpect(header("Consumer-Key", "sdkman-consumer-key")) + .andExpect(header("Consumer-Token", "sdkman-consumer-token")) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON.toString())).andRespond(withSuccess()); }