-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix redirect failures from apache client 5.x (#5996)
This commit changes the underlying http client used by the RestTemplate in the Container Image Registry component from Apache Http Client to Reactor Netty. Our upgrade to Spring Boot 3.x brought with it an update from 4.x to 5.x for the Apache Http client. The 5.x line removes support for dropping headers - which is a requirement of this component. Moving to Reactor Netty solves the redirect issue while also greatly reducing the complexity of this code. Fixes #5989
- Loading branch information
Showing
6 changed files
with
227 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...taflow/container/registry/authorization/DropAuthorizationHeaderOnContainerTestManual.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.dataflow.container.registry.authorization; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient; | ||
import org.springframework.cloud.dataflow.configuration.metadata.ApplicationConfigurationMetadataResolverAutoConfiguration; | ||
import org.springframework.cloud.dataflow.configuration.metadata.container.DefaultContainerImageMetadataResolver; | ||
import org.springframework.cloud.dataflow.container.registry.ContainerRegistryAutoConfiguration; | ||
import org.springframework.cloud.dataflow.container.registry.ContainerRegistryConfiguration; | ||
import org.springframework.cloud.dataflow.container.registry.ContainerRegistryProperties; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.annotation.Primary; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* This test is aimed at performing a manual test against a deployed container registry; | ||
* In order to invoke this test populate the fields of DropAuthorizationHeaderOnContainerTestManual.TestApplication | ||
* named registryDomainName, registryUser, registrySecret and imageNameAndTag | ||
* | ||
* The image should be one built with spring-boot:build-image or paketo so that is has a label named 'org.springframework.boot.version' | ||
* For docker hub use: | ||
* registryDomainName="registry-1.docker.io", | ||
* registryUser="docker user" | ||
* registrySecret="docker access token" | ||
* imageNameAndTag="springcloudstream/s3-sink-rabbit:5.0.0" | ||
* | ||
* @author Corneil du Plessis | ||
*/ | ||
public class DropAuthorizationHeaderOnContainerTestManual { | ||
|
||
private static final String registryDomainName = "registry-1.docker.io"; | ||
private static final String registryUser = "<docker-user>"; | ||
private static final String registrySecret = "<docker-access-token>"; | ||
private static final String imageNameAndTag = "springcloudstream/s3-sink-rabbit:5.0.0"; | ||
|
||
private AnnotationConfigApplicationContext context; | ||
|
||
@AfterEach | ||
void clean() { | ||
if (context != null) { | ||
context.close(); | ||
} | ||
context = null; | ||
} | ||
|
||
@Test | ||
void testContainerImageLabels() { | ||
context = new AnnotationConfigApplicationContext(TestApplication.class); | ||
DefaultContainerImageMetadataResolver imageMetadataResolver = context.getBean(DefaultContainerImageMetadataResolver.class); | ||
Map<String, String> imageLabels = imageMetadataResolver.getImageLabels(registryDomainName + "/" + imageNameAndTag); | ||
System.out.println("imageLabels:" + imageLabels.keySet()); | ||
assertThat(imageLabels).containsKey("org.springframework.boot.version"); | ||
} | ||
|
||
@Import({ContainerRegistryAutoConfiguration.class, ApplicationConfigurationMetadataResolverAutoConfiguration.class}) | ||
@AutoConfigureWebClient | ||
static class TestApplication { | ||
|
||
@Bean | ||
@Primary | ||
ContainerRegistryProperties containerRegistryProperties() { | ||
ContainerRegistryProperties properties = new ContainerRegistryProperties(); | ||
ContainerRegistryConfiguration registryConfiguration = new ContainerRegistryConfiguration(); | ||
registryConfiguration.setRegistryHost(registryDomainName); | ||
registryConfiguration.setAuthorizationType(ContainerRegistryConfiguration.AuthorizationType.dockeroauth2); | ||
registryConfiguration.setUser(registryUser); | ||
registryConfiguration.setSecret(registrySecret); | ||
properties.setRegistryConfigurations(Collections.singletonMap(registryDomainName, registryConfiguration)); | ||
|
||
return properties; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.