diff --git a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java index 0ecc8a0d82..4afa1ffc34 100644 --- a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java +++ b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/BuildService.java @@ -18,19 +18,17 @@ import com.netflix.spinnaker.kork.artifacts.model.Artifact; import java.util.List; import java.util.Map; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.web.util.UriUtils; import retrofit.client.Response; +@RequiredArgsConstructor +@EnableConfigurationProperties(IgorFeatureFlagProperties.class) public class BuildService { private final IgorService igorService; private final IgorFeatureFlagProperties igorFeatureFlagProperties; - public BuildService( - IgorService igorService, IgorFeatureFlagProperties igorFeatureFlagProperties) { - this.igorService = igorService; - this.igorFeatureFlagProperties = igorFeatureFlagProperties; - } - private String encode(String uri) { return UriUtils.encodeFragment(uri, "UTF-8"); } @@ -45,11 +43,9 @@ public Response build( } public String stop(String master, String jobName, String queuedBuild, Integer buildNumber) { - if (this.igorFeatureFlagProperties.isJobNameAsQueryParameter()) { - return igorService.stopWithJobNameAsQueryParameter( - master, jobName, queuedBuild, buildNumber, ""); - } - return igorService.stop(master, jobName, queuedBuild, buildNumber, ""); + return this.igorFeatureFlagProperties.isJobNameAsQueryParameter() + ? igorService.stopWithJobNameAsQueryParameter(master, jobName, queuedBuild, buildNumber, "") + : igorService.stop(master, jobName, queuedBuild, buildNumber, ""); } public Map queuedBuild(String master, String item) { @@ -57,7 +53,9 @@ public Map queuedBuild(String master, String item) { } public Map getBuild(Integer buildNumber, String master, String job) { - return igorService.getBuild(buildNumber, master, encode(job)); + return this.igorFeatureFlagProperties.isJobNameAsQueryParameter() + ? igorService.getBuildWithJobAsQueryParam(buildNumber, master, encode(job)) + : igorService.getBuild(buildNumber, master, encode(job)); } public Map getPropertyFile( diff --git a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java index f65c31de3e..e13e558bfe 100644 --- a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java +++ b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorFeatureFlagProperties.java @@ -16,17 +16,13 @@ package com.netflix.spinnaker.orca.igor; +import lombok.Getter; +import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; +@Getter +@Setter @ConfigurationProperties(prefix = "feature.igor") public class IgorFeatureFlagProperties { private boolean jobNameAsQueryParameter = true; - - public boolean isJobNameAsQueryParameter() { - return jobNameAsQueryParameter; - } - - public void setJobNameAsQueryParameter(boolean jobNameAsQueryParameter) { - this.jobNameAsQueryParameter = jobNameAsQueryParameter; - } } diff --git a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java index b9896c678b..e2ec1a5c68 100644 --- a/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java +++ b/orca-igor/src/main/java/com/netflix/spinnaker/orca/igor/IgorService.java @@ -66,6 +66,12 @@ Map getBuild( @Path("master") String master, @Path(encode = false, value = "job") String job); + @GET("/builds/status/{buildNumber}/{master}") + Map getBuildWithJobAsQueryParam( + @Path("buildNumber") Integer buildNumber, + @Path("master") String master, + @Query(encodeValue = false, value = "job") String job); + @GET("/builds/properties/{buildNumber}/{fileName}/{master}/{job}") Map getPropertyFile( @Path("buildNumber") Integer buildNumber, diff --git a/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy b/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy index 2b736c24c5..f7f6e3785c 100644 --- a/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy +++ b/orca-igor/src/test/groovy/com/netflix/spinnaker/orca/igor/BuildServiceSpec.groovy @@ -33,7 +33,7 @@ class BuildServiceSpec extends Specification { void setup() { igorService = Mock(IgorService) - buildService = new BuildService(igorService, new IgorFeatureFlagProperties()) + buildService = new BuildService(igorService, new IgorFeatureFlagProperties(jobNameAsQueryParameter: false)) } void 'build method encodes the job name'() { @@ -52,6 +52,18 @@ class BuildServiceSpec extends Specification { 1 * igorService.getBuild(BUILD_NUMBER, MASTER, JOB_NAME_ENCODED) } + void 'getBuild method get job name in query when flag is true'() { + IgorFeatureFlagProperties igorFeatureFlagProperties = new IgorFeatureFlagProperties() + igorFeatureFlagProperties.setJobNameAsQueryParameter(true) + buildService = new BuildService(igorService, igorFeatureFlagProperties) + + when: + buildService.getBuild(BUILD_NUMBER, MASTER, JOB_NAME) + + then: + 1 * igorService.getBuildWithJobAsQueryParam(BUILD_NUMBER, MASTER, JOB_NAME_ENCODED) + } + void 'getPropertyFile method encodes the job name'() { when: buildService.getPropertyFile(BUILD_NUMBER, FILENAME, MASTER, JOB_NAME)