@@ -22,6 +22,7 @@ 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"
2526 xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
2627)
2728
@@ -605,8 +606,7 @@ type BucketUpdatableAttrs struct {
605606 //
606607 // +optional
607608 // +kubebuilder:validation:Enum="";unspecified;inherited;enforced
608- // +kubebuilder:default:=""
609- PublicAccessPrevention string `json:"publicAccessPrevention,omitempty"`
609+ PublicAccessPrevention * string `json:"publicAccessPrevention,omitempty"`
610610
611611 // RequesterPays reports whether the bucket is a Requester Pays bucket.
612612 // Clients performing operations on Requester Pays buckets must provide
@@ -646,7 +646,7 @@ func NewBucketUpdatableAttrs(ba *storage.BucketAttrs) *BucketUpdatableAttrs {
646646 Logging : NewBucketLogging (ba .Logging ),
647647 PredefinedACL : ba .PredefinedACL ,
648648 PredefinedDefaultObjectACL : ba .PredefinedDefaultObjectACL ,
649- PublicAccessPrevention : ba .PublicAccessPrevention . String ( ),
649+ PublicAccessPrevention : convertPublicAccessPreventionEnumToStringPtr ( ba .PublicAccessPrevention ),
650650 RequesterPays : ba .RequesterPays ,
651651 RetentionPolicy : NewRetentionPolicy (ba .RetentionPolicy ),
652652 VersioningEnabled : ba .VersioningEnabled ,
@@ -656,8 +656,13 @@ func NewBucketUpdatableAttrs(ba *storage.BucketAttrs) *BucketUpdatableAttrs {
656656
657657// convertPublicAccessPreventionStringToEnum converts a string representation of storage.PublicAccessPrevention to its
658658// enum value.
659- func convertPublicAccessPreventionStringToEnum (pap string ) storage.PublicAccessPrevention {
660- switch pap {
659+ func convertPublicAccessPreventionStringToEnum (pap * string ) storage.PublicAccessPrevention {
660+ // if the field is not set, treat it as unknown
661+ if pap == nil {
662+ return storage .PublicAccessPreventionUnknown
663+ }
664+
665+ switch * pap {
661666 case "unspecified" , "inherited" :
662667 return storage .PublicAccessPreventionInherited
663668 case "enforced" :
@@ -667,6 +672,16 @@ func convertPublicAccessPreventionStringToEnum(pap string) storage.PublicAccessP
667672 }
668673}
669674
675+ // convertPublicAccessPreventionEnumToStringPtr converts an enum value of storage.PublicAccessPrevention to its
676+ // string pointer value used in BucketUpdatableAttrs.
677+ func convertPublicAccessPreventionEnumToStringPtr (pap storage.PublicAccessPrevention ) * string {
678+ if pap == storage .PublicAccessPreventionUnknown {
679+ return nil
680+ }
681+
682+ return gcp .StringPtr (pap .String ())
683+ }
684+
670685// CopyToBucketAttrs create a copy in storage format
671686func CopyToBucketAttrs (ba * BucketUpdatableAttrs ) * storage.BucketAttrs {
672687 if ba == nil {
@@ -750,7 +765,7 @@ type BucketSpecAttrs struct {
750765 StorageClass string `json:"storageClass,omitempty"`
751766}
752767
753- // NewBucketSpecAttrs create new instance from storage BuckateAttrs
768+ // NewBucketSpecAttrs create new instance from storage.BucketAttrs
754769func NewBucketSpecAttrs (ba * storage.BucketAttrs ) BucketSpecAttrs {
755770 if ba == nil {
756771 return BucketSpecAttrs {}
0 commit comments