Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Extend object retaintion with go library

hi all

anyone using the go library to access Google storage object?

i'm trying to extend a retaintion for an object but i always get a 403 error, but the same request made with gcloud command and with the same service account, ends property

 

any idea or a sample, working, code?

3 5 301
5 REPLIES 5

Hi @GandalfGrey,

Welcome to Google Cloud Community!

Extending Object Retention with Go and Troubleshooting 403 Errors:
  • Double-check authentication: Ensure your service account has proper permissions and credentials.
  • Verify scopes: Include necessary scopes like https://www.googleapis.com/auth/devstorage.full_control when creating the client.
  • Use a working code example: I provided a sample Go code for updating object retention.
  • Troubleshoot further: Check IAM permissions, error messages, API logging, and consider versioning and bucket-level policies.


@christianpaula wrote:

Use a working code example: I provided a sample Go code for updating object retention.


where is the sample code?

everything else was already checked, also, the same service account used with gcloud command works as expected

 

@christianpaula any update ? Were i can find the example code to extend retention with the go library ?

This is a log when trying to extend the retention on an existing object. I'm not 100% sure that the body is correct, as it's only referring to the bucket, not to the object (but the object is referenced in the url)

2024/01/10 17:42:14 http2: Transport encoding header ":authority" = "storage.googleapis.com"
2024/01/10 17:42:14 http2: Transport encoding header ":method" = "PATCH"
2024/01/10 17:42:14 http2: Transport encoding header ":path" = "/storage/v1/b/mybucket/o/kopia.blobcfg?alt=json&prettyPrint=false&projection=full"
2024/01/10 17:42:14 http2: Transport encoding header ":scheme" = "https"
2024/01/10 17:42:14 http2: Transport encoding header "x-goog-api-client" = "gl-go/1.21.1 gdcl/0.155.0"
2024/01/10 17:42:14 http2: Transport encoding header "x-goog-api-client" = "gccl-invocation-id/25bc132a-fb96-446e-944a-a5d9da459f9a gccl-attempt-count/1 gl-go/1.21.1 gccl/1.36.0"
2024/01/10 17:42:14 http2: Transport encoding header "user-agent" = "google-api-go-client/0.5"
2024/01/10 17:42:14 http2: Transport encoding header "content-type" = "application/json"
2024/01/10 17:42:14 http2: Transport encoding header "x-goog-gcs-idempotency-token" = "25bc132a-fb96-446e-944a-a5d9da459f9a"
2024/01/10 17:42:14 http2: Transport encoding header "authorization" = "Bearer xxxx"
2024/01/10 17:42:14 http2: Transport encoding header "content-length" = "104"
2024/01/10 17:42:14 http2: Transport encoding header "accept-encoding" = "gzip"
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: wrote HEADERS flags=END_HEADERS stream=99 len=131
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: wrote DATA flags=END_STREAM stream=99 len=104 data="{\"bucket\":\"mybucket\",\"retention\":{\"mode\":\"Unlocked\",\"retainUntilTime\":\"2024-07-08T16:42:14Z\"}}\n"
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read HEADERS flags=END_HEADERS stream=97 len=101
2024/01/10 17:42:14 http2: decoded hpack field header field ":status" = "403"
2024/01/10 17:42:14 http2: decoded hpack field header field "x-guploader-uploadid" = "ABPtcPpQgTfdWl-yxk5yun6aSPY1c8BRstV9BBeGOdomHoTvpm_kmyDikeaZSOyv24LNqPdVh7I"
2024/01/10 17:42:14 http2: decoded hpack field header field "content-type" = "application/json; charset=UTF-8"
2024/01/10 17:42:14 http2: decoded hpack field header field "date" = "Wed, 10 Jan 2024 16:42:14 GMT"
2024/01/10 17:42:14 http2: decoded hpack field header field "vary" = "Origin"
2024/01/10 17:42:14 http2: decoded hpack field header field "vary" = "X-Origin"
2024/01/10 17:42:14 http2: decoded hpack field header field "cache-control" = "no-cache, no-store, max-age=0, must-revalidate"
2024/01/10 17:42:14 http2: decoded hpack field header field "expires" = "Mon, 01 Jan 1990 00:00:00 GMT"
2024/01/10 17:42:14 http2: decoded hpack field header field "pragma" = "no-cache"
2024/01/10 17:42:14 http2: decoded hpack field header field "content-length" = "128"
2024/01/10 17:42:14 http2: decoded hpack field header field "server" = "UploadServer"
2024/01/10 17:42:14 http2: Transport received HEADERS flags=END_HEADERS stream=97 len=101
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read DATA stream=97 len=128 data="{\"error\":{\"code\":403,\"message\":\"Access denied.\",\"errors\":[{\"message\":\"Access denied.\",\"domain\":\"global\",\"reason\":\"forbidden\"}]}}"
2024/01/10 17:42:14 http2: Transport received DATA stream=97 len=128 data="{\"error\":{\"code\":403,\"message\":\"Access denied.\",\"errors\":[{\"message\":\"Access denied.\",\"domain\":\"global\",\"reason\":\"forbidden\"}]}}"
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read DATA flags=END_STREAM stream=97 len=0 data=""
2024/01/10 17:42:14 http2: Transport received DATA flags=END_STREAM stream=97 len=0 data=""
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read PING len=8 ping="\x00\x00\x00\x00\x00\x00\x04 "
2024/01/10 17:42:14 http2: Transport received PING len=8 ping="\x00\x00\x00\x00\x00\x00\x04 "
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: wrote PING flags=ACK len=8 ping="\x00\x00\x00\x00\x00\x00\x04 "

This is the call that i made:

2024/01/10 17:42:14 http2: Transport encoding header ":authority" = "storage.googleapis.com"
2024/01/10 17:42:14 http2: Transport encoding header ":method" = "PATCH"
2024/01/10 17:42:14 http2: Transport encoding header ":path" = "/storage/v1/b/mybucket/o/kopia.blobcfg?alt=json&prettyPrint=false&projection=full"
2024/01/10 17:42:14 http2: Transport encoding header ":scheme" = "https"
2024/01/10 17:42:14 http2: Transport encoding header "x-goog-api-client" = "gl-go/1.21.1 gdcl/0.155.0"
2024/01/10 17:42:14 http2: Transport encoding header "x-goog-api-client" = "gccl-invocation-id/25bc132a-fb96-446e-944a-a5d9da459f9a gccl-attempt-count/1 gl-go/1.21.1 gccl/1.36.0"
2024/01/10 17:42:14 http2: Transport encoding header "user-agent" = "google-api-go-client/0.5"
2024/01/10 17:42:14 http2: Transport encoding header "content-type" = "application/json"
2024/01/10 17:42:14 http2: Transport encoding header "x-goog-gcs-idempotency-token" = "25bc132a-fb96-446e-944a-a5d9da459f9a"
2024/01/10 17:42:14 http2: Transport encoding header "authorization" = "Bearer xxxx"
2024/01/10 17:42:14 http2: Transport encoding header "content-length" = "104"
2024/01/10 17:42:14 http2: Transport encoding header "accept-encoding" = "gzip"
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: wrote HEADERS flags=END_HEADERS stream=99 len=131
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: wrote DATA flags=END_STREAM stream=99 len=104 data="{\"bucket\":\"mybucket\",\"retention\":{\"mode\":\"Unlocked\",\"retainUntilTime\":\"2024-07-08T16:42:14Z\"}}\n"
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read HEADERS flags=END_HEADERS stream=97 len=101
2024/01/10 17:42:14 http2: decoded hpack field header field ":status" = "403"
2024/01/10 17:42:14 http2: decoded hpack field header field "x-guploader-uploadid" = "ABPtcPpQgTfdWl-yxk5yun6aSPY1c8BRstV9BBeGOdomHoTvpm_kmyDikeaZSOyv24LNqPdVh7I"
2024/01/10 17:42:14 http2: decoded hpack field header field "content-type" = "application/json; charset=UTF-8"
2024/01/10 17:42:14 http2: decoded hpack field header field "date" = "Wed, 10 Jan 2024 16:42:14 GMT"
2024/01/10 17:42:14 http2: decoded hpack field header field "vary" = "Origin"
2024/01/10 17:42:14 http2: decoded hpack field header field "vary" = "X-Origin"
2024/01/10 17:42:14 http2: decoded hpack field header field "cache-control" = "no-cache, no-store, max-age=0, must-revalidate"
2024/01/10 17:42:14 http2: decoded hpack field header field "expires" = "Mon, 01 Jan 1990 00:00:00 GMT"
2024/01/10 17:42:14 http2: decoded hpack field header field "pragma" = "no-cache"
2024/01/10 17:42:14 http2: decoded hpack field header field "content-length" = "128"
2024/01/10 17:42:14 http2: decoded hpack field header field "server" = "UploadServer"
2024/01/10 17:42:14 http2: Transport received HEADERS flags=END_HEADERS stream=97 len=101
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read DATA stream=97 len=128 data="{\"error\":{\"code\":403,\"message\":\"Access denied.\",\"errors\":[{\"message\":\"Access denied.\",\"domain\":\"global\",\"reason\":\"forbidden\"}]}}"
2024/01/10 17:42:14 http2: Transport received DATA stream=97 len=128 data="{\"error\":{\"code\":403,\"message\":\"Access denied.\",\"errors\":[{\"message\":\"Access denied.\",\"domain\":\"global\",\"reason\":\"forbidden\"}]}}"
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read DATA flags=END_STREAM stream=97 len=0 data=""
2024/01/10 17:42:14 http2: Transport received DATA flags=END_STREAM stream=97 len=0 data=""
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: read PING len=8 ping="\x00\x00\x00\x00\x00\x00\x04 "
2024/01/10 17:42:14 http2: Transport received PING len=8 ping="\x00\x00\x00\x00\x00\x00\x04 "
2024/01/10 17:42:14 http2: Framer 0xc0006d60e0: wrote PING flags=ACK len=8 ping="\x00\x00\x00\x00\x00\x00\x04 "