Hedronite · Go Lesson · Polyglot-Dev / Go · Sun 2026-09-13

Go Cloud Storage BucketAttrs lifecycle and retention inventory — Attrs walk

Same three shelves. cloud.google.com/go/storage.

Lesson Class: DevOps-Go (GCS BucketAttrs)
Cloud Referent: GCS lifecycle + retention + versioning via Go
Paired Ops: Python GCS lifecycle census
Paired Dev: Python google-cloud-storage inventory
Paired Cert: GCP PCA Cloud Storage
Grounding: Bootcamp Ch.3 · PCA-Notes
List
Buckets iterator.
Attrs
Class, lifecycle, retention.
Bound
No Bucket.Update.
Inventory reads. Update is another binary.

Same three shelves. cloud.google.com/go/storage.

§I — Frame

Mirror the Python inventory with Go. List buckets, call Bucket.Attrs, print storage class, lifecycle rules, retention, versioning. Do not update bucket attrs from this tool.

§II — Sketch

ctx := context.Background()
client, err := storage.NewClient(ctx)
if err != nil {
    return err
}
defer client.Close()

it := client.Buckets(ctx, projectID)
for {
    battrs, err := it.Next()
    if err == iterator.Done {
        break
    }
    if err != nil {
        return err
    }
    // battrs.StorageClass
    // battrs.VersioningEnabled
    // battrs.RetentionPolicy (RetentionPeriod, IsLocked, EffectiveTime)
    // battrs.Lifecycle.Rules — Action.Type, Action.StorageClass, Condition.AgeInDays
}

Use iterator.Done correctly. Treat permission errors per bucket as WARN rows when the caller asks for best-effort fleet scans.

§III — Boundaries

  1. No Bucket.Update for lifecycle or retention from the inventory binary.
  2. Project ID is required context; empty iteration is not org-wide truth.
  3. Align WARN strings with Ops/Dev so Maghrib can fold Go items into the Dev quiz (no Go quiz.html).

§IV — Closing

Print class, rules, retention lock, versioning. Leave patching to a different program with a different review.

Related