Skip to content

Commit

Permalink
bucket policy: moved bucketpolicy to v1alpha2
Browse files Browse the repository at this point in the history
Signed-off-by: Krish Chowdhary <krish@redhat.com>
  • Loading branch information
Krish Chowdhary committed Oct 26, 2020
1 parent 77c50d5 commit 99e30e5
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 73 deletions.
4 changes: 2 additions & 2 deletions apis/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
notificationv1alpha3 "github.com/crossplane/provider-aws/apis/notification/v1alpha1"
redshiftv1alpha1 "github.com/crossplane/provider-aws/apis/redshift/v1alpha1"
route53v1alpha1 "github.com/crossplane/provider-aws/apis/route53/v1alpha1"
s3v1alpha1 "github.com/crossplane/provider-aws/apis/s3/v1alpha1"
s3v1alpha2 "github.com/crossplane/provider-aws/apis/s3/v1alpha2"
s3v1beta1 "github.com/crossplane/provider-aws/apis/s3/v1beta1"
sqsv1beta1 "github.com/crossplane/provider-aws/apis/sqs/v1beta1"
awsv1alpha3 "github.com/crossplane/provider-aws/apis/v1alpha3"
Expand All @@ -62,7 +62,7 @@ func init() {
awsv1alpha3.SchemeBuilder.AddToScheme,
awsv1beta1.SchemeBuilder.AddToScheme,
acmv1alpha1.SchemeBuilder.AddToScheme,
s3v1alpha1.SchemeBuilder.AddToScheme,
s3v1alpha2.SchemeBuilder.AddToScheme,
s3v1beta1.SchemeBuilder.AddToScheme,
acmpcav1alpha1.SchemeBuilder.AddToScheme,
databasev1alpha1.SchemeBuilder.AddToScheme,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2020 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.
Expand All @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
8 changes: 4 additions & 4 deletions apis/s3/v1alpha1/doc.go → apis/s3/v1alpha2/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2020 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.
Expand All @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains configuration resources for AWS S3 services such as
// Package v1alpha2 contains configuration resources for AWS S3 services such as
// S3.
// +kubebuilder:object:generate=true
// +groupName=s3.aws.crossplane.io
// +versionName=v1alpha1
package v1alpha1
// +versionName=v1alpha2
package v1alpha2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2020 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
Expand All @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1alpha2

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions apis/s3/v1alpha1/register.go → apis/s3/v1alpha2/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Crossplane Authors.
Copyright 2020 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.
Expand All @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1alpha2

import (
"reflect"
Expand All @@ -26,7 +26,7 @@ import (
// Package type metadata.
const (
Group = "s3.aws.crossplane.io"
Version = "v1alpha1"
Version = "v1alpha2"
)

var (
Expand Down

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

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

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

2 changes: 1 addition & 1 deletion examples/s3/bucket.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: s3.aws.crossplane.io/v1beta1
kind: Bucket
metadata:
name: test-bucket-rh-krish
name: test-bucket
spec:
deletionPolicy: Delete
forProvider:
Expand Down
4 changes: 2 additions & 2 deletions examples/s3/bucketpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spec:
forProvider:
region: us-west-1
bucketNameRef:
name: test-bucket-rh-krish
name: test-bucket
statement:
- action:
- s3:ListBucket
Expand All @@ -19,7 +19,7 @@ spec:
- IAMUserArnSelector:
example: "true"
resource:
- "arn:aws:s3:::test-bucket-rh-krish"
- "arn:aws:s3:::test-bucket"
condition:
IpAddress:
key: "aws:SourceIp"
Expand Down
4 changes: 2 additions & 2 deletions package/crds/s3.aws.crossplane.io_bucketpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ spec:
required:
- spec
type: object
version: v1alpha1
version: v1alpha2
versions:
- name: v1alpha1
- name: v1alpha2
served: true
storage: true
status:
Expand Down
12 changes: 6 additions & 6 deletions pkg/clients/s3/bucketpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws/awserr"
"github.com/aws/aws-sdk-go-v2/service/s3"

"github.com/crossplane/provider-aws/apis/s3/v1alpha1"
"github.com/crossplane/provider-aws/apis/s3/v1alpha2"
)

// BucketPolicyClient is the external client used for S3BucketPolicy Custom Resource
Expand Down Expand Up @@ -55,7 +55,7 @@ func IsErrorBucketNotFound(err error) bool {
}

// Serialize is the custom marshaller for the BucketPolicyParameters
func Serialize(p v1alpha1.BucketPolicyParameters) (interface{}, error) {
func Serialize(p v1alpha2.BucketPolicyParameters) (interface{}, error) {
m := make(map[string]interface{})
m["Version"] = p.PolicyVersion
if p.PolicyID != "" {
Expand All @@ -74,7 +74,7 @@ func Serialize(p v1alpha1.BucketPolicyParameters) (interface{}, error) {
}

// SerializeBucketPolicyStatement is the custom marshaller for the BucketPolicyStatement
func SerializeBucketPolicyStatement(p v1alpha1.BucketPolicyStatement) (interface{}, error) { // nolint:gocyclo
func SerializeBucketPolicyStatement(p v1alpha2.BucketPolicyStatement) (interface{}, error) { // nolint:gocyclo
m := make(map[string]interface{})
if p.Principal != nil {
principal, err := SerializeBucketPrincipal(p.Principal)
Expand Down Expand Up @@ -117,7 +117,7 @@ func SerializeBucketPolicyStatement(p v1alpha1.BucketPolicyStatement) (interface
}

// SerializeBucketPrincipal is the custom serializer for the BucketPrincipal
func SerializeBucketPrincipal(p *v1alpha1.BucketPrincipal) (interface{}, error) {
func SerializeBucketPrincipal(p *v1alpha2.BucketPrincipal) (interface{}, error) {
all := "*"
if p.AllowAnon {
return all, nil
Expand All @@ -142,7 +142,7 @@ func SerializeBucketPrincipal(p *v1alpha1.BucketPrincipal) (interface{}, error)
}

// SerializeAWSPrincipal converts an AWSPrincipal to a string
func SerializeAWSPrincipal(p v1alpha1.AWSPrincipal) *string {
func SerializeAWSPrincipal(p v1alpha2.AWSPrincipal) *string {
switch {
case p.AWSAccountID != nil:
return p.AWSAccountID
Expand All @@ -157,7 +157,7 @@ func SerializeAWSPrincipal(p v1alpha1.AWSPrincipal) *string {

// SerializeBucketCondition converts the string -> Condition map
// into a serialized version
func SerializeBucketCondition(p map[string]v1alpha1.Condition) (interface{}, error) {
func SerializeBucketCondition(p map[string]v1alpha2.Condition) (interface{}, error) {
m := make(map[string]interface{})
for k, v := range p {
subMap := make(map[string]interface{})
Expand Down
30 changes: 15 additions & 15 deletions pkg/clients/s3/bucketpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/test"
"github.com/google/go-cmp/cmp"

"github.com/crossplane/provider-aws/apis/s3/v1alpha1"
"github.com/crossplane/provider-aws/apis/s3/v1alpha2"
aws "github.com/crossplane/provider-aws/pkg/clients"
)

Expand All @@ -33,34 +33,34 @@ var (
statementID = aws.String("1")
)

type statementModifier func(statement *v1alpha1.BucketPolicyStatement)
type statementModifier func(statement *v1alpha2.BucketPolicyStatement)

func withPrincipal(s *v1alpha1.BucketPrincipal) statementModifier {
return func(statement *v1alpha1.BucketPolicyStatement) {
func withPrincipal(s *v1alpha2.BucketPrincipal) statementModifier {
return func(statement *v1alpha2.BucketPolicyStatement) {
statement.Principal = s
}
}

func withPolicyAction(s []string) statementModifier {
return func(statement *v1alpha1.BucketPolicyStatement) {
return func(statement *v1alpha2.BucketPolicyStatement) {
statement.PolicyAction = s
}
}

func withResourcePath(s []string) statementModifier {
return func(statement *v1alpha1.BucketPolicyStatement) {
return func(statement *v1alpha2.BucketPolicyStatement) {
statement.ResourcePath = s
}
}

func withConditionBlock(m map[string]v1alpha1.Condition) statementModifier {
return func(statement *v1alpha1.BucketPolicyStatement) {
func withConditionBlock(m map[string]v1alpha2.Condition) statementModifier {
return func(statement *v1alpha2.BucketPolicyStatement) {
statement.ConditionBlock = m
}
}

func policyStatement(m ...statementModifier) *v1alpha1.BucketPolicyStatement {
cr := &v1alpha1.BucketPolicyStatement{
func policyStatement(m ...statementModifier) *v1alpha2.BucketPolicyStatement {
cr := &v1alpha2.BucketPolicyStatement{
StatementID: statementID,
Effect: effect,
}
Expand All @@ -72,7 +72,7 @@ func policyStatement(m ...statementModifier) *v1alpha1.BucketPolicyStatement {

func TestSerializeBucketPolicyStatement(t *testing.T) {
cases := map[string]struct {
in v1alpha1.BucketPolicyStatement
in v1alpha2.BucketPolicyStatement
out string
err error
}{
Expand All @@ -82,7 +82,7 @@ func TestSerializeBucketPolicyStatement(t *testing.T) {
},
"ValidInput": {
in: *policyStatement(
withPrincipal(&v1alpha1.BucketPrincipal{
withPrincipal(&v1alpha2.BucketPrincipal{
AllowAnon: true,
}),
withPolicyAction([]string{"s3:ListBucket"}),
Expand All @@ -92,8 +92,8 @@ func TestSerializeBucketPolicyStatement(t *testing.T) {
},
"ComplexInput": {
in: *policyStatement(
withPrincipal(&v1alpha1.BucketPrincipal{
AWSPrincipals: []v1alpha1.AWSPrincipal{
withPrincipal(&v1alpha2.BucketPrincipal{
AWSPrincipals: []v1alpha2.AWSPrincipal{
{
IAMUserARN: aws.String("arn:aws:iam::111122223333:userARN"),
},
Expand All @@ -107,7 +107,7 @@ func TestSerializeBucketPolicyStatement(t *testing.T) {
}),
withPolicyAction([]string{"s3:ListBucket"}),
withResourcePath([]string{"arn:aws:s3:::test.s3.crossplane.com"}),
withConditionBlock(map[string]v1alpha1.Condition{
withConditionBlock(map[string]v1alpha2.Condition{
"test": {
ConditionKey: "test",
ConditionStringValue: aws.String("testKey"),
Expand Down
Loading

0 comments on commit 99e30e5

Please sign in to comment.