Skip to content

Commit 019087c

Browse files
author
Corneil du Plessis
committed
Replace RedirectExec with modified chain handler.
Fixes spring-attic#5989
1 parent 9e93935 commit 019087c

File tree

1 file changed

+42
-53
lines changed

1 file changed

+42
-53
lines changed

spring-cloud-dataflow-container-registry/src/main/java/org/springframework/cloud/dataflow/container/registry/ContainerRegistryService.java

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.http.HttpMethod;
3232
import org.springframework.http.ResponseEntity;
3333
import org.springframework.util.StringUtils;
34-
import org.springframework.web.client.RestClientException;
3534
import org.springframework.web.client.RestTemplate;
3635
import org.springframework.web.util.UriComponents;
3736
import org.springframework.web.util.UriComponentsBuilder;
@@ -47,9 +46,9 @@ public class ContainerRegistryService {
4746

4847
private static final Logger logger = LoggerFactory.getLogger(ContainerRegistryService.class);
4948

50-
private static final List<String> SUPPORTED_MANIFEST_MEDIA_TYPES = Collections
51-
.unmodifiableList(Arrays.asList(ContainerRegistryProperties.OCI_IMAGE_MANIFEST_MEDIA_TYPE,
52-
ContainerRegistryProperties.DOCKER_IMAGE_MANIFEST_MEDIA_TYPE));
49+
private static final List<String> SUPPORTED_MANIFEST_MEDIA_TYPES =
50+
Collections.unmodifiableList(Arrays.asList(ContainerRegistryProperties.OCI_IMAGE_MANIFEST_MEDIA_TYPE,
51+
ContainerRegistryProperties.DOCKER_IMAGE_MANIFEST_MEDIA_TYPE));
5352

5453
private static final String HTTPS_SCHEME = "https";
5554

@@ -89,38 +88,35 @@ public Map<String, ContainerRegistryConfiguration> getContainerRegistryConfigura
8988
}
9089

9190
/**
92-
* Get the tag information for the given container image identified by its repository
93-
* and registry. The registry information is expected to be set via container registry
94-
* configuration in SCDF.
91+
* Get the tag information for the given container image identified by its repository and registry.
92+
* The registry information is expected to be set via container registry configuration in SCDF.
9593
* @param registryName the container registry name
9694
* @param repositoryName the image repository name
9795
* @return the list of tags for the image
9896
*/
9997
public List<String> getTags(String registryName, String repositoryName) {
10098
try {
101-
ContainerRegistryConfiguration containerRegistryConfiguration = this.registryConfigurations
102-
.get(registryName);
99+
ContainerRegistryConfiguration containerRegistryConfiguration = this.registryConfigurations.get(registryName);
103100
Map<String, String> properties = new HashMap<>();
104101
properties.put(DockerOAuth2RegistryAuthorizer.DOCKER_REGISTRY_REPOSITORY_FIELD_KEY, repositoryName);
105-
HttpHeaders httpHeaders = new HttpHeaders(
106-
this.registryAuthorizerMap.get(containerRegistryConfiguration.getAuthorizationType())
107-
.getAuthorizationHeaders(containerRegistryConfiguration, properties));
102+
HttpHeaders httpHeaders = new HttpHeaders(this.registryAuthorizerMap.get(containerRegistryConfiguration.getAuthorizationType()).getAuthorizationHeaders(
103+
containerRegistryConfiguration, properties));
108104
httpHeaders.set(HttpHeaders.ACCEPT, "application/json");
109105

110106
UriComponents manifestUriComponents = UriComponentsBuilder.newInstance()
111-
.scheme(HTTPS_SCHEME)
112-
.host(containerRegistryConfiguration.getRegistryHost())
113-
.path(TAGS_LIST_PATH)
114-
.build()
115-
.expand(repositoryName);
107+
.scheme(HTTPS_SCHEME)
108+
.host(containerRegistryConfiguration.getRegistryHost())
109+
.path(TAGS_LIST_PATH)
110+
.build().expand(repositoryName);
116111

117112
RestTemplate requestRestTemplate = this.containerImageRestTemplateFactory.getContainerRestTemplate(
118113
containerRegistryConfiguration.isDisableSslVerification(),
119-
containerRegistryConfiguration.isUseHttpProxy(), containerRegistryConfiguration.getExtra());
114+
containerRegistryConfiguration.isUseHttpProxy(),
115+
containerRegistryConfiguration.getExtra());
120116

121-
ResponseEntity<Map> manifest = requestRestTemplate.exchange(manifestUriComponents.toUri(), HttpMethod.GET,
122-
new HttpEntity<>(httpHeaders), Map.class);
123-
return (List<String>) manifest.getBody().get(TAGS_FIELD);
117+
ResponseEntity<Map> manifest = requestRestTemplate.exchange(manifestUriComponents.toUri(),
118+
HttpMethod.GET, new HttpEntity<>(httpHeaders), Map.class);
119+
return (List<String>) manifest.getBody().get(TAGS_FIELD);
124120
}
125121
catch (Exception e) {
126122
logger.error("Exception getting tag information for the {} from {}", repositoryName, registryName);
@@ -136,25 +132,28 @@ public List<String> getTags(String registryName, String repositoryName) {
136132
public Map getRepositories(String registryName) {
137133
try {
138134
ContainerRegistryConfiguration containerRegistryConfiguration = this.registryConfigurations
139-
.get(registryName);
135+
.get(registryName);
140136
Map<String, String> properties = new HashMap<>();
141137
properties.put(DockerOAuth2RegistryAuthorizer.DOCKER_REGISTRY_REPOSITORY_FIELD_KEY, registryName);
142138
HttpHeaders httpHeaders = new HttpHeaders(
143139
this.registryAuthorizerMap.get(containerRegistryConfiguration.getAuthorizationType())
144-
.getAuthorizationHeaders(containerRegistryConfiguration, properties));
140+
.getAuthorizationHeaders(
141+
containerRegistryConfiguration, properties));
145142
httpHeaders.set(HttpHeaders.ACCEPT, "application/json");
146143
UriComponents manifestUriComponents = UriComponentsBuilder.newInstance()
147-
.scheme(HTTPS_SCHEME)
148-
.host(containerRegistryConfiguration.getRegistryHost())
149-
.path(CATALOG_LIST_PATH)
150-
.build();
144+
.scheme(HTTPS_SCHEME)
145+
.host(containerRegistryConfiguration.getRegistryHost())
146+
.path(CATALOG_LIST_PATH)
147+
.build();
148+
151149

152150
RestTemplate requestRestTemplate = this.containerImageRestTemplateFactory.getContainerRestTemplate(
153151
containerRegistryConfiguration.isDisableSslVerification(),
154-
containerRegistryConfiguration.isUseHttpProxy(), containerRegistryConfiguration.getExtra());
152+
containerRegistryConfiguration.isUseHttpProxy(),
153+
containerRegistryConfiguration.getExtra());
155154

156-
ResponseEntity<Map> manifest = requestRestTemplate.exchange(manifestUriComponents.toUri(), HttpMethod.GET,
157-
new HttpEntity<>(httpHeaders), Map.class);
155+
ResponseEntity<Map> manifest = requestRestTemplate.exchange(manifestUriComponents.toUri(),
156+
HttpMethod.GET, new HttpEntity<>(httpHeaders), Map.class);
158157
return manifest.getBody();
159158
}
160159
catch (Exception e) {
@@ -207,20 +206,18 @@ public <T> T getImageManifest(ContainerRegistryRequest registryRequest, Class<T>
207206
// Docker Registry HTTP V2 API pull manifest
208207
ContainerImage containerImage = registryRequest.getContainerImage();
209208
UriComponents manifestUriComponents = UriComponentsBuilder.newInstance()
210-
.scheme(HTTPS_SCHEME)
211-
.host(containerImage.getHostname())
212-
.port(StringUtils.hasText(containerImage.getPort()) ? containerImage.getPort() : null)
213-
.path(IMAGE_MANIFEST_REFERENCE_PATH)
214-
.build()
215-
.expand(containerImage.getRepository(), containerImage.getRepositoryReference());
209+
.scheme(HTTPS_SCHEME)
210+
.host(containerImage.getHostname())
211+
.port(StringUtils.hasText(containerImage.getPort()) ? containerImage.getPort() : null)
212+
.path(IMAGE_MANIFEST_REFERENCE_PATH)
213+
.build().expand(containerImage.getRepository(), containerImage.getRepositoryReference());
216214

217-
ResponseEntity<T> manifest = registryRequest.getRestTemplate()
218-
.exchange(manifestUriComponents.toUri(), HttpMethod.GET, new HttpEntity<>(httpHeaders), responseClassType);
215+
ResponseEntity<T> manifest = registryRequest.getRestTemplate().exchange(manifestUriComponents.toUri(),
216+
HttpMethod.GET, new HttpEntity<>(httpHeaders), responseClassType);
219217
return manifest.getBody();
220218
}
221219

222-
public <T> T getImageBlob(ContainerRegistryRequest registryRequest, String configDigest,
223-
Class<T> responseClassType) {
220+
public <T> T getImageBlob(ContainerRegistryRequest registryRequest, String configDigest, Class<T> responseClassType) {
224221
ContainerImage containerImage = registryRequest.getContainerImage();
225222
HttpHeaders httpHeaders = new HttpHeaders(registryRequest.getAuthHttpHeaders());
226223

@@ -230,19 +227,11 @@ public <T> T getImageBlob(ContainerRegistryRequest registryRequest, String confi
230227
.host(containerImage.getHostname())
231228
.port(StringUtils.hasText(containerImage.getPort()) ? containerImage.getPort() : null)
232229
.path(IMAGE_BLOB_DIGEST_PATH)
233-
.build()
234-
.expand(containerImage.getRepository(), configDigest);
235-
try {
236-
logger.info("getImageBlob:request:{},{}", blobUriComponents.toUri(), httpHeaders);
237-
ResponseEntity<T> blob = registryRequest.getRestTemplate()
238-
.exchange(blobUriComponents.toUri(), HttpMethod.GET, new HttpEntity<>(httpHeaders), responseClassType);
230+
.build().expand(containerImage.getRepository(), configDigest);
239231

240-
return blob.getStatusCode().is2xxSuccessful() ? blob.getBody() : null;
241-
}
242-
catch (RestClientException x) {
243-
logger.error("getImageBlob:exception:" + x, x);
244-
return null;
245-
}
246-
}
232+
ResponseEntity<T> blob = registryRequest.getRestTemplate().exchange(blobUriComponents.toUri(),
233+
HttpMethod.GET, new HttpEntity<>(httpHeaders), responseClassType);
247234

235+
return blob.getBody();
236+
}
248237
}

0 commit comments

Comments
 (0)