gensupport: fix incorrect MIME boundary being used in bodies on retries

And fix the test that was trying to catch this case but was failing
due to its always-returns-zeros rand fake. The corrected test now
fails without the fix and passes with it.

Thanks to Michael Fraenkel for identifying the problem.

Fixes googleapis/google-api-go-client#343
Fixes googleapis/google-cloud-go#1350
Fixes golang/go#30693

Change-Id: If4251facebbbbeb9f1e169845d0d3573e871d741
Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/39076
Reviewed-by: Jean de Klerk <deklerk@google.com>
2 files changed
tree: be282e00903dccc6f4e902f8d26cffcd7ffd2419
  1. abusiveexperiencereport/
  2. acceleratedmobilepageurl/
  3. accesscontextmanager/
  4. adexchangebuyer/
  5. adexchangebuyer2/
  6. adexchangeseller/
  7. adexperiencereport/
  8. admin/
  9. adsense/
  10. adsensehost/
  11. alertcenter/
  12. analytics/
  13. analyticsreporting/
  14. androiddeviceprovisioning/
  15. androidenterprise/
  16. androidmanagement/
  17. androidpublisher/
  18. appengine/
  19. appsactivity/
  20. appstate/
  21. bigquery/
  22. bigquerydatatransfer/
  23. bigtableadmin/
  24. binaryauthorization/
  25. blogger/
  26. books/
  27. calendar/
  28. chat/
  29. civicinfo/
  30. classroom/
  31. cloudasset/
  32. cloudbilling/
  33. cloudbuild/
  34. clouddebugger/
  35. clouderrorreporting/
  36. cloudfunctions/
  37. cloudidentity/
  38. cloudiot/
  39. cloudkms/
  40. cloudprivatecatalog/
  41. cloudprivatecatalogproducer/
  42. cloudprofiler/
  43. cloudresourcemanager/
  44. cloudscheduler/
  45. cloudsearch/
  46. cloudshell/
  47. cloudtasks/
  48. cloudtrace/
  49. composer/
  50. compute/
  51. consumersurveys/
  52. container/
  53. containeranalysis/
  54. content/
  55. customsearch/
  56. dataflow/
  57. dataproc/
  58. datastore/
  59. deploymentmanager/
  60. dfareporting/
  61. dialogflow/
  62. digitalassetlinks/
  63. discovery/
  64. dlp/
  65. dns/
  66. docs/
  67. doubleclickbidmanager/
  68. doubleclicksearch/
  69. drive/
  70. driveactivity/
  71. examples/
  72. file/
  73. firebasedynamiclinks/
  74. firebasehosting/
  75. firebaseremoteconfig/
  76. firebaserules/
  77. firestore/
  78. fitness/
  79. fusiontables/
  80. games/
  81. gamesconfiguration/
  82. gamesmanagement/
  83. genomics/
  84. gensupport/
  85. gmail/
  86. google-api-go-generator/
  87. googleapi/
  88. groupsmigration/
  89. groupssettings/
  90. healthcare/
  91. iam/
  92. iamcredentials/
  93. iap/
  94. identitytoolkit/
  95. indexing/
  96. integration-tests/
  97. internal/
  98. iterator/
  99. jobs/
  100. kgsearch/
  101. language/
  102. lib/
  103. libraryagent/
  104. licensing/
  105. logging/
  106. manufacturers/
  107. mirror/
  108. ml/
  109. monitoring/
  110. oauth2/
  111. option/
  112. oslogin/
  113. pagespeedonline/
  114. partners/
  115. people/
  116. photoslibrary/
  117. playcustomapp/
  118. playmoviespartner/
  119. plus/
  120. plusdomains/
  121. poly/
  122. prediction/
  123. proximitybeacon/
  124. pubsub/
  125. qpxexpress/
  126. redis/
  127. remotebuildexecution/
  128. replicapool/
  129. replicapoolupdater/
  130. reseller/
  131. runtimeconfig/
  132. safebrowsing/
  133. script/
  134. searchconsole/
  135. servicebroker/
  136. serviceconsumermanagement/
  137. servicecontrol/
  138. servicemanagement/
  139. servicenetworking/
  140. serviceusage/
  141. serviceuser/
  142. sheets/
  143. siteverification/
  144. slides/
  145. sourcerepo/
  146. spanner/
  147. spectrum/
  148. speech/
  149. sqladmin/
  150. storage/
  151. storagetransfer/
  152. streetviewpublish/
  153. support/
  154. surveys/
  155. tagmanager/
  156. tasks/
  157. testing/
  158. texttospeech/
  159. toolresults/
  160. tpu/
  161. tracing/
  162. translate/
  163. transport/
  164. urlshortener/
  165. vault/
  166. videointelligence/
  167. vision/
  168. webfonts/
  169. webmasters/
  170. websecurityscanner/
  171. youtube/
  172. youtubeanalytics/
  173. youtubereporting/
  174. .gitignore
  175. .hgtags
  176. api-list.json
  177. AUTHORS
  178. CONTRIBUTING.md
  179. CONTRIBUTORS
  180. doc.go
  181. GettingStarted.md
  182. go.mod
  183. go.sum
  184. key.json.enc
  185. LICENSE
  186. NOTES
  187. README.md
  188. TODO
  189. tools.go
README.md

Google APIs Client Library for Go

Getting Started

$ go get google.golang.org/api/tasks/v1
$ go get google.golang.org/api/moderator/v1
$ go get google.golang.org/api/urlshortener/v1
... etc ...

and using:

package main

import (
	"net/http"

	"google.golang.org/api/urlshortener/v1"
)

func main() {
	svc, err := urlshortener.New(http.DefaultClient)
	// ...
}

Status

GoDoc

These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available “new style” Google APIs.

Due to the auto-generated nature of this collection of libraries, complete APIs or specific versions can appear or go away without notice. As a result, you should always locally vendor any API(s) that your code relies upon.

These client libraries are officially supported by Google. However, the libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.

If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub, consider using the Cloud Client Libraries for Go instead. These are the new and idiomatic Go libraries targeted specifically at Google Cloud Platform Services.

The generator itself and the code it produces are beta. Some APIs are alpha/beta, and indicated as such in the import path (e.g., “google.golang.org/api/someapi/v1alpha”).

Application Default Credentials Example

Application Default Credentials provide a simplified way to obtain credentials for authenticating with Google APIs.

The Application Default Credentials authenticate as the application itself, which make them great for working with Google Cloud APIs like Storage or Datastore. They are the recommended form of authentication when building applications that run on Google Compute Engine or Google App Engine.

Default credentials are provided by the golang.org/x/oauth2/google package. To use them, add the following import:

import "golang.org/x/oauth2/google"

Some credentials types require you to specify scopes, and service entry points may not inject them. If you encounter this situation you may need to specify scopes as follows:

import (
        "context"
        "golang.org/x/oauth2/google"
        "google.golang.org/api/compute/v1"
)

func main() {
        // Use oauth2.NoContext if there isn't a good context to pass in.
        ctx := context.Background()

        client, err := google.DefaultClient(ctx, compute.ComputeScope)
        if err != nil {
                //...
        }
        computeService, err := compute.New(client)
        if err != nil {
                //...
        }
}

If you need a oauth2.TokenSource, use the DefaultTokenSource function:

ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...)
if err != nil {
        //...
}
client := oauth2.NewClient(ctx, ts)

See also: golang.org/x/oauth2/google package documentation.