forked from giantswarm/aws-operator
/
current.go
40 lines (31 loc) · 862 Bytes
/
current.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package kmskey
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/giantswarm/microerror"
"github.com/giantswarm/aws-operator/service/awsconfig/v3/key"
)
func (r *Resource) GetCurrentState(ctx context.Context, obj interface{}) (interface{}, error) {
currentState := KMSKeyState{}
customObject, err := key.ToCustomObject(obj)
if err != nil {
return currentState, err
}
clusterID := key.ClusterID(customObject)
alias := toAlias(clusterID)
input := &kms.DescribeKeyInput{
KeyId: aws.String(alias),
}
output, err := r.awsClients.KMS.DescribeKey(input)
if IsKeyNotFound(err) {
// Fall through.
return nil, nil
}
if err != nil {
return currentState, microerror.Mask(err)
}
currentState.KeyID = *output.KeyMetadata.KeyId
currentState.KeyAlias = alias
return currentState, nil
}