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

IAMUserPolicyAttachment #196

Merged
merged 4 commits into from
Apr 29, 2020
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
93 changes: 93 additions & 0 deletions apis/identity/v1alpha1/iamuserpolicyattachment_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2019 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

runtimev1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
)

// IAMUserPolicyAttachmentParameters define the desired state of an AWS IAMUserPolicyAttachment.
type IAMUserPolicyAttachmentParameters struct {

// PolicyARN is the Amazon Resource Name (ARN) of the IAM policy you want to
// attach.
// +immutable
PolicyARN string `json:"policyArn"`

// UserName presents the name of the IAMUser.
// +optional
UserName *string `json:"userName,omitempty"`

// UserNameRef references to an IAMUser to retrieve its userName
// +optional
UserNameRef *runtimev1alpha1.Reference `json:"userNameRef,omitempty"`

// UserNameSelector selects a reference to an IAMUser to retrieve its userName
// +optional
UserNameSelector *runtimev1alpha1.Selector `json:"userNameSelector,omitempty"`
}

// An IAMUserPolicyAttachmentSpec defines the desired state of an
// IAMUserPolicyAttachment.
type IAMUserPolicyAttachmentSpec struct {
runtimev1alpha1.ResourceSpec `json:",inline"`
ForProvider IAMUserPolicyAttachmentParameters `json:"forProvider"`
}

// IAMUserPolicyAttachmentObservation keeps the state for the external resource
type IAMUserPolicyAttachmentObservation struct {
// AttachedPolicyARN is the arn for the attached policy. If nil, the policy
// is not yet attached
AttachedPolicyARN string `json:"attachedPolicyArn"`
}

// An IAMUserPolicyAttachmentStatus represents the observed state of an
// IAMUserPolicyAttachment.
type IAMUserPolicyAttachmentStatus struct {
runtimev1alpha1.ResourceStatus `json:",inline"`
AtProvider IAMUserPolicyAttachmentObservation `json:"atProvider"`
}

// +kubebuilder:object:root=true

// An IAMUserPolicyAttachment is a managed resource that represents an AWS IAM
// User policy attachment.
// +kubebuilder:printcolumn:name="USERNAME",type="string",JSONPath=".spec.forProvider.userName"
// +kubebuilder:printcolumn:name="POLICYARN",type="string",JSONPath=".spec.forProvider.policyArn"
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
type IAMUserPolicyAttachment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IAMUserPolicyAttachmentSpec `json:"spec"`
Status IAMUserPolicyAttachmentStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// IAMUserPolicyAttachmentList contains a list of IAMUserPolicyAttachments
type IAMUserPolicyAttachmentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []IAMUserPolicyAttachment `json:"items"`
}
42 changes: 42 additions & 0 deletions apis/identity/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2019 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"
"sigs.k8s.io/controller-runtime/pkg/client"
)

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

// Resolve spec.forProvider.userName
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.UserName),
Reference: mg.Spec.ForProvider.UserNameRef,
Selector: mg.Spec.ForProvider.UserNameSelector,
To: reference.To{Managed: &IAMUser{}, List: &IAMUserList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return err
}
mg.Spec.ForProvider.UserName = reference.ToPtrValue(rsp.ResolvedValue)
mg.Spec.ForProvider.UserNameRef = rsp.ResolvedReference

return nil
}
11 changes: 10 additions & 1 deletion apis/identity/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@ var (
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
)

// User type metadata.
// IAMUser type metadata.
var (
IAMUserKind = reflect.TypeOf(IAMUser{}).Name()
IAMUserGroupKind = schema.GroupKind{Group: Group, Kind: IAMUserKind}.String()
IAMUserKindAPIVersion = IAMUserKind + "." + SchemeGroupVersion.String()
IAMUserGroupVersionKind = SchemeGroupVersion.WithKind(IAMUserKind)
)

// IAMUserPolicyAttachment type metadata.
var (
IAMUserPolicyAttachmentKind = reflect.TypeOf(IAMUserPolicyAttachment{}).Name()
IAMUserPolicyAttachmentGroupKind = schema.GroupKind{Group: Group, Kind: IAMUserPolicyAttachmentKind}.String()
IAMUserPolicyAttachmentKindAPIVersion = IAMUserPolicyAttachmentKind + "." + SchemeGroupVersion.String()
IAMUserPolicyAttachmentGroupVersionKind = SchemeGroupVersion.WithKind(IAMUserPolicyAttachmentKind)
)

func init() {
SchemeBuilder.Register(&IAMUser{}, &IAMUserList{})
SchemeBuilder.Register(&IAMUserPolicyAttachment{}, &IAMUserPolicyAttachmentList{})
}
139 changes: 139 additions & 0 deletions apis/identity/v1alpha1/zz_generated.deepcopy.go

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

70 changes: 70 additions & 0 deletions apis/identity/v1alpha1/zz_generated.managed.go

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

Loading