@@ -22,6 +22,8 @@ import (
2222 "cloud.google.com/go/storage"
2323 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
25+ gcp "github.com/crossplane-contrib/provider-gcp/pkg/clients"
26+
2527 xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
2628)
2729
@@ -605,8 +607,7 @@ type BucketUpdatableAttrs struct {
605607 //
606608 // +optional
607609 // +kubebuilder:validation:Enum="";unspecified;inherited;enforced
608- // +kubebuilder:default:=""
609- PublicAccessPrevention string `json:"publicAccessPrevention,omitempty"`
610+ PublicAccessPrevention * string `json:"publicAccessPrevention,omitempty"`
610611
611612 // RequesterPays reports whether the bucket is a Requester Pays bucket.
612613 // Clients performing operations on Requester Pays buckets must provide
@@ -646,7 +647,7 @@ func NewBucketUpdatableAttrs(ba *storage.BucketAttrs) *BucketUpdatableAttrs {
646647 Logging : NewBucketLogging (ba .Logging ),
647648 PredefinedACL : ba .PredefinedACL ,
648649 PredefinedDefaultObjectACL : ba .PredefinedDefaultObjectACL ,
649- PublicAccessPrevention : ba .PublicAccessPrevention . String ( ),
650+ PublicAccessPrevention : convertPublicAccessPreventionEnumToStringPtr ( ba .PublicAccessPrevention ),
650651 RequesterPays : ba .RequesterPays ,
651652 RetentionPolicy : NewRetentionPolicy (ba .RetentionPolicy ),
652653 VersioningEnabled : ba .VersioningEnabled ,
@@ -656,8 +657,13 @@ func NewBucketUpdatableAttrs(ba *storage.BucketAttrs) *BucketUpdatableAttrs {
656657
657658// convertPublicAccessPreventionStringToEnum converts a string representation of storage.PublicAccessPrevention to its
658659// enum value.
659- func convertPublicAccessPreventionStringToEnum (pap string ) storage.PublicAccessPrevention {
660- switch pap {
660+ func convertPublicAccessPreventionStringToEnum (pap * string ) storage.PublicAccessPrevention {
661+ // if the field is not set, treat it as unknown
662+ if pap == nil {
663+ return storage .PublicAccessPreventionUnknown
664+ }
665+
666+ switch * pap {
661667 case "unspecified" , "inherited" :
662668 return storage .PublicAccessPreventionInherited
663669 case "enforced" :
@@ -667,6 +673,16 @@ func convertPublicAccessPreventionStringToEnum(pap string) storage.PublicAccessP
667673 }
668674}
669675
676+ // convertPublicAccessPreventionEnumToStringPtr converts an enum value of storage.PublicAccessPrevention to its
677+ // string pointer value used in BucketUpdatableAttrs.
678+ func convertPublicAccessPreventionEnumToStringPtr (pap storage.PublicAccessPrevention ) * string {
679+ if pap == storage .PublicAccessPreventionUnknown {
680+ return nil
681+ }
682+
683+ return gcp .StringPtr (pap .String ())
684+ }
685+
670686// CopyToBucketAttrs create a copy in storage format
671687func CopyToBucketAttrs (ba * BucketUpdatableAttrs ) * storage.BucketAttrs {
672688 if ba == nil {
@@ -750,7 +766,7 @@ type BucketSpecAttrs struct {
750766 StorageClass string `json:"storageClass,omitempty"`
751767}
752768
753- // NewBucketSpecAttrs create new instance from storage BuckateAttrs
769+ // NewBucketSpecAttrs create new instance from storage.BucketAttrs
754770func NewBucketSpecAttrs (ba * storage.BucketAttrs ) BucketSpecAttrs {
755771 if ba == nil {
756772 return BucketSpecAttrs {}
0 commit comments