|
| 1 | +// Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"). You may |
| 4 | +// not use this file except in compliance with the License. A copy of the |
| 5 | +// License is located at |
| 6 | +// |
| 7 | +// http://aws.amazon.com/apache2.0/ |
| 8 | +// |
| 9 | +// or in the "license" file accompanying this file. This file is distributed |
| 10 | +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | +// express or implied. See the License for the specific language governing |
| 12 | +// permissions and limitations under the License. |
| 13 | + |
| 14 | +package secretsmanager |
| 15 | + |
| 16 | +import ( |
| 17 | + "github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients" |
| 18 | + "github.com/aws/amazon-ecs-cli/ecs-cli/modules/config" |
| 19 | + "github.com/aws/aws-sdk-go/service/secretsmanager" |
| 20 | + "github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface" |
| 21 | +) |
| 22 | + |
| 23 | +// SMClient defines methods for interacting with the SecretsManagerAPI interface |
| 24 | +type SMClient interface { |
| 25 | + CreateSecret(secretsmanager.CreateSecretInput) (*secretsmanager.CreateSecretOutput, error) |
| 26 | + ListSecrets(*string) (*secretsmanager.ListSecretsOutput, error) |
| 27 | +} |
| 28 | + |
| 29 | +type secretsManagerClient struct { |
| 30 | + client secretsmanageriface.SecretsManagerAPI |
| 31 | +} |
| 32 | + |
| 33 | +// NewSecretsManagerClient creates an instance of an secretsManagerClient |
| 34 | +func NewSecretsManagerClient(config *config.CommandConfig) SMClient { |
| 35 | + client := secretsmanager.New(config.Session) |
| 36 | + client.Handlers.Build.PushBackNamed(clients.CustomUserAgentHandler()) |
| 37 | + |
| 38 | + return newClient(client) |
| 39 | +} |
| 40 | + |
| 41 | +func newClient(client secretsmanageriface.SecretsManagerAPI) SMClient { |
| 42 | + return &secretsManagerClient{ |
| 43 | + client: client, |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func (c *secretsManagerClient) CreateSecret(input secretsmanager.CreateSecretInput) (*secretsmanager.CreateSecretOutput, error) { |
| 48 | + output, err := c.client.CreateSecret(&input) |
| 49 | + |
| 50 | + if err != nil { |
| 51 | + return nil, err |
| 52 | + } |
| 53 | + |
| 54 | + return output, nil |
| 55 | +} |
| 56 | + |
| 57 | +func (c *secretsManagerClient) ListSecrets(nextToken *string) (*secretsmanager.ListSecretsOutput, error) { |
| 58 | + request := secretsmanager.ListSecretsInput{ |
| 59 | + NextToken: nextToken, |
| 60 | + } |
| 61 | + output, err := c.client.ListSecrets(&request) |
| 62 | + |
| 63 | + if err != nil { |
| 64 | + return nil, err |
| 65 | + } |
| 66 | + |
| 67 | + return output, nil |
| 68 | +} |
0 commit comments