Skip to content
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

Implement Secrets #304

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8a5ba02
Initial resource implementation
iHaoo Aug 4, 2020
5ffef90
Updated finder to convert SecretListEntry to DescribeSecretResponse list
iHaoo Aug 5, 2020
1f3f442
Updated Copyable main model
iHaoo Aug 5, 2020
01bcb16
Added all relevant parameters with corresponding annotations
iHaoo Aug 5, 2020
df7120e
Updated create()
iHaoo Aug 5, 2020
f613eb9
Updated refresh()
iHaoo Aug 5, 2020
012dd2c
Updated update()
iHaoo Aug 5, 2020
ca10895
Updated delete()
iHaoo Aug 5, 2020
6bd7f6f
Updated findAllAws() to set proper parameters
iHaoo Aug 5, 2020
3dc9598
Removed unnecessary id param
iHaoo Aug 5, 2020
cab6c6a
Updated findAllAws to use paginator and stream
iHaoo Aug 5, 2020
f84ebd8
Added helper method to convert SecretListEntry to DescribeSecretResponse
iHaoo Aug 5, 2020
bc0996c
Updated secretBinary to String
iHaoo Aug 6, 2020
efaa567
Removed unnecessary helper method for update()
iHaoo Aug 6, 2020
d99128d
Updated findAws() to properly return filtered result
iHaoo Aug 6, 2020
9a84818
Updated tags to create and update properly
iHaoo Aug 10, 2020
7ceb318
Changed all Instant types to String
iHaoo Aug 11, 2020
940f6f1
Updated delete logic
iHaoo Aug 11, 2020
563ea4c
Updated tag logic to correctly edit tags
iHaoo Aug 11, 2020
42a1406
Added documentation and comments
iHaoo Aug 11, 2020
a5ea2f8
Added secret.gyro example
iHaoo Aug 11, 2020
5a02280
Updated licenses
iHaoo Aug 11, 2020
83b9fbf
Added Required annotation to Name
iHaoo Aug 11, 2020
30e0e9a
Added try/catch clause for secrets not found
iHaoo Aug 11, 2020
3119bd6
Updated example comments
iHaoo Aug 12, 2020
786f485
Updated docs and annotations
iHaoo Aug 12, 2020
386e4ac
Added try/catch clause for not found resource
iHaoo Aug 12, 2020
eb784a0
Set all output fields of newly created secret
iHaoo Aug 12, 2020
8084ad1
Consolidate helper method logic
iHaoo Aug 12, 2020
19cef39
Added empty list default return if no resource is found
iHaoo Aug 13, 2020
ce7b795
Merge branch 'master' into feature/secrets-manager-resource
deepanjan90 Aug 13, 2020
c0148c5
Merge branch 'master' into feature/secrets-manager-resource
deepanjan90 Aug 13, 2020
b2c7f80
Merge branch 'master' of https://github.com/perfectsense/gyro-aws-pro…
iHaoo Aug 13, 2020
241a3fc
Updated kmsKey type to use Resource
iHaoo Aug 13, 2020
8fcd370
Merge branch 'feature/secrets-manager-resource' of https://github.com…
iHaoo Aug 13, 2020
7d1b449
Remove commented line
iHaoo Aug 14, 2020
542d092
Added new lines
iHaoo Aug 14, 2020
cee4b7d
Move variables from read-only
iHaoo Aug 14, 2020
70ea73d
Updated docs and added new line at EOF
iHaoo Aug 14, 2020
f513bc2
Remove redundant check
iHaoo Aug 14, 2020
fbdf4ef
Consolidate builder into lambda expression
iHaoo Aug 14, 2020
d4b80d1
Refactored fetching secrt model
iHaoo Aug 14, 2020
da6d506
Removed Client Request Token
iHaoo Aug 14, 2020
d03470b
Updated Kms Key logic
iHaoo Aug 14, 2020
8d75de9
Updated docs
iHaoo Aug 14, 2020
37bbb9a
Updated secret example script
iHaoo Aug 14, 2020
3b22927
Consolidate Create Secret request into lambda
iHaoo Aug 19, 2020
1a5c005
Refactored refresh logic into method
iHaoo Aug 19, 2020
26ab2a1
Added complex type handling for RotationRulesType
iHaoo Aug 19, 2020
211689e
Updated docs and styling
iHaoo Aug 19, 2020
047be7d
Updated ARN doc
iHaoo Aug 19, 2020
b8a0665
Fixed typo in example
iHaoo Aug 19, 2020
93fa598
Added license onto SecretRotationRulesType
iHaoo Aug 19, 2020
8d4f12e
Updated ArrayList type
iHaoo Aug 21, 2020
399bb10
Updated docs
iHaoo Aug 21, 2020
d4c2f2d
Remove duplicate code
iHaoo Aug 21, 2020
0d9ccef
NPE check
iHaoo Aug 21, 2020
aaabaf4
Add condition for updating secret based on number of changed fields
iHaoo Aug 21, 2020
910c97a
Remove unnecessary primary key
iHaoo Aug 21, 2020
4428a80
Updated finder docs and added 'arn' field
iHaoo Aug 24, 2020
3620b4c
Added condition for update for non-tag fields changed
iHaoo Aug 24, 2020
f15c95c
Updated update conditions
iHaoo Aug 24, 2020
fbb6116
Reduced number of conditions
iHaoo Aug 24, 2020
7f8e141
Remove lines
iHaoo Sep 1, 2020
6a85ed0
Updated variable name
iHaoo Sep 1, 2020
2a0f7a2
Updated copyright info
iHaoo Sep 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dependencies {
implementation 'software.amazon.awssdk:acmpca'
implementation 'software.amazon.awssdk:dynamodb'
implementation 'software.amazon.awssdk:neptune'
implementation 'software.amazon.awssdk:secretsmanager'
implementation 'org.json:json:20180813'

gyroDoclet "gyro:gyro-doclet:0.99.0-SNAPSHOT"
Expand Down
15 changes: 15 additions & 0 deletions examples/secretsmanager/secret.gyro
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
aws::secret secret
name: "secret-example"
description: "secret-example-description-updated"
force-delete-without-recovery: true
kms-key: $(aws::kms-key secret-kms-key-example)
secret-string: "secret-string-example"
tags: {
"secret-example-tag" : "secret-example-tag-value"
}
end

aws::kms-key secret-kms-key-example
aliases: ["alias/secret1", "alias/secret2"]
description: "secret kms key example description"
end
82 changes: 82 additions & 0 deletions src/main/java/gyro/aws/secretsmanager/SecretFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2020, Perfect Sense, Inc.
*
* 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 gyro.aws.secretsmanager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import gyro.aws.AwsFinder;
import gyro.core.Type;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.DescribeSecretResponse;
import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;
import software.amazon.awssdk.services.secretsmanager.model.SecretListEntry;

/**
* Query secrets manager.
*
* Example
* -------
*
* .. code-block:: gyro
*
* secrets: $(external-query aws::secret { arn: 'secret-arn-example'})
*/
iHaoo marked this conversation as resolved.
Show resolved Hide resolved
@Type("secret")
public class SecretFinder extends AwsFinder<SecretsManagerClient, DescribeSecretResponse, SecretResource> {

iHaoo marked this conversation as resolved.
Show resolved Hide resolved
@Override
protected List<DescribeSecretResponse> findAllAws(SecretsManagerClient client) {
return client.listSecretsPaginator().stream().flatMap(list ->
list.secretList().stream().map(this::convertEntry)).collect(Collectors.toList());
}

@Override
protected List<DescribeSecretResponse> findAws(
SecretsManagerClient client, Map<String, String> filters) {
List<DescribeSecretResponse> list = new ArrayList<>();
try {
iHaoo marked this conversation as resolved.
Show resolved Hide resolved

list.add(client.describeSecret(r -> r.secretId(filters.get("arn"))));
} catch (ResourceNotFoundException ex) {
// No resource found
}

return list;
iHaoo marked this conversation as resolved.
Show resolved Hide resolved
}

private DescribeSecretResponse convertEntry(SecretListEntry entry) {
return DescribeSecretResponse.builder()
.arn(entry.arn())
.deletedDate(entry.deletedDate())
.description(entry.description())
.kmsKeyId(entry.kmsKeyId())
.lastAccessedDate(entry.lastAccessedDate())
.lastChangedDate(entry.lastChangedDate())
.lastRotatedDate(entry.lastRotatedDate())
.name(entry.name())
.owningService(entry.owningService())
.rotationEnabled(entry.rotationEnabled())
.rotationLambdaARN(entry.rotationLambdaARN())
.rotationRules(entry.rotationRules())
.tags(entry.tags())
.versionIdsToStages(entry.secretVersionsToStages())
.build();
}
}
Loading