Skip to content

Commit

Permalink
update PR to reflect review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Krish Chowdhary <krish@redhat.com>
  • Loading branch information
krishchow committed Jul 27, 2020
1 parent e62b392 commit ccec8ef
Show file tree
Hide file tree
Showing 16 changed files with 528 additions and 431 deletions.
2 changes: 2 additions & 0 deletions apis/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
identityv1alpha1 "github.com/crossplane/provider-aws/apis/identity/v1alpha1"
identityv1beta1 "github.com/crossplane/provider-aws/apis/identity/v1beta1"
networkv1alpha3 "github.com/crossplane/provider-aws/apis/network/v1alpha3"
storagev1alpha1 "github.com/crossplane/provider-aws/apis/storage/v1alpha1"
storagev1alpha3 "github.com/crossplane/provider-aws/apis/storage/v1alpha3"
awsv1alpha3 "github.com/crossplane/provider-aws/apis/v1alpha3"
)
Expand All @@ -44,6 +45,7 @@ func init() {
networkv1alpha3.SchemeBuilder.AddToScheme,
awsv1alpha3.SchemeBuilder.AddToScheme,
storagev1alpha3.SchemeBuilder.AddToScheme,
storagev1alpha1.SchemeBuilder.AddToScheme,
databasev1alpha1.SchemeBuilder.AddToScheme,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha3
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,16 +25,32 @@ import (
// S3BucketPolicyParameters define the desired state of an AWS S3BucketPolicy.
type S3BucketPolicyParameters struct {
// This is the current IAM policy version
PolicyVersion string `json:"Version"`
PolicyVersion string `json:"version"`

// This is the policy's optional identifier
PolicyID string `json:"Id,omitempty"`
PolicyID string `json:"id,omitempty"`

// This is the list of statement this policy applies
PolicyStatement []S3BucketPolicyStatement `json:"Statement"`
PolicyStatement []S3BucketPolicyStatement `json:"statement"`

// BucketName presents the name of the bucket.
// +optional
BucketName string `json:"bucketName,omitempty"`

// BucketNameRef references to an S3Bucket to retrieve its bucketName
// +optional
BucketNameRef *runtimev1alpha1.Reference `json:"bucketNameRef,omitempty"`

// BucketNameSelector selects a reference to an S3Bucket to retrieve its bucketName
// +optional
BucketNameSelector *runtimev1alpha1.Selector `json:"bucketNameSelector,omitempty"`

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

//Serialize is the custom marshaller for the S3BucketPolicyParameters
// Serialize is the custom marshaller for the S3BucketPolicyParameters
func (p *S3BucketPolicyParameters) Serialize() (interface{}, error) {
m := make(map[string]interface{})
m["Version"] = p.PolicyVersion
Expand All @@ -50,11 +66,6 @@ func (p *S3BucketPolicyParameters) Serialize() (interface{}, error) {
slc[i] = msg
}
m["Statement"] = slc
//dat, err := json.Marshal(m)
//if err != nil {
// return nil, err
//}
//str := string(dat)
return m, nil
}

Expand All @@ -63,29 +74,29 @@ func (p *S3BucketPolicyParameters) Serialize() (interface{}, error) {
type S3BucketPolicyStatement struct {
// Optional identifier for this statement, must be unique within the
// policy if provided.
StatementID string `json:"Sid,omitempty"`
StatementID string `json:"sid,omitempty"`

// The effect is required and specifies whether the statement results
// in an allow or an explicit deny. Valid values for Effect are Allow and Deny.
Effect string `json:"Effect"`
Effect string `json:"effect"`

// Used with the S3 policy to specify the principal that is allowed
// or denied access to a resource.
Principal *S3BucketPrincipal `json:"Principal,omitempty"`
Principal *S3BucketPrincipal `json:"principal,omitempty"`

// Each element of the PolicyAction array describes describes the specific
// action or actions that will be allowed or denied with this PolicyStatement.
PolicyAction []string `json:"Action"`
PolicyAction []string `json:"action"`

// This flag indicates that this policy should apply to the IAMUsername
// that was either passed in or created for this bucket.
ApplyToIAMUser bool `json:"EffectIAMUser,omitempty"`
ApplyToIAMUser bool `json:"effectIAMUser,omitempty"`

// The paths on which this resource will apply
ResourcePath []string `json:"Resource"`
ResourcePath []string `json:"resource"`
}

//Serialize is the custom marshaller for the S3BucketPolicyStatement
// Serialize is the custom marshaller for the S3BucketPolicyStatement
func (p *S3BucketPolicyStatement) Serialize() (interface{}, error) {
m := make(map[string]interface{})
principal, err := p.Principal.Serialize()
Expand All @@ -107,11 +118,11 @@ func (p *S3BucketPolicyStatement) Serialize() (interface{}, error) {
type S3BucketPrincipal struct {
// This flag indicates if the policy should be made available
// to all anonymous users.
AllowAnon bool `json:"AllowAnon,omitempty"`
AllowAnon bool `json:"allowAnon,omitempty"`

// This list contains the all of the AWS IAM users which are affected
// by the policy statement
AWSPrincipal []string `json:"AWS,omitempty"`
AWSPrincipal []string `json:"aws,omitempty"`
}

func tryFirst(slc []string) interface{} {
Expand All @@ -121,7 +132,7 @@ func tryFirst(slc []string) interface{} {
return slc
}

//Serialize is the custom serializer for the S3BucketPrincipal
// Serialize is the custom serializer for the S3BucketPrincipal
func (p *S3BucketPrincipal) Serialize() (interface{}, error) {
all := "*"
if p.AllowAnon {
Expand All @@ -137,29 +148,6 @@ func (p *S3BucketPrincipal) Serialize() (interface{}, error) {
type S3BucketPolicySpec struct {
runtimev1alpha1.ResourceSpec `json:",inline"`
PolicyBody S3BucketPolicyParameters `json:"forProvider"`
// BucketName presents the name of the bucket.
// +optional
BucketName string `json:"bucketName,omitempty"`

// BucketNameRef references to an S3Bucket to retrieve its bucketName
// +optional
BucketNameRef *runtimev1alpha1.Reference `json:"bucketNameRef,omitempty"`

// BucketNameSelector selects a reference to an S3Bucket to retrieve its bucketName
// +optional
BucketNameSelector *runtimev1alpha1.Selector `json:"bucketNameSelector,omitempty"`

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

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

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

// An S3BucketPolicyStatus represents the observed state of an
Expand Down
22 changes: 22 additions & 0 deletions apis/storage/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
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 contains configuration resources for AWS storage services such as
// S3.
// +kubebuilder:object:generate=true
// +groupName=storage.aws.crossplane.io
// +versionName=v1alpha1
package v1alpha1
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha3
package v1alpha1

import (
"context"

"github.com/crossplane/provider-aws/apis/storage/v1alpha3"

"github.com/crossplane/crossplane-runtime/pkg/reference"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -24,7 +26,7 @@ import (
// S3BucketIAMUser returns the Spec.UserName of a S3Bucket.
func S3BucketIAMUser() reference.ExtractValueFn {
return func(mg resource.Managed) string {
r, ok := mg.(*S3Bucket)
r, ok := mg.(*v1alpha3.S3Bucket)
if !ok {
return ""
}
Expand All @@ -37,31 +39,30 @@ func (mg *S3BucketPolicy) ResolveReferences(ctx context.Context, c client.Reader
r := reference.NewAPIResolver(c, mg)
// Resolve spec.BucketName
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.BucketName,
Reference: mg.Spec.BucketNameRef,
Selector: mg.Spec.BucketNameSelector,
To: reference.To{Managed: &S3Bucket{}, List: &S3BucketList{}},
CurrentValue: mg.Spec.PolicyBody.BucketName,
Reference: mg.Spec.PolicyBody.BucketNameRef,
Selector: mg.Spec.PolicyBody.BucketNameSelector,
To: reference.To{Managed: &v1alpha3.S3Bucket{}, List: &v1alpha3.S3BucketList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return err
}
mg.Spec.BucketName = rsp.ResolvedValue
mg.Spec.BucketNameRef = rsp.ResolvedReference
mg.Spec.PolicyBody.BucketName = rsp.ResolvedValue
mg.Spec.PolicyBody.BucketNameRef = rsp.ResolvedReference

// Resolve spec.UserName
rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.UserName,
Reference: mg.Spec.BucketNameRef,
Selector: mg.Spec.BucketNameSelector,
To: reference.To{Managed: &S3Bucket{}, List: &S3BucketList{}},
CurrentValue: mg.Spec.PolicyBody.UserName,
Reference: mg.Spec.PolicyBody.BucketNameRef,
Selector: mg.Spec.PolicyBody.BucketNameSelector,
To: reference.To{Managed: &v1alpha3.S3Bucket{}, List: &v1alpha3.S3BucketList{}},
Extract: S3BucketIAMUser(),
})
if err != nil {
return err
}
mg.Spec.UserName = rsp.ResolvedValue
mg.Spec.UserNameRef = rsp.ResolvedReference
mg.Spec.PolicyBody.UserName = rsp.ResolvedValue

return nil
}
50 changes: 50 additions & 0 deletions apis/storage/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
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 (
"reflect"

"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

// Package type metadata.
const (
Group = "storage.aws.crossplane.io"
Version = "v1alpha1"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
)

// S3BucketPolicy type metadata.
var (
S3BucketPolicyKind = reflect.TypeOf(S3BucketPolicy{}).Name()
S3BucketPolicyGroupKind = schema.GroupKind{Group: Group, Kind: S3BucketPolicyKind}.String()
S3BucketPolicyKindAPIVersion = S3BucketPolicyKind + "." + SchemeGroupVersion.String()
S3BucketPolicyGroupVersionKind = SchemeGroupVersion.WithKind(S3BucketPolicyKind)
)

func init() {
SchemeBuilder.Register(&S3BucketPolicy{}, &S3BucketPolicyList{})
}
Loading

0 comments on commit ccec8ef

Please sign in to comment.