func getKeyInfo()

in aws/pkg/value/encryption/envelope/awskms/service.go [108:130]


func getKeyInfo(kmsClient kmsiface.KMSAPI, keyARN string) (string, error) {
	// Check arguments
	if types.IsNil(kmsClient) {
		return "", fmt.Errorf("unable to initialize awskms service with nil client")
	}
	if keyARN == "" {
		return "", fmt.Errorf("unable to initialize awskms service with blank key")
	}

	// Retrieve key information from AWS
	keyInfo, err := kmsClient.DescribeKey(&kms.DescribeKeyInput{
		KeyId: aws.String(keyARN),
	})
	if err != nil {
		return "", fmt.Errorf("error fetching AWS KMS information: %w", err)
	}
	if keyInfo == nil || keyInfo.KeyMetadata == nil || keyInfo.KeyMetadata.KeyId == nil {
		return "", errors.New("no key returned")
	}

	// No error
	return aws.StringValue(keyInfo.KeyMetadata.KeyId), nil
}