Skip to content

Migrate data_source_google_compute_images.go data source to use direct HTTP rather than a client library - #18669

Open
GitOleksandrBokov wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
GitOleksandrBokov:data_source_google_compute_images-migration-resubmit
Open

Migrate data_source_google_compute_images.go data source to use direct HTTP rather than a client library#18669
GitOleksandrBokov wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
GitOleksandrBokov:data_source_google_compute_images-migration-resubmit

Conversation

@GitOleksandrBokov

Copy link
Copy Markdown
Contributor

Resubmit of #18466, which was reverted in #18643 because of a CodeQL "incorrect conversion between integer types" alert. Only the id parsing differs from the reverted version; the rest is unchanged from the branch that was approved by @WentaoNi and @c2thorn.

Part of the ongoing migration of handwritten compute files from the Apiary client library to direct HTTP calls (transport_tpg.SendRequest). Same pattern as #18444 and the merged data source migrations #17090 / #17117.

  • Replaces NewClient(...).Images.List(project).Filter(filter).Do() with GET projects/{project}/global/images via transport_tpg.SendRequest + transport_tpg.AddQueryParams.
  • Adds pageToken pagination. The previous code issued a single Do() call, which returns only the first page (server default 500 items) and silently truncated larger projects.
  • The filter query parameter is sent unconditionally (even when empty) to keep the request shape identical to the typed client, so the recorded VCR cassette stays replay-compatible. pageToken is only sent when non-empty for the same reason.
  • What changed since the revert. The REST API serializes int64/uint64 fields as JSON strings; archiveSizeBytes, diskSizeGb and id are now all parsed with tpgresource.StringToFixed64, which returns an int64 directly, so the file contains no integer conversion at all and no longer imports strconv. The reverted version parsed id with strconv.ParseUint(v, 10, 64) and cast the result to int64; go/incorrect-integer-conversion flags that because a 64-bit unsigned value does not fit in int64. image_id is a schema.TypeInt, so such a value could never be stored anyway - the cast silently produced a negative number, and the parse now returns an explicit error instead. tpgresource.StringToFixed64 is also the helper MMv1 generates for type: Integer properties in this format.
  • No schema, test, or documentation changes.

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

compute: migrated `google_compute_images` data source to use direct HTTP rather than a client library
compute: fixed truncation of results at 500 images in `google_compute_images` data source

Resubmit of GoogleCloudPlatform#18466, reverted in GoogleCloudPlatform#18643. The uint64 image id is parsed
with tpgresource.StringToFixed64 instead of strconv.ParseUint plus an
int64 cast, so there is no narrowing conversion left for CodeQL to flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant