@@ -18,8 +18,8 @@ import (
1818
1919// StorageBucket represents a Google Cloud Storage bucket
2020type StorageBucket struct {
21- Name string `json:"name"`
22- Location string `json:"location"`
21+ Name string `json:"name"`
22+ Location string `json:"location"`
2323}
2424
2525// NewSyncBucketsCmd creates a new cobra command for syncing Storage buckets
@@ -117,13 +117,13 @@ func processBuckets(ctx context.Context, storageClient *storage.Service, project
117117// processBucket handles processing of a single Storage bucket
118118func processBucket (_ context.Context , storageClient * storage.Service , bucket * storage.Bucket , project string ) (api.AgentResource , error ) {
119119 metadata := initBucketMetadata (bucket , project )
120-
120+
121121 // Process IAM policy if available
122122 err := processIamPolicy (storageClient , bucket , metadata )
123123 if err != nil {
124124 log .Error ("Error processing IAM policy" , "error" , err )
125125 }
126-
126+
127127 // Process bucket details
128128 processStorageDetails (bucket , metadata )
129129
@@ -143,11 +143,11 @@ func processBucket(_ context.Context, storageClient *storage.Service, bucket *st
143143 Config : map [string ]any {
144144 "name" : bucket .Name ,
145145 "googleStorage" : map [string ]any {
146- "project" : project ,
147- "location" : bucket .Location ,
148- "storageClass" : bucket .StorageClass ,
146+ "project" : project ,
147+ "location" : bucket .Location ,
148+ "storageClass" : bucket .StorageClass ,
149149 "retentionPolicy" : bucket .RetentionPolicy != nil ,
150- "versioning" : bucket .Versioning != nil && bucket .Versioning .Enabled ,
150+ "versioning" : bucket .Versioning != nil && bucket .Versioning .Enabled ,
151151 },
152152 },
153153 Metadata : metadata ,
@@ -180,23 +180,23 @@ func initBucketMetadata(bucket *storage.Bucket, project string) map[string]strin
180180
181181 metadata := map [string ]string {
182182 // Storage namespace
183- "storage/type" : "google-bucket" ,
184- "storage/bucket" : bucket .Name ,
185- "storage/location" : bucket .Location ,
186- "storage/location-type" : bucket .LocationType ,
187- "storage/storage-class" : bucket .StorageClass ,
188- "storage/created" : created ,
189- "storage/updated" : updated ,
190- "storage/versioning" : fmt .Sprintf ("%v" , bucket .Versioning != nil && bucket .Versioning .Enabled ),
191-
183+ "storage/type" : "google-bucket" ,
184+ "storage/bucket" : bucket .Name ,
185+ "storage/location" : bucket .Location ,
186+ "storage/location-type" : bucket .LocationType ,
187+ "storage/storage-class" : bucket .StorageClass ,
188+ "storage/created" : created ,
189+ "storage/updated" : updated ,
190+ "storage/versioning" : fmt .Sprintf ("%v" , bucket .Versioning != nil && bucket .Versioning .Enabled ),
191+
192192 // Google namespace
193- "google/project" : project ,
194- "google/location" : bucket .Location ,
195- "google/location-type" : bucket .LocationType ,
196- "google/storage-class" : bucket .StorageClass ,
197- "google/console-url" : consoleUrl ,
198- "google/resource-type" : "storage.googleapis.com/Bucket" ,
199- "google/metageneration" : strconv .FormatInt (bucket .Metageneration , 10 ),
193+ "google/project" : project ,
194+ "google/location" : bucket .Location ,
195+ "google/location-type" : bucket .LocationType ,
196+ "google/storage-class" : bucket .StorageClass ,
197+ "google/console-url" : consoleUrl ,
198+ "google/resource-type" : "storage.googleapis.com/Bucket" ,
199+ "google/metageneration" : strconv .FormatInt (bucket .Metageneration , 10 ),
200200 }
201201
202202 if bucket .Etag != "" {
@@ -232,7 +232,7 @@ func initBucketMetadata(bucket *storage.Bucket, project string) map[string]strin
232232 // Add public access prevention information
233233 if bucket .IamConfiguration != nil && bucket .IamConfiguration .PublicAccessPrevention != "" {
234234 metadata ["storage/public-access-prevention" ] = bucket .IamConfiguration .PublicAccessPrevention
235-
235+
236236 // Add uniform bucket-level access information
237237 if bucket .IamConfiguration .UniformBucketLevelAccess != nil {
238238 metadata ["storage/uniform-bucket-access" ] = strconv .FormatBool (bucket .IamConfiguration .UniformBucketLevelAccess .Enabled )
@@ -288,7 +288,7 @@ func initBucketMetadata(bucket *storage.Bucket, project string) map[string]strin
288288 metadata ["storage/cors-methods" ] = strings .Join (methodList , "," )
289289 }
290290 }
291-
291+
292292 return metadata
293293}
294294
@@ -301,7 +301,7 @@ func processIamPolicy(storageClient *storage.Service, bucket *storage.Bucket, me
301301
302302 if policy != nil && policy .Bindings != nil {
303303 roleUsers := make (map [string ][]string )
304-
304+
305305 for _ , binding := range policy .Bindings {
306306 if binding .Members != nil {
307307 roleUsers [binding .Role ] = append (roleUsers [binding .Role ], binding .Members ... )
@@ -321,17 +321,17 @@ func processIamPolicy(storageClient *storage.Service, bucket *storage.Bucket, me
321321 if roleCount >= 10 {
322322 break
323323 }
324-
324+
325325 // Simplify role name for metadata
326326 shortRole := role
327327 if strings .HasPrefix (role , "roles/" ) {
328328 shortRole = strings .TrimPrefix (role , "roles/" )
329329 }
330-
330+
331331 // Sort members for consistent output
332332 members := roleUsers [role ]
333333 sort .Strings (members )
334-
334+
335335 // Add role and members to metadata
336336 metadata [fmt .Sprintf ("google/storage/iam/%s" , shortRole )] = strings .Join (members , "," )
337337 roleCount ++
@@ -356,17 +356,17 @@ func processStorageDetails(bucket *storage.Bucket, metadata map[string]string) {
356356 // Handle lifecycle rules
357357 if bucket .Lifecycle != nil && bucket .Lifecycle .Rule != nil {
358358 metadata ["storage/lifecycle-rules" ] = strconv .Itoa (len (bucket .Lifecycle .Rule ))
359-
359+
360360 // Extract some details about lifecycle rules
361361 for i , rule := range bucket .Lifecycle .Rule {
362362 if rule .Action != nil && rule .Action .Type != "" {
363363 metadata [fmt .Sprintf ("storage/lifecycle/%d/action" , i )] = rule .Action .Type
364-
364+
365365 if rule .Action .Type == "SetStorageClass" && rule .Action .StorageClass != "" {
366366 metadata [fmt .Sprintf ("storage/lifecycle/%d/storage-class" , i )] = rule .Action .StorageClass
367367 }
368368 }
369-
369+
370370 // Add conditions if present
371371 if rule .Condition != nil {
372372 if rule .Condition .Age != nil && * rule .Condition .Age > 0 {
@@ -395,12 +395,12 @@ func processStorageDetails(bucket *storage.Bucket, metadata map[string]string) {
395395 if bucket .RetentionPolicy != nil {
396396 metadata ["storage/retention-policy" ] = "enabled"
397397 metadata ["storage/retention-period" ] = strconv .FormatInt (bucket .RetentionPolicy .RetentionPeriod , 10 )
398-
398+
399399 retentionDays := bucket .RetentionPolicy .RetentionPeriod / 86400 // Convert seconds to days
400400 if retentionDays > 0 {
401401 metadata ["storage/retention-days" ] = strconv .FormatInt (retentionDays , 10 )
402402 }
403-
403+
404404 if bucket .RetentionPolicy .EffectiveTime != "" {
405405 metadata ["storage/retention-effective-time" ] = bucket .RetentionPolicy .EffectiveTime
406406 }
@@ -421,7 +421,7 @@ func processStorageDetails(bucket *storage.Bucket, metadata map[string]string) {
421421 }
422422 metadata ["google/storage/label-count" ] = strconv .Itoa (len (bucket .Labels ))
423423 }
424-
424+
425425 // Handle autoclass if set
426426 if bucket .Autoclass != nil {
427427 metadata ["storage/autoclass-enabled" ] = strconv .FormatBool (bucket .Autoclass .Enabled )
@@ -481,4 +481,4 @@ func upsertToCtrlplane(ctx context.Context, resources []api.AgentResource, proje
481481
482482 log .Info ("Response from upserting resources" , "status" , upsertResp .Status )
483483 return nil
484- }
484+ }
0 commit comments