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

Implements kms(cmk) alias #779

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions apis/kms/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package v1alpha1

import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"

// CustomKeyParameters are custom parameters for Key.
type CustomKeyParameters struct {
// Specifies whether the CMK is enabled.
Expand All @@ -8,3 +10,18 @@ type CustomKeyParameters struct {
// Specifies how many days the Key is retained when scheduled for deletion. Defaults to 30 days.
PendingWindowInDays *int64 `json:"pendingWindowInDays,omitempty"`
}

// CustomAliasParameters are custom parameters for Alias.
type CustomAliasParameters struct {
// Associates the alias with the specified customer managed CMK (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk). The CMK must be in the same AWS Region. \n A valid CMK ID is required. If you supply a null or empty string value, this operation returns an error. \n For help finding the key ID and ARN, see Finding the Key ID and ARN (https://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html#find-cmk-id-arn) in the AWS Key Management Service Developer Guide. \n Specify the key ID or the Amazon Resource Name (ARN) of the CMK. \n For example: \n * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab \n * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab \n To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey.
// +optional
TargetKeyID *string `json:"targetKeyID,omitempty"`

// TargetKeyIDRef is a reference to a KMS Key used to set TargetKeyID.
// +optional
TargetKeyIDRef *xpv1.Reference `json:"targetKeyIDRef,omitempty"`

// TargetKeyIDSelector selects a reference to a KMS Key used to set TargetKeyID.
// +optional
TargetKeyIDSelector *xpv1.Selector `json:"targetKeyIDSelector,omitempty"`
}
12 changes: 9 additions & 3 deletions apis/kms/v1alpha1/generator-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ignore:
resource_names:
- CustomKeyStore
- Grant
- Alias
- CustomKeyStore
- Grant
field_paths:
- CreateAliasInput.TargetKeyId
resources:
Key:
exceptions:
Expand All @@ -11,3 +12,8 @@ resources:
# so the IsNotFound() function is generated correctly
404:
code: NotFoundException
Alias:
exceptions:
errors:
404:
code: NotFoundException
43 changes: 43 additions & 0 deletions apis/kms/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2021 The Crossplane Authors.
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 v1alpha1

import (
"context"

"github.com/crossplane/crossplane-runtime/pkg/reference"
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// ResolveReferences of this Alias
func (mg *Alias) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// Resolve spec.forProvider.targetKeyID
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.TargetKeyID),
Reference: mg.Spec.ForProvider.TargetKeyIDRef,
Selector: mg.Spec.ForProvider.TargetKeyIDSelector,
To: reference.To{Managed: &Key{}, List: &KeyList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.targetKeyID")
}
mg.Spec.ForProvider.TargetKeyID = reference.ToPtrValue(rsp.ResolvedValue)
mg.Spec.ForProvider.TargetKeyIDRef = rsp.ResolvedReference

return nil
}
94 changes: 94 additions & 0 deletions apis/kms/v1alpha1/zz_alias.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 165 additions & 0 deletions apis/kms/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading