|
| 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 kms |
| 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/aws" |
| 20 | + "github.com/aws/aws-sdk-go/service/kms" |
| 21 | + "github.com/aws/aws-sdk-go/service/kms/kmsiface" |
| 22 | +) |
| 23 | + |
| 24 | +// Client defines methods for interacting with KMS |
| 25 | +type Client interface { |
| 26 | + DescribeKey(keyID string) (*kms.DescribeKeyOutput, error) |
| 27 | +} |
| 28 | + |
| 29 | +type kmsClient struct { |
| 30 | + client kmsiface.KMSAPI |
| 31 | +} |
| 32 | + |
| 33 | +func NewKMSClient(config *config.CommandConfig) Client { |
| 34 | + client := kms.New(config.Session) |
| 35 | + client.Handlers.Build.PushBackNamed(clients.CustomUserAgentHandler()) |
| 36 | + |
| 37 | + return newClient(client) |
| 38 | +} |
| 39 | + |
| 40 | +func newClient(client kmsiface.KMSAPI) Client { |
| 41 | + return &kmsClient{ |
| 42 | + client: client, |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +func (c *kmsClient) DescribeKey(keyID string) (*kms.DescribeKeyOutput, error) { |
| 47 | + request := kms.DescribeKeyInput{ |
| 48 | + KeyId: aws.String(keyID), |
| 49 | + } |
| 50 | + |
| 51 | + output, err := c.client.DescribeKey(&request) |
| 52 | + if err != nil { |
| 53 | + return nil, err |
| 54 | + } |
| 55 | + |
| 56 | + return output, nil |
| 57 | +} |
0 commit comments