Skip to content

Commit 10897d7

Browse files
fix(docker): address review comments on the fix to the issue of retrofit2 replacing ? with %3F causing api failure with 400
1 parent 5e32a8a commit 10897d7

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

clouddriver-docker/src/main/groovy/com/netflix/spinnaker/clouddriver/docker/registry/api/v2/auth/DockerBearerTokenService.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.netflix.spinnaker.clouddriver.docker.registry.api.v2.auth
1919
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.DockerUserAgent
2020
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.exception.DockerRegistryAuthenticationException
2121
import com.netflix.spinnaker.config.DefaultServiceEndpoint
22+
import com.netflix.spinnaker.kork.annotations.VisibleForTesting
2223
import com.netflix.spinnaker.kork.client.ServiceClientProvider
2324
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall
2425
import groovy.util.logging.Slf4j
@@ -236,7 +237,8 @@ class DockerBearerTokenService {
236237
cachedTokens.remove(repository)
237238
}
238239

239-
private interface TokenService {
240+
@VisibleForTesting
241+
interface TokenService {
240242
@GET("/{path}")
241243
@Headers([
242244
"Docker-Distribution-API-Version: registry/2.0"

clouddriver-docker/src/main/groovy/com/netflix/spinnaker/clouddriver/docker/registry/api/v2/client/DockerRegistryClient.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,12 @@ class DockerRegistryClient {
474474
return tags
475475
}
476476

477-
static def parseForQueryParams(String nextPath) {
477+
/**
478+
* This method takes a string that might contain a query string and splits it into the path and the query parameters.
479+
* @param nextPath the string that might contain a query string
480+
* @return a tuple containing the path (without query string) and a map of query parameters
481+
*/
482+
static Tuple2<String, Map<String, String>> parseForQueryParams(String nextPath) {
478483
def nextPathNew
479484
def queryParamsString
480485
Map<String, String> queryParams = [:]

clouddriver-docker/src/test/java/com/netflix/spinnaker/clouddriver/docker/registry/api/v2/client/DockerRegistryServiceTest.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package com.netflix.spinnaker.clouddriver.docker.registry.api.v2.client;
1818

19+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
1920
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021

2122
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.auth.DockerBearerToken;
23+
import com.netflix.spinnaker.clouddriver.docker.registry.api.v2.auth.DockerBearerTokenService;
2224
import com.netflix.spinnaker.kork.retrofit.ErrorHandlingExecutorCallAdapterFactory;
2325
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall;
2426
import java.io.IOException;
@@ -29,20 +31,14 @@
2931
import okhttp3.ResponseBody;
3032
import org.junit.jupiter.api.BeforeAll;
3133
import org.junit.jupiter.api.Test;
32-
import retrofit2.Call;
3334
import retrofit2.Response;
3435
import retrofit2.Retrofit;
3536
import retrofit2.converter.jackson.JacksonConverterFactory;
36-
import retrofit2.http.GET;
37-
import retrofit2.http.Header;
38-
import retrofit2.http.Headers;
39-
import retrofit2.http.Path;
40-
import retrofit2.http.Query;
4137

4238
public class DockerRegistryServiceTest {
4339

4440
static DockerRegistryClient.DockerRegistryService dockerRegistryService;
45-
static TokenService tokenService;
41+
static DockerBearerTokenService.TokenService tokenService;
4642
String service = "registry.docker.io";
4743
String scope = "repository:library/nginx:pull";
4844
String repository = "library/nginx";
@@ -53,7 +49,8 @@ public class DockerRegistryServiceTest {
5349

5450
@BeforeAll
5551
public static void setup() {
56-
tokenService = buildService(TokenService.class, "https://auth.docker.io");
52+
tokenService =
53+
buildService(DockerBearerTokenService.TokenService.class, "https://auth.docker.io");
5754
dockerRegistryService =
5855
buildService(
5956
DockerRegistryClient.DockerRegistryService.class, "https://registry-1.docker.io");
@@ -92,7 +89,7 @@ void getTagsWithQueryParams() {
9289
Retrofit2SyncCall.executeCall(
9390
dockerRegistryService.get(tagsPath, getBearerToken(), "Spinnaker", queryMap));
9491
String nextLink = response.headers().get("link");
95-
assert nextLink != null;
92+
assertThat(nextLink).isNotNull();
9693
}
9794

9895
private String getBearerToken() {
@@ -114,14 +111,4 @@ private static <T> T buildService(Class<T> type, String baseUrl) {
114111
.build()
115112
.create(type);
116113
}
117-
118-
private interface TokenService {
119-
@GET("/{path}")
120-
@Headers({"Docker-Distribution-API-Version: registry/2.0"})
121-
Call<DockerBearerToken> getToken(
122-
@Path(value = "path", encoded = true) String path,
123-
@Query(value = "service") String service,
124-
@Query(value = "scope") String scope,
125-
@Header("User-Agent") String agent);
126-
}
127114
}

0 commit comments

Comments
 (0)