Repository navigation
Add a ConfigResourceClient for plain text and binary files #3355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sharanggupta
wants to merge
6
commits into
spring-cloud:main
Choose a base branch
from
sharanggupta:gh-789-config-resource-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfa0cca
Add a ConfigResourceClient for plain text and binary files
sharanggupta e6ce44f
Use the config server import's properties for the ConfigResourceClient
sharanggupta 2b446c3
Use the import's credentials, URIs, labels and a size limit in the Co…
sharanggupta 4f5fa67
Validate max size, log skips, skip empty labels
sharanggupta 88822f1
Keep the RestClient holder failure non-fatal
sharanggupta d30c6dc
Make DefaultConfigResourceClient package-private
sharanggupta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
...ent/src/main/java/org/springframework/cloud/config/client/BinaryResourceConfigClient.java
This file contains hidden or 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,56 @@ | ||
| /* | ||
| * Copyright 2013-present 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.config.client; | ||
|
|
||
| import org.springframework.core.io.Resource; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
|
|
||
| /** | ||
| * Provides access to the binary files served by a Spring Cloud Config Server. | ||
| * | ||
| * @author Craig Walls | ||
| * @author Anshul Mehra | ||
| * @author Sharang Gupta | ||
| * @since 5.1.0 | ||
| * @see ConfigResourceClient | ||
| */ | ||
| public interface BinaryResourceConfigClient { | ||
|
|
||
| /** | ||
| * Retrieves a binary file using the configured profile and label. | ||
| * @param path the path of the file, relative to the application's folder | ||
| * @return the file served by the config server | ||
| * @throws IllegalArgumentException when the application name or the config server URI | ||
| * is undefined | ||
| * @throws HttpClientErrorException when the file is not found | ||
| */ | ||
| Resource getBinaryResource(String path); | ||
|
|
||
| /** | ||
| * Retrieves a binary file. | ||
| * @param profile the profile, or {@code null} for the configured one; may be a | ||
| * comma-separated list | ||
| * @param label the label, or {@code null} for the configured one | ||
| * @param path the path of the file, relative to the application's folder | ||
| * @return the file served by the config server | ||
| * @throws IllegalArgumentException when the application name or the config server URI | ||
| * is undefined | ||
| * @throws HttpClientErrorException when the file is not found | ||
| */ | ||
| Resource getBinaryResource(String profile, String label, String path); | ||
|
|
||
| } |
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
...ig-client/src/main/java/org/springframework/cloud/config/client/ConfigResourceClient.java
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * Copyright 2013-present 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.config.client; | ||
|
|
||
| /** | ||
| * Provides access to the plain text and binary files served by a Spring Cloud Config | ||
| * Server. When the configuration is imported with {@code spring.config.import}, a | ||
| * {@link ConfigResourceClient} that uses the same connection settings as the import is | ||
| * available as a bean. | ||
| * | ||
| * @author Daniel Lavoie | ||
| * @author Sharang Gupta | ||
| * @since 5.1.0 | ||
| * @see ConfigResourceClientAutoConfiguration | ||
| */ | ||
| public interface ConfigResourceClient extends PlainTextConfigClient, BinaryResourceConfigClient { | ||
|
|
||
| } |
55 changes: 55 additions & 0 deletions
55
...n/java/org/springframework/cloud/config/client/ConfigResourceClientAutoConfiguration.java
This file contains hidden or 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,55 @@ | ||
| /* | ||
| * Copyright 2013-present 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.config.client; | ||
|
|
||
| import org.springframework.beans.factory.ObjectProvider; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Bean; | ||
|
|
||
| /** | ||
| * Auto-configuration for a {@link ConfigResourceClient} that reads plain text and binary | ||
| * files from the config server with the connection that loaded the configuration, when it | ||
| * was imported with {@code spring.config.import}. | ||
| * | ||
| * @author Daniel Lavoie | ||
| * @author Roy Clarkson | ||
| * @author Dylan Roberts | ||
| * @author Sharang Gupta | ||
| * @since 5.1.0 | ||
| */ | ||
| @AutoConfiguration(after = ConfigClientAutoConfiguration.class) | ||
| @ConditionalOnProperty(name = ConfigClientProperties.PREFIX + ".enabled", matchIfMissing = true) | ||
| public class ConfigResourceClientAutoConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean(ConfigResourceClient.class) | ||
| @ConditionalOnBean(ConfigServerRestClientHolder.class) | ||
| public ConfigResourceClient configResourceClient(ConfigServerRestClientHolder restClientHolder, | ||
| @Qualifier(ConfigServerConfigDataLocationResolver.PROPERTIES_BEAN_NAME) ObjectProvider<ConfigClientProperties> importedProperties, | ||
| ObjectProvider<ConfigClientProperties> properties) { | ||
| // The properties resolved by the config server import describe the server the | ||
| // RestClient talks to; a context may also hold the ones bound by | ||
| // ConfigClientAutoConfiguration. | ||
| return new DefaultConfigResourceClient(restClientHolder.getRestClient(), | ||
| importedProperties.getIfAvailable(properties::getObject)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
...t/src/main/java/org/springframework/cloud/config/client/ConfigServerRestClientHolder.java
This file contains hidden or 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,51 @@ | ||
| /* | ||
| * Copyright 2013-present 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.config.client; | ||
|
|
||
| import org.springframework.util.Assert; | ||
| import org.springframework.web.client.RestClient; | ||
|
|
||
| /** | ||
| * Holds the {@link RestClient} built from the {@code RestTemplate} that loaded the | ||
| * configuration from the config server, which carries the client's headers, credentials, | ||
| * TLS settings, timeouts and interceptors. It is registered as a bean of its own type, | ||
| * not as a {@link RestClient}, so that it is neither ambiguous with the application's own | ||
| * {@link RestClient} nor injected into it by accident. | ||
| * | ||
| * @author Sharang Gupta | ||
| * @since 5.1.0 | ||
| */ | ||
| final class ConfigServerRestClientHolder { | ||
|
|
||
| /** | ||
| * Name of the bean registered when the configuration is imported from the config | ||
| * server. | ||
| */ | ||
| static final String BEAN_NAME = "configServerRestClientHolder"; | ||
|
|
||
| private final RestClient restClient; | ||
|
|
||
| ConfigServerRestClientHolder(RestClient restClient) { | ||
| Assert.notNull(restClient, "RestClient must not be null"); | ||
| this.restClient = restClient; | ||
| } | ||
|
|
||
| RestClient getRestClient() { | ||
| return this.restClient; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should validate this in some way. A negative number does not really make sense in this case. Also I wonder if setting it to 0 would be away to disable the limit?