Skip to content

Commit

Permalink
iamuserpolicy: rename kind 'UserPolicyAttachment' to 'IAMUserPolicyAt…
Browse files Browse the repository at this point in the history
…tachment'

Signed-off-by: sahil-lakhwani <[email protected]>
  • Loading branch information
sahil-lakhwani committed Apr 29, 2020
1 parent f949ca1 commit 2fa94d9
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 211 deletions.
8 changes: 4 additions & 4 deletions apis/identity/v1alpha1/iamuser_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// UserNameReferencer is used to get the Name from a referenced IAM User object
type UserNameReferencer struct {
// IAMUserNameReferencer is used to get the Name from a referenced IAM User object
type IAMUserNameReferencer struct {
corev1.LocalObjectReference `json:",inline"`
}

// GetStatus implements GetStatus method of AttributeReferencer interface
func (v *UserNameReferencer) GetStatus(ctx context.Context, _ resource.CanReference, reader client.Reader) ([]resource.ReferenceStatus, error) {
func (v *IAMUserNameReferencer) GetStatus(ctx context.Context, _ resource.CanReference, reader client.Reader) ([]resource.ReferenceStatus, error) {
return getUserStatus(ctx, v.Name, reader)
}

// Build retrieves and builds the IAM UserName
func (v *UserNameReferencer) Build(ctx context.Context, _ resource.CanReference, reader client.Reader) (string, error) {
func (v *IAMUserNameReferencer) Build(ctx context.Context, _ resource.CanReference, reader client.Reader) (string, error) {
user := IAMUser{}
nn := types.NamespacedName{Name: v.Name}
if err := reader.Get(ctx, nn, &user); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions apis/identity/v1alpha1/iamuser_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestUserNameReferencerGetStatus(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
r := UserNameReferencer{LocalObjectReference: corev1.LocalObjectReference{Name: mockName}}
r := IAMUserNameReferencer{LocalObjectReference: corev1.LocalObjectReference{Name: mockName}}

reader := &mockReader{readFn: func(ctx context.Context, key client.ObjectKey, obj runtime.Object) error {
if diff := cmp.Diff(key, client.ObjectKey{Name: mockName}); diff != "" {
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestUserNameReferencerBuild(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
r := UserNameReferencer{LocalObjectReference: corev1.LocalObjectReference{Name: mockName}}
r := IAMUserNameReferencer{LocalObjectReference: corev1.LocalObjectReference{Name: mockName}}

reader := &mockReader{readFn: func(ctx context.Context, key client.ObjectKey, obj runtime.Object) error {
if diff := cmp.Diff(key, client.ObjectKey{Name: mockName}); diff != "" {
Expand Down
55 changes: 27 additions & 28 deletions apis/identity/v1alpha1/iamuserpolicyattachment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"
)

// UserNameReferencerForUserPolicyAttachment is an attribute referencer that retrieves Name from a referenced User
type UserNameReferencerForUserPolicyAttachment struct {
UserNameReferencer `json:",inline"`
// IAMUserNameReferencerForUserPolicyAttachment is an attribute referencer that retrieves Name from a referenced IAMUser
type IAMUserNameReferencerForUserPolicyAttachment struct {
IAMUserNameReferencer `json:",inline"`
}

// Assign assigns the retrieved name to the managed resource
func (v *UserNameReferencerForUserPolicyAttachment) Assign(res resource.CanReference, value string) error {
p, ok := res.(*UserPolicyAttachment)
func (v *IAMUserNameReferencerForUserPolicyAttachment) Assign(res resource.CanReference, value string) error {
p, ok := res.(*IAMUserPolicyAttachment)
if !ok {
return errors.New(errResourceIsNotUserPolicyAttachment)
}
Expand All @@ -46,48 +46,47 @@ const (
errResourceIsNotUserPolicyAttachment = "the managed resource is not an UserPolicyAttachment"
)

// UserPolicyAttachmentParameters define the desired state of an AWS IAM
// User policy attachment.
type UserPolicyAttachmentParameters struct {
// 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 IAM user.
// UserName presents the name of the IAMUser.
// +optional
UserName string `json:"userName,omitempty"`

// UserNameRef references to an User to retrieve its Name
// UserNameRef references to an IAMUser to retrieve its Name
// +optional
UserNameRef *UserNameReferencerForUserPolicyAttachment `json:"userNameRef,omitempty"`
UserNameRef *IAMUserNameReferencerForUserPolicyAttachment `json:"userNameRef,omitempty"`
}

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

// UserPolicyAttachmentObservation keeps the state for the external resource
type UserPolicyAttachmentObservation struct {
// 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 UserPolicyAttachmentStatus represents the observed state of an
// UserPolicyAttachment.
type UserPolicyAttachmentStatus struct {
// An IAMUserPolicyAttachmentStatus represents the observed state of an
// IAMUserPolicyAttachment.
type IAMUserPolicyAttachmentStatus struct {
runtimev1alpha1.ResourceStatus `json:",inline"`
AtProvider UserPolicyAttachmentObservation `json:"atProvider"`
AtProvider IAMUserPolicyAttachmentObservation `json:"atProvider"`
}

// +kubebuilder:object:root=true

// An UserPolicyAttachment is a managed resource that represents an AWS IAM
// 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"
Expand All @@ -96,19 +95,19 @@ type UserPolicyAttachmentStatus struct {
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
type UserPolicyAttachment struct {
type IAMUserPolicyAttachment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

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

// +kubebuilder:object:root=true

// UserPolicyAttachmentList contains a list of UserPolicyAttachments
type UserPolicyAttachmentList struct {
// IAMUserPolicyAttachmentList contains a list of IAMUserPolicyAttachments
type IAMUserPolicyAttachmentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []UserPolicyAttachment `json:"items"`
Items []IAMUserPolicyAttachment `json:"items"`
}
8 changes: 4 additions & 4 deletions apis/identity/v1alpha1/iamuserpolicyattachment_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/test"
)

var _ resource.AttributeReferencer = (*UserNameReferencerForUserPolicyAttachment)(nil)
var _ resource.AttributeReferencer = (*IAMUserNameReferencerForUserPolicyAttachment)(nil)

func TestUserNameReferencerForUserPolicyAttachment_AssignInvalidType_ReturnsErr(t *testing.T) {

r := &UserNameReferencerForUserPolicyAttachment{}
r := &IAMUserNameReferencerForUserPolicyAttachment{}
expectedErr := errors.New(errResourceIsNotUserPolicyAttachment)

err := r.Assign(nil, "mockValue")
Expand All @@ -41,8 +41,8 @@ func TestUserNameReferencerForUserPolicyAttachment_AssignInvalidType_ReturnsErr(

func TestUserNameReferencerForUserPolicyAttachment_AssignValidType_ReturnsExpected(t *testing.T) {

r := &UserNameReferencerForUserPolicyAttachment{}
res := &UserPolicyAttachment{}
r := &IAMUserNameReferencerForUserPolicyAttachment{}
res := &IAMUserPolicyAttachment{}
var expectedErr error

err := r.Assign(res, "mockValue")
Expand Down
4 changes: 2 additions & 2 deletions apis/identity/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ var (

// UserPolicyAttachment type metadata.
var (
UserPolicyAttachmentKind = reflect.TypeOf(UserPolicyAttachment{}).Name()
UserPolicyAttachmentKind = reflect.TypeOf(IAMUserPolicyAttachment{}).Name()
UserPolicyAttachmentGroupKind = schema.GroupKind{Group: Group, Kind: UserPolicyAttachmentKind}.String()
UserPolicyAttachmentKindAPIVersion = UserPolicyAttachmentKind + "." + SchemeGroupVersion.String()
UserPolicyAttachmentGroupVersionKind = SchemeGroupVersion.WithKind(UserPolicyAttachmentKind)
)

func init() {
SchemeBuilder.Register(&IAMUser{}, &IAMUserList{})
SchemeBuilder.Register(&UserPolicyAttachment{}, &UserPolicyAttachmentList{})
SchemeBuilder.Register(&IAMUserPolicyAttachment{}, &IAMUserPolicyAttachmentList{})
}
Loading

0 comments on commit 2fa94d9

Please sign in to comment.