This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add secret resolver factory methods to secrets extension (#300)
Description =========== This patch adds factory methods for the internal secret resolver classes. This allows to create these resolvers without exporting the internal classes and their constructors etc to the public API. The provided API for this is behind a traid `SecretResolverFactory` I also added two helper methods to create AwsCredentialsProvider objects. ```groovy SecretResolver awsSecretResolver(AwsCredentialsProvider credentials, Region region) SecretResolver awsSecretResolver(String profileName, Region region) SecretResolver awsSecretResolver(Region region) SecretResolver environmentResolver() SecretResolver chainResolver(SecretResolver... resolvers) SecretResolver chainResolver(Iterable<SecretResolver> resolvers) AwsCredentialsProvider awsCredentialsProvider(String profileName) AwsCredentialsProvider awsCredentialsProvider(String profileName, ProfileFile profileFile) ``` Changes ======= * ![ADD] `SecretResolverFactory` methods to secrets extension
- Loading branch information
Showing
5 changed files
with
208 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,8 +169,6 @@ class SecretsPluginIntegrationSpec extends SecretsIntegrationSpec { | |
})) | ||
} | ||
""".stripIndent() | ||
|
||
|
||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/groovy/wooga/gradle/secrets/SecretResolverFactory.groovy
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,59 @@ | ||
/* | ||
* Copyright 2021 Wooga GmbH | ||
* | ||
* 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 | ||
* | ||
* http://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 wooga.gradle.secrets | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider | ||
import software.amazon.awssdk.profiles.ProfileFile | ||
import software.amazon.awssdk.regions.Region | ||
import wooga.gradle.secrets.internal.AWSSecretsManagerResolver | ||
import wooga.gradle.secrets.internal.EnvironmentResolver | ||
import wooga.gradle.secrets.internal.SecretResolverChain | ||
|
||
trait SecretResolverFactory { | ||
SecretResolver awsSecretResolver(AwsCredentialsProvider credentials, Region region) { | ||
new AWSSecretsManagerResolver(credentials, region) | ||
} | ||
|
||
SecretResolver awsSecretResolver(String profileName, Region region) { | ||
new AWSSecretsManagerResolver(awsCredentialsProvider(profileName), region) | ||
} | ||
|
||
SecretResolver awsSecretResolver(Region region) { | ||
new AWSSecretsManagerResolver(region) | ||
} | ||
|
||
SecretResolver environmentResolver() { | ||
new EnvironmentResolver() | ||
} | ||
|
||
SecretResolver chainResolver(SecretResolver... resolvers) { | ||
chainResolver(resolvers.toList()) | ||
} | ||
|
||
SecretResolver chainResolver(Iterable<SecretResolver> resolvers) { | ||
new SecretResolverChain(resolvers) | ||
} | ||
|
||
AwsCredentialsProvider awsCredentialsProvider(String profileName) { | ||
awsCredentialsProvider(profileName, ProfileFile.defaultProfileFile()) | ||
} | ||
|
||
AwsCredentialsProvider awsCredentialsProvider(String profileName, ProfileFile profileFile) { | ||
DefaultCredentialsProvider.builder().profileFile(profileFile).profileName(profileName).build() | ||
} | ||
} |
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
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