Debian Codegraph @

gsuiteaddons/apiv1/g_suite_add_ons_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package gsuiteaddons
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 gsuiteaddonspb "cloud.google.com/go/gsuiteaddons/apiv1/gsuiteaddonspb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/iterator"
32 "google.golang.org/api/option"
33 "google.golang.org/api/option/internaloption"
34 gtransport "google.golang.org/api/transport/grpc"
35 httptransport "google.golang.org/api/transport/http"
36 "google.golang.org/grpc"
37 "google.golang.org/grpc/codes"
38 "google.golang.org/protobuf/encoding/protojson"
39 "google.golang.org/protobuf/proto"
40 )
41
42 var newClientHook clientHook
43
44 // CallOptions contains the retry settings for each method of Client.
45 type CallOptions struct {
46 GetAuthorization []gax.CallOption
47 CreateDeployment []gax.CallOption
48 ReplaceDeployment []gax.CallOption
49 GetDeployment []gax.CallOption
50 ListDeployments []gax.CallOption
51 DeleteDeployment []gax.CallOption
52 InstallDeployment []gax.CallOption
53 UninstallDeployment []gax.CallOption
54 GetInstallStatus []gax.CallOption
55 }
56
57 func defaultGRPCClientOptions() []option.ClientOption {
58 return []option.ClientOption{
59 internaloption.WithDefaultEndpoint("gsuiteaddons.googleapis.com:443"),
60 internaloption.WithDefaultEndpointTemplate("gsuiteaddons.UNIVERSE_DOMAIN:443"),
61 internaloption.WithDefaultMTLSEndpoint("gsuiteaddons.mtls.googleapis.com:443"),
62 internaloption.WithDefaultUniverseDomain("googleapis.com"),
63 internaloption.WithDefaultAudience("https://gsuiteaddons.googleapis.com/"),
64 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
65 internaloption.EnableJwtWithScope(),
66 internaloption.EnableNewAuthLibrary(),
67 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
68 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
69 }
70 }
71
72 func defaultCallOptions() *CallOptions {
73 return &CallOptions{
74 GetAuthorization: []gax.CallOption{
75 gax.WithTimeout(120000 * time.Millisecond),
76 },
77 CreateDeployment: []gax.CallOption{
78 gax.WithTimeout(10000 * time.Millisecond),
79 },
80 ReplaceDeployment: []gax.CallOption{
81 gax.WithTimeout(10000 * time.Millisecond),
82 gax.WithRetry(func() gax.Retryer {
83 return gax.OnCodes([]codes.Code{
84 codes.Unavailable,
85 codes.Unknown,
86 }, gax.Backoff{
87 Initial: 1000 * time.Millisecond,
88 Max: 10000 * time.Millisecond,
89 Multiplier: 1.30,
90 })
91 }),
92 },
93 GetDeployment: []gax.CallOption{
94 gax.WithTimeout(10000 * time.Millisecond),
95 gax.WithRetry(func() gax.Retryer {
96 return gax.OnCodes([]codes.Code{
97 codes.Unavailable,
98 codes.Unknown,
99 }, gax.Backoff{
100 Initial: 1000 * time.Millisecond,
101 Max: 10000 * time.Millisecond,
102 Multiplier: 1.30,
103 })
104 }),
105 },
106 ListDeployments: []gax.CallOption{
107 gax.WithTimeout(10000 * time.Millisecond),
108 gax.WithRetry(func() gax.Retryer {
109 return gax.OnCodes([]codes.Code{
110 codes.Unavailable,
111 codes.Unknown,
112 }, gax.Backoff{
113 Initial: 1000 * time.Millisecond,
114 Max: 10000 * time.Millisecond,
115 Multiplier: 1.30,
116 })
117 }),
118 },
119 DeleteDeployment: []gax.CallOption{
120 gax.WithTimeout(10000 * time.Millisecond),
121 },
122 InstallDeployment: []gax.CallOption{
123 gax.WithTimeout(10000 * time.Millisecond),
124 gax.WithRetry(func() gax.Retryer {
125 return gax.OnCodes([]codes.Code{
126 codes.Unavailable,
127 codes.Unknown,
128 }, gax.Backoff{
129 Initial: 1000 * time.Millisecond,
130 Max: 10000 * time.Millisecond,
131 Multiplier: 1.30,
132 })
133 }),
134 },
135 UninstallDeployment: []gax.CallOption{
136 gax.WithTimeout(10000 * time.Millisecond),
137 gax.WithRetry(func() gax.Retryer {
138 return gax.OnCodes([]codes.Code{
139 codes.Unavailable,
140 codes.Unknown,
141 }, gax.Backoff{
142 Initial: 1000 * time.Millisecond,
143 Max: 10000 * time.Millisecond,
144 Multiplier: 1.30,
145 })
146 }),
147 },
148 GetInstallStatus: []gax.CallOption{
149 gax.WithTimeout(10000 * time.Millisecond),
150 gax.WithRetry(func() gax.Retryer {
151 return gax.OnCodes([]codes.Code{
152 codes.Unavailable,
153 codes.Unknown,
154 }, gax.Backoff{
155 Initial: 1000 * time.Millisecond,
156 Max: 10000 * time.Millisecond,
157 Multiplier: 1.30,
158 })
159 }),
160 },
161 }
162 }
163
164 func defaultRESTCallOptions() *CallOptions {
165 return &CallOptions{
166 GetAuthorization: []gax.CallOption{
167 gax.WithTimeout(120000 * time.Millisecond),
168 },
169 CreateDeployment: []gax.CallOption{
170 gax.WithTimeout(10000 * time.Millisecond),
171 },
172 ReplaceDeployment: []gax.CallOption{
173 gax.WithTimeout(10000 * time.Millisecond),
174 gax.WithRetry(func() gax.Retryer {
175 return gax.OnHTTPCodes(gax.Backoff{
176 Initial: 1000 * time.Millisecond,
177 Max: 10000 * time.Millisecond,
178 Multiplier: 1.30,
179 },
180 http.StatusServiceUnavailable,
181 http.StatusInternalServerError)
182 }),
183 },
184 GetDeployment: []gax.CallOption{
185 gax.WithTimeout(10000 * time.Millisecond),
186 gax.WithRetry(func() gax.Retryer {
187 return gax.OnHTTPCodes(gax.Backoff{
188 Initial: 1000 * time.Millisecond,
189 Max: 10000 * time.Millisecond,
190 Multiplier: 1.30,
191 },
192 http.StatusServiceUnavailable,
193 http.StatusInternalServerError)
194 }),
195 },
196 ListDeployments: []gax.CallOption{
197 gax.WithTimeout(10000 * time.Millisecond),
198 gax.WithRetry(func() gax.Retryer {
199 return gax.OnHTTPCodes(gax.Backoff{
200 Initial: 1000 * time.Millisecond,
201 Max: 10000 * time.Millisecond,
202 Multiplier: 1.30,
203 },
204 http.StatusServiceUnavailable,
205 http.StatusInternalServerError)
206 }),
207 },
208 DeleteDeployment: []gax.CallOption{
209 gax.WithTimeout(10000 * time.Millisecond),
210 },
211 InstallDeployment: []gax.CallOption{
212 gax.WithTimeout(10000 * time.Millisecond),
213 gax.WithRetry(func() gax.Retryer {
214 return gax.OnHTTPCodes(gax.Backoff{
215 Initial: 1000 * time.Millisecond,
216 Max: 10000 * time.Millisecond,
217 Multiplier: 1.30,
218 },
219 http.StatusServiceUnavailable,
220 http.StatusInternalServerError)
221 }),
222 },
223 UninstallDeployment: []gax.CallOption{
224 gax.WithTimeout(10000 * time.Millisecond),
225 gax.WithRetry(func() gax.Retryer {
226 return gax.OnHTTPCodes(gax.Backoff{
227 Initial: 1000 * time.Millisecond,
228 Max: 10000 * time.Millisecond,
229 Multiplier: 1.30,
230 },
231 http.StatusServiceUnavailable,
232 http.StatusInternalServerError)
233 }),
234 },
235 GetInstallStatus: []gax.CallOption{
236 gax.WithTimeout(10000 * time.Millisecond),
237 gax.WithRetry(func() gax.Retryer {
238 return gax.OnHTTPCodes(gax.Backoff{
239 Initial: 1000 * time.Millisecond,
240 Max: 10000 * time.Millisecond,
241 Multiplier: 1.30,
242 },
243 http.StatusServiceUnavailable,
244 http.StatusInternalServerError)
245 }),
246 },
247 }
248 }
249
250 // internalClient is an interface that defines the methods available from Google Workspace add-ons API.
251 type internalClient interface {
252 Close() error
253 setGoogleClientInfo(...string)
254 Connection() *grpc.ClientConn
255 GetAuthorization(context.Context, *gsuiteaddonspb.GetAuthorizationRequest, ...gax.CallOption) (*gsuiteaddonspb.Authorization, error)
256 CreateDeployment(context.Context, *gsuiteaddonspb.CreateDeploymentRequest, ...gax.CallOption) (*gsuiteaddonspb.Deployment, error)
257 ReplaceDeployment(context.Context, *gsuiteaddonspb.ReplaceDeploymentRequest, ...gax.CallOption) (*gsuiteaddonspb.Deployment, error)
258 GetDeployment(context.Context, *gsuiteaddonspb.GetDeploymentRequest, ...gax.CallOption) (*gsuiteaddonspb.Deployment, error)
259 ListDeployments(context.Context, *gsuiteaddonspb.ListDeploymentsRequest, ...gax.CallOption) *DeploymentIterator
260 DeleteDeployment(context.Context, *gsuiteaddonspb.DeleteDeploymentRequest, ...gax.CallOption) error
261 InstallDeployment(context.Context, *gsuiteaddonspb.InstallDeploymentRequest, ...gax.CallOption) error
262 UninstallDeployment(context.Context, *gsuiteaddonspb.UninstallDeploymentRequest, ...gax.CallOption) error
263 GetInstallStatus(context.Context, *gsuiteaddonspb.GetInstallStatusRequest, ...gax.CallOption) (*gsuiteaddonspb.InstallStatus, error)
264 }
265
266 // Client is a client for interacting with Google Workspace add-ons API.
267 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
268 //
269 // A service for managing Google Workspace add-ons deployments.
270 //
271 // A Google Workspace add-on is a third-party embedded component that can be
272 // installed in Google Workspace Applications like Gmail, Calendar, Drive, and
273 // the Google Docs, Sheets, and Slides editors. Google Workspace add-ons can
274 // display UI cards, receive contextual information from the host application,
275 // and perform actions in the host application (See:
276 // https://developers.google.com/gsuite/add-ons/overview (at https://developers.google.com/gsuite/add-ons/overview) for more information).
277 //
278 // A Google Workspace add-on deployment resource specifies metadata about the
279 // add-on, including a specification of the entry points in the host application
280 // that trigger add-on executions (see:
281 // https://developers.google.com/gsuite/add-ons/concepts/gsuite-manifests (at https://developers.google.com/gsuite/add-ons/concepts/gsuite-manifests)).
282 // Add-on deployments defined via the Google Workspace add-ons API define their
283 // entrypoints using HTTPS URLs (See:
284 // https://developers.google.com/gsuite/add-ons/guides/alternate-runtimes (at https://developers.google.com/gsuite/add-ons/guides/alternate-runtimes)),
285 //
286 // A Google Workspace add-on deployment can be installed in developer mode,
287 // which allows an add-on developer to test the experience an end-user would see
288 // when installing and running the add-on in their G Suite applications. When
289 // running in developer mode, more detailed error messages are exposed in the
290 // add-on UI to aid in debugging.
291 //
292 // A Google Workspace add-on deployment can be published to Google Workspace
293 // Marketplace, which allows other Google Workspace users to discover and
294 // install the add-on. See:
295 // https://developers.google.com/gsuite/add-ons/how-tos/publish-add-on-overview (at https://developers.google.com/gsuite/add-ons/how-tos/publish-add-on-overview)
296 // for details.
297 type Client struct {
298 // The internal transport-dependent client.
299 internalClient internalClient
300
301 // The call options for this service.
302 CallOptions *CallOptions
303 }
304
305 // Wrapper methods routed to the internal client.
306
307 // Close closes the connection to the API service. The user should invoke this when
308 // the client is no longer required.
309 func (c *Client) Close() error {
310 return c.internalClient.Close()
311 }
312
313 // setGoogleClientInfo sets the name and version of the application in
314 // the `x-goog-api-client` header passed on each request. Intended for
315 // use by Google-written clients.
316 func (c *Client) setGoogleClientInfo(keyval ...string) {
317 c.internalClient.setGoogleClientInfo(keyval...)
318 }
319
320 // Connection returns a connection to the API service.
321 //
322 // Deprecated: Connections are now pooled so this method does not always
323 // return the same resource.
324 func (c *Client) Connection() *grpc.ClientConn {
325 return c.internalClient.Connection()
326 }
327
328 // GetAuthorization gets the authorization information for deployments in a given project.
329 func (c *Client) GetAuthorization(ctx context.Context, req *gsuiteaddonspb.GetAuthorizationRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Authorization, error) {
330 return c.internalClient.GetAuthorization(ctx, req, opts...)
331 }
332
333 // CreateDeployment creates a deployment with the specified name and configuration.
334 func (c *Client) CreateDeployment(ctx context.Context, req *gsuiteaddonspb.CreateDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
335 return c.internalClient.CreateDeployment(ctx, req, opts...)
336 }
337
338 // ReplaceDeployment creates or replaces a deployment with the specified name.
339 func (c *Client) ReplaceDeployment(ctx context.Context, req *gsuiteaddonspb.ReplaceDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
340 return c.internalClient.ReplaceDeployment(ctx, req, opts...)
341 }
342
343 // GetDeployment gets the deployment with the specified name.
344 func (c *Client) GetDeployment(ctx context.Context, req *gsuiteaddonspb.GetDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
345 return c.internalClient.GetDeployment(ctx, req, opts...)
346 }
347
348 // ListDeployments lists all deployments in a particular project.
349 func (c *Client) ListDeployments(ctx context.Context, req *gsuiteaddonspb.ListDeploymentsRequest, opts ...gax.CallOption) *DeploymentIterator {
350 return c.internalClient.ListDeployments(ctx, req, opts...)
351 }
352
353 // DeleteDeployment deletes the deployment with the given name.
354 func (c *Client) DeleteDeployment(ctx context.Context, req *gsuiteaddonspb.DeleteDeploymentRequest, opts ...gax.CallOption) error {
355 return c.internalClient.DeleteDeployment(ctx, req, opts...)
356 }
357
358 // InstallDeployment installs a deployment in developer mode.
359 // See:
360 // https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons (at https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons).
361 func (c *Client) InstallDeployment(ctx context.Context, req *gsuiteaddonspb.InstallDeploymentRequest, opts ...gax.CallOption) error {
362 return c.internalClient.InstallDeployment(ctx, req, opts...)
363 }
364
365 // UninstallDeployment uninstalls a developer mode deployment.
366 // See:
367 // https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons (at https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons).
368 func (c *Client) UninstallDeployment(ctx context.Context, req *gsuiteaddonspb.UninstallDeploymentRequest, opts ...gax.CallOption) error {
369 return c.internalClient.UninstallDeployment(ctx, req, opts...)
370 }
371
372 // GetInstallStatus fetches the install status of a developer mode deployment.
373 func (c *Client) GetInstallStatus(ctx context.Context, req *gsuiteaddonspb.GetInstallStatusRequest, opts ...gax.CallOption) (*gsuiteaddonspb.InstallStatus, error) {
374 return c.internalClient.GetInstallStatus(ctx, req, opts...)
375 }
376
377 // gRPCClient is a client for interacting with Google Workspace add-ons API over gRPC transport.
378 //
379 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
380 type gRPCClient struct {
381 // Connection pool of gRPC connections to the service.
382 connPool gtransport.ConnPool
383
384 // Points back to the CallOptions field of the containing Client
385 CallOptions **CallOptions
386
387 // The gRPC API client.
388 client gsuiteaddonspb.GSuiteAddOnsClient
389
390 // The x-goog-* metadata to be sent with each request.
391 xGoogHeaders []string
392
393 logger *slog.Logger
394 }
395
396 // NewClient creates a new g suite add ons client based on gRPC.
397 // The returned client must be Closed when it is done being used to clean up its underlying connections.
398 //
399 // A service for managing Google Workspace add-ons deployments.
400 //
401 // A Google Workspace add-on is a third-party embedded component that can be
402 // installed in Google Workspace Applications like Gmail, Calendar, Drive, and
403 // the Google Docs, Sheets, and Slides editors. Google Workspace add-ons can
404 // display UI cards, receive contextual information from the host application,
405 // and perform actions in the host application (See:
406 // https://developers.google.com/gsuite/add-ons/overview (at https://developers.google.com/gsuite/add-ons/overview) for more information).
407 //
408 // A Google Workspace add-on deployment resource specifies metadata about the
409 // add-on, including a specification of the entry points in the host application
410 // that trigger add-on executions (see:
411 // https://developers.google.com/gsuite/add-ons/concepts/gsuite-manifests (at https://developers.google.com/gsuite/add-ons/concepts/gsuite-manifests)).
412 // Add-on deployments defined via the Google Workspace add-ons API define their
413 // entrypoints using HTTPS URLs (See:
414 // https://developers.google.com/gsuite/add-ons/guides/alternate-runtimes (at https://developers.google.com/gsuite/add-ons/guides/alternate-runtimes)),
415 //
416 // A Google Workspace add-on deployment can be installed in developer mode,
417 // which allows an add-on developer to test the experience an end-user would see
418 // when installing and running the add-on in their G Suite applications. When
419 // running in developer mode, more detailed error messages are exposed in the
420 // add-on UI to aid in debugging.
421 //
422 // A Google Workspace add-on deployment can be published to Google Workspace
423 // Marketplace, which allows other Google Workspace users to discover and
424 // install the add-on. See:
425 // https://developers.google.com/gsuite/add-ons/how-tos/publish-add-on-overview (at https://developers.google.com/gsuite/add-ons/how-tos/publish-add-on-overview)
426 // for details.
427 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
428 clientOpts := defaultGRPCClientOptions()
429 if newClientHook != nil {
430 hookOpts, err := newClientHook(ctx, clientHookParams{})
431 if err != nil {
432 return nil, err
433 }
434 clientOpts = append(clientOpts, hookOpts...)
435 }
436
437 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
438 if err != nil {
439 return nil, err
440 }
441 client := Client{CallOptions: defaultCallOptions()}
442
443 c := &gRPCClient{
444 connPool: connPool,
445 client: gsuiteaddonspb.NewGSuiteAddOnsClient(connPool),
446 CallOptions: &client.CallOptions,
447 logger: internaloption.GetLogger(opts),
448 }
449 c.setGoogleClientInfo()
450
451 client.internalClient = c
452
453 return &client, nil
454 }
455
456 // Connection returns a connection to the API service.
457 //
458 // Deprecated: Connections are now pooled so this method does not always
459 // return the same resource.
460 func (c *gRPCClient) Connection() *grpc.ClientConn {
461 return c.connPool.Conn()
462 }
463
464 // setGoogleClientInfo sets the name and version of the application in
465 // the `x-goog-api-client` header passed on each request. Intended for
466 // use by Google-written clients.
467 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
468 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
469 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
470 c.xGoogHeaders = []string{
471 "x-goog-api-client", gax.XGoogHeader(kv...),
472 }
473 }
474
475 // Close closes the connection to the API service. The user should invoke this when
476 // the client is no longer required.
477 func (c *gRPCClient) Close() error {
478 return c.connPool.Close()
479 }
480
481 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
482 type restClient struct {
483 // The http endpoint to connect to.
484 endpoint string
485
486 // The http client.
487 httpClient *http.Client
488
489 // The x-goog-* headers to be sent with each request.
490 xGoogHeaders []string
491
492 // Points back to the CallOptions field of the containing Client
493 CallOptions **CallOptions
494
495 logger *slog.Logger
496 }
497
498 // NewRESTClient creates a new g suite add ons rest client.
499 //
500 // A service for managing Google Workspace add-ons deployments.
501 //
502 // A Google Workspace add-on is a third-party embedded component that can be
503 // installed in Google Workspace Applications like Gmail, Calendar, Drive, and
504 // the Google Docs, Sheets, and Slides editors. Google Workspace add-ons can
505 // display UI cards, receive contextual information from the host application,
506 // and perform actions in the host application (See:
507 // https://developers.google.com/gsuite/add-ons/overview (at https://developers.google.com/gsuite/add-ons/overview) for more information).
508 //
509 // A Google Workspace add-on deployment resource specifies metadata about the
510 // add-on, including a specification of the entry points in the host application
511 // that trigger add-on executions (see:
512 // https://developers.google.com/gsuite/add-ons/concepts/gsuite-manifests (at https://developers.google.com/gsuite/add-ons/concepts/gsuite-manifests)).
513 // Add-on deployments defined via the Google Workspace add-ons API define their
514 // entrypoints using HTTPS URLs (See:
515 // https://developers.google.com/gsuite/add-ons/guides/alternate-runtimes (at https://developers.google.com/gsuite/add-ons/guides/alternate-runtimes)),
516 //
517 // A Google Workspace add-on deployment can be installed in developer mode,
518 // which allows an add-on developer to test the experience an end-user would see
519 // when installing and running the add-on in their G Suite applications. When
520 // running in developer mode, more detailed error messages are exposed in the
521 // add-on UI to aid in debugging.
522 //
523 // A Google Workspace add-on deployment can be published to Google Workspace
524 // Marketplace, which allows other Google Workspace users to discover and
525 // install the add-on. See:
526 // https://developers.google.com/gsuite/add-ons/how-tos/publish-add-on-overview (at https://developers.google.com/gsuite/add-ons/how-tos/publish-add-on-overview)
527 // for details.
528 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
529 clientOpts := append(defaultRESTClientOptions(), opts...)
530 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
531 if err != nil {
532 return nil, err
533 }
534
535 callOpts := defaultRESTCallOptions()
536 c := &restClient{
537 endpoint: endpoint,
538 httpClient: httpClient,
539 CallOptions: &callOpts,
540 logger: internaloption.GetLogger(opts),
541 }
542 c.setGoogleClientInfo()
543
544 return &Client{internalClient: c, CallOptions: callOpts}, nil
545 }
546
547 func defaultRESTClientOptions() []option.ClientOption {
548 return []option.ClientOption{
549 internaloption.WithDefaultEndpoint("https://gsuiteaddons.googleapis.com"),
550 internaloption.WithDefaultEndpointTemplate("https://gsuiteaddons.UNIVERSE_DOMAIN"),
551 internaloption.WithDefaultMTLSEndpoint("https://gsuiteaddons.mtls.googleapis.com"),
552 internaloption.WithDefaultUniverseDomain("googleapis.com"),
553 internaloption.WithDefaultAudience("https://gsuiteaddons.googleapis.com/"),
554 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
555 internaloption.EnableNewAuthLibrary(),
556 }
557 }
558
559 // setGoogleClientInfo sets the name and version of the application in
560 // the `x-goog-api-client` header passed on each request. Intended for
561 // use by Google-written clients.
562 func (c *restClient) setGoogleClientInfo(keyval ...string) {
563 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
564 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
565 c.xGoogHeaders = []string{
566 "x-goog-api-client", gax.XGoogHeader(kv...),
567 }
568 }
569
570 // Close closes the connection to the API service. The user should invoke this when
571 // the client is no longer required.
572 func (c *restClient) Close() error {
573 // Replace httpClient with nil to force cleanup.
574 c.httpClient = nil
575 return nil
576 }
577
578 // Connection returns a connection to the API service.
579 //
580 // Deprecated: This method always returns nil.
581 func (c *restClient) Connection() *grpc.ClientConn {
582 return nil
583 }
584 func (c *gRPCClient) GetAuthorization(ctx context.Context, req *gsuiteaddonspb.GetAuthorizationRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Authorization, error) {
585 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
586
587 hds = append(c.xGoogHeaders, hds...)
588 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
589 opts = append((*c.CallOptions).GetAuthorization[0:len((*c.CallOptions).GetAuthorization):len((*c.CallOptions).GetAuthorization)], opts...)
590 var resp *gsuiteaddonspb.Authorization
591 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
592 var err error
593 resp, err = executeRPC(ctx, c.client.GetAuthorization, req, settings.GRPC, c.logger, "GetAuthorization")
594 return err
595 }, opts...)
596 if err != nil {
597 return nil, err
598 }
599 return resp, nil
600 }
601
602 func (c *gRPCClient) CreateDeployment(ctx context.Context, req *gsuiteaddonspb.CreateDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
603 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
604
605 hds = append(c.xGoogHeaders, hds...)
606 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
607 opts = append((*c.CallOptions).CreateDeployment[0:len((*c.CallOptions).CreateDeployment):len((*c.CallOptions).CreateDeployment)], opts...)
608 var resp *gsuiteaddonspb.Deployment
609 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
610 var err error
611 resp, err = executeRPC(ctx, c.client.CreateDeployment, req, settings.GRPC, c.logger, "CreateDeployment")
612 return err
613 }, opts...)
614 if err != nil {
615 return nil, err
616 }
617 return resp, nil
618 }
619
620 func (c *gRPCClient) ReplaceDeployment(ctx context.Context, req *gsuiteaddonspb.ReplaceDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
621 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "deployment.name", url.QueryEscape(req.GetDeployment().GetName()))}
622
623 hds = append(c.xGoogHeaders, hds...)
624 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
625 opts = append((*c.CallOptions).ReplaceDeployment[0:len((*c.CallOptions).ReplaceDeployment):len((*c.CallOptions).ReplaceDeployment)], opts...)
626 var resp *gsuiteaddonspb.Deployment
627 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
628 var err error
629 resp, err = executeRPC(ctx, c.client.ReplaceDeployment, req, settings.GRPC, c.logger, "ReplaceDeployment")
630 return err
631 }, opts...)
632 if err != nil {
633 return nil, err
634 }
635 return resp, nil
636 }
637
638 func (c *gRPCClient) GetDeployment(ctx context.Context, req *gsuiteaddonspb.GetDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
639 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
640
641 hds = append(c.xGoogHeaders, hds...)
642 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
643 opts = append((*c.CallOptions).GetDeployment[0:len((*c.CallOptions).GetDeployment):len((*c.CallOptions).GetDeployment)], opts...)
644 var resp *gsuiteaddonspb.Deployment
645 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
646 var err error
647 resp, err = executeRPC(ctx, c.client.GetDeployment, req, settings.GRPC, c.logger, "GetDeployment")
648 return err
649 }, opts...)
650 if err != nil {
651 return nil, err
652 }
653 return resp, nil
654 }
655
656 func (c *gRPCClient) ListDeployments(ctx context.Context, req *gsuiteaddonspb.ListDeploymentsRequest, opts ...gax.CallOption) *DeploymentIterator {
657 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
658
659 hds = append(c.xGoogHeaders, hds...)
660 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
661 opts = append((*c.CallOptions).ListDeployments[0:len((*c.CallOptions).ListDeployments):len((*c.CallOptions).ListDeployments)], opts...)
662 it := &DeploymentIterator{}
663 req = proto.Clone(req).(*gsuiteaddonspb.ListDeploymentsRequest)
664 it.InternalFetch = func(pageSize int, pageToken string) ([]*gsuiteaddonspb.Deployment, string, error) {
665 resp := &gsuiteaddonspb.ListDeploymentsResponse{}
666 if pageToken != "" {
667 req.PageToken = pageToken
668 }
669 if pageSize > math.MaxInt32 {
670 req.PageSize = math.MaxInt32
671 } else if pageSize != 0 {
672 req.PageSize = int32(pageSize)
673 }
674 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
675 var err error
676 resp, err = executeRPC(ctx, c.client.ListDeployments, req, settings.GRPC, c.logger, "ListDeployments")
677 return err
678 }, opts...)
679 if err != nil {
680 return nil, "", err
681 }
682
683 it.Response = resp
684 return resp.GetDeployments(), resp.GetNextPageToken(), nil
685 }
686 fetch := func(pageSize int, pageToken string) (string, error) {
687 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
688 if err != nil {
689 return "", err
690 }
691 it.items = append(it.items, items...)
692 return nextPageToken, nil
693 }
694
695 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
696 it.pageInfo.MaxSize = int(req.GetPageSize())
697 it.pageInfo.Token = req.GetPageToken()
698
699 return it
700 }
701
702 func (c *gRPCClient) DeleteDeployment(ctx context.Context, req *gsuiteaddonspb.DeleteDeploymentRequest, opts ...gax.CallOption) error {
703 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
704
705 hds = append(c.xGoogHeaders, hds...)
706 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
707 opts = append((*c.CallOptions).DeleteDeployment[0:len((*c.CallOptions).DeleteDeployment):len((*c.CallOptions).DeleteDeployment)], opts...)
708 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
709 var err error
710 _, err = executeRPC(ctx, c.client.DeleteDeployment, req, settings.GRPC, c.logger, "DeleteDeployment")
711 return err
712 }, opts...)
713 return err
714 }
715
716 func (c *gRPCClient) InstallDeployment(ctx context.Context, req *gsuiteaddonspb.InstallDeploymentRequest, opts ...gax.CallOption) error {
717 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
718
719 hds = append(c.xGoogHeaders, hds...)
720 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
721 opts = append((*c.CallOptions).InstallDeployment[0:len((*c.CallOptions).InstallDeployment):len((*c.CallOptions).InstallDeployment)], opts...)
722 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
723 var err error
724 _, err = executeRPC(ctx, c.client.InstallDeployment, req, settings.GRPC, c.logger, "InstallDeployment")
725 return err
726 }, opts...)
727 return err
728 }
729
730 func (c *gRPCClient) UninstallDeployment(ctx context.Context, req *gsuiteaddonspb.UninstallDeploymentRequest, opts ...gax.CallOption) error {
731 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
732
733 hds = append(c.xGoogHeaders, hds...)
734 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
735 opts = append((*c.CallOptions).UninstallDeployment[0:len((*c.CallOptions).UninstallDeployment):len((*c.CallOptions).UninstallDeployment)], opts...)
736 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
737 var err error
738 _, err = executeRPC(ctx, c.client.UninstallDeployment, req, settings.GRPC, c.logger, "UninstallDeployment")
739 return err
740 }, opts...)
741 return err
742 }
743
744 func (c *gRPCClient) GetInstallStatus(ctx context.Context, req *gsuiteaddonspb.GetInstallStatusRequest, opts ...gax.CallOption) (*gsuiteaddonspb.InstallStatus, error) {
745 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
746
747 hds = append(c.xGoogHeaders, hds...)
748 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
749 opts = append((*c.CallOptions).GetInstallStatus[0:len((*c.CallOptions).GetInstallStatus):len((*c.CallOptions).GetInstallStatus)], opts...)
750 var resp *gsuiteaddonspb.InstallStatus
751 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
752 var err error
753 resp, err = executeRPC(ctx, c.client.GetInstallStatus, req, settings.GRPC, c.logger, "GetInstallStatus")
754 return err
755 }, opts...)
756 if err != nil {
757 return nil, err
758 }
759 return resp, nil
760 }
761
762 // GetAuthorization gets the authorization information for deployments in a given project.
763 func (c *restClient) GetAuthorization(ctx context.Context, req *gsuiteaddonspb.GetAuthorizationRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Authorization, error) {
764 baseUrl, err := url.Parse(c.endpoint)
765 if err != nil {
766 return nil, err
767 }
768 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
769
770 params := url.Values{}
771 params.Add("$alt", "json;enum-encoding=int")
772
773 baseUrl.RawQuery = params.Encode()
774
775 // Build HTTP headers from client and context metadata.
776 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
777
778 hds = append(c.xGoogHeaders, hds...)
779 hds = append(hds, "Content-Type", "application/json")
780 headers := gax.BuildHeaders(ctx, hds...)
781 opts = append((*c.CallOptions).GetAuthorization[0:len((*c.CallOptions).GetAuthorization):len((*c.CallOptions).GetAuthorization)], opts...)
782 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
783 resp := &gsuiteaddonspb.Authorization{}
784 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
785 if settings.Path != "" {
786 baseUrl.Path = settings.Path
787 }
788 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
789 if err != nil {
790 return err
791 }
792 httpReq = httpReq.WithContext(ctx)
793 httpReq.Header = headers
794
795 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAuthorization")
796 if err != nil {
797 return err
798 }
799
800 if err := unm.Unmarshal(buf, resp); err != nil {
801 return err
802 }
803
804 return nil
805 }, opts...)
806 if e != nil {
807 return nil, e
808 }
809 return resp, nil
810 }
811
812 // CreateDeployment creates a deployment with the specified name and configuration.
813 func (c *restClient) CreateDeployment(ctx context.Context, req *gsuiteaddonspb.CreateDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
814 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
815 body := req.GetDeployment()
816 jsonReq, err := m.Marshal(body)
817 if err != nil {
818 return nil, err
819 }
820
821 baseUrl, err := url.Parse(c.endpoint)
822 if err != nil {
823 return nil, err
824 }
825 baseUrl.Path += fmt.Sprintf("/v1/%v/deployments", req.GetParent())
826
827 params := url.Values{}
828 params.Add("$alt", "json;enum-encoding=int")
829 params.Add("deploymentId", fmt.Sprintf("%v", req.GetDeploymentId()))
830
831 baseUrl.RawQuery = params.Encode()
832
833 // Build HTTP headers from client and context metadata.
834 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
835
836 hds = append(c.xGoogHeaders, hds...)
837 hds = append(hds, "Content-Type", "application/json")
838 headers := gax.BuildHeaders(ctx, hds...)
839 opts = append((*c.CallOptions).CreateDeployment[0:len((*c.CallOptions).CreateDeployment):len((*c.CallOptions).CreateDeployment)], opts...)
840 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
841 resp := &gsuiteaddonspb.Deployment{}
842 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
843 if settings.Path != "" {
844 baseUrl.Path = settings.Path
845 }
846 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
847 if err != nil {
848 return err
849 }
850 httpReq = httpReq.WithContext(ctx)
851 httpReq.Header = headers
852
853 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDeployment")
854 if err != nil {
855 return err
856 }
857
858 if err := unm.Unmarshal(buf, resp); err != nil {
859 return err
860 }
861
862 return nil
863 }, opts...)
864 if e != nil {
865 return nil, e
866 }
867 return resp, nil
868 }
869
870 // ReplaceDeployment creates or replaces a deployment with the specified name.
871 func (c *restClient) ReplaceDeployment(ctx context.Context, req *gsuiteaddonspb.ReplaceDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
872 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
873 body := req.GetDeployment()
874 jsonReq, err := m.Marshal(body)
875 if err != nil {
876 return nil, err
877 }
878
879 baseUrl, err := url.Parse(c.endpoint)
880 if err != nil {
881 return nil, err
882 }
883 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetDeployment().GetName())
884
885 params := url.Values{}
886 params.Add("$alt", "json;enum-encoding=int")
887
888 baseUrl.RawQuery = params.Encode()
889
890 // Build HTTP headers from client and context metadata.
891 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "deployment.name", url.QueryEscape(req.GetDeployment().GetName()))}
892
893 hds = append(c.xGoogHeaders, hds...)
894 hds = append(hds, "Content-Type", "application/json")
895 headers := gax.BuildHeaders(ctx, hds...)
896 opts = append((*c.CallOptions).ReplaceDeployment[0:len((*c.CallOptions).ReplaceDeployment):len((*c.CallOptions).ReplaceDeployment)], opts...)
897 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
898 resp := &gsuiteaddonspb.Deployment{}
899 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
900 if settings.Path != "" {
901 baseUrl.Path = settings.Path
902 }
903 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
904 if err != nil {
905 return err
906 }
907 httpReq = httpReq.WithContext(ctx)
908 httpReq.Header = headers
909
910 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ReplaceDeployment")
911 if err != nil {
912 return err
913 }
914
915 if err := unm.Unmarshal(buf, resp); err != nil {
916 return err
917 }
918
919 return nil
920 }, opts...)
921 if e != nil {
922 return nil, e
923 }
924 return resp, nil
925 }
926
927 // GetDeployment gets the deployment with the specified name.
928 func (c *restClient) GetDeployment(ctx context.Context, req *gsuiteaddonspb.GetDeploymentRequest, opts ...gax.CallOption) (*gsuiteaddonspb.Deployment, error) {
929 baseUrl, err := url.Parse(c.endpoint)
930 if err != nil {
931 return nil, err
932 }
933 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
934
935 params := url.Values{}
936 params.Add("$alt", "json;enum-encoding=int")
937
938 baseUrl.RawQuery = params.Encode()
939
940 // Build HTTP headers from client and context metadata.
941 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
942
943 hds = append(c.xGoogHeaders, hds...)
944 hds = append(hds, "Content-Type", "application/json")
945 headers := gax.BuildHeaders(ctx, hds...)
946 opts = append((*c.CallOptions).GetDeployment[0:len((*c.CallOptions).GetDeployment):len((*c.CallOptions).GetDeployment)], opts...)
947 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
948 resp := &gsuiteaddonspb.Deployment{}
949 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
950 if settings.Path != "" {
951 baseUrl.Path = settings.Path
952 }
953 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
954 if err != nil {
955 return err
956 }
957 httpReq = httpReq.WithContext(ctx)
958 httpReq.Header = headers
959
960 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDeployment")
961 if err != nil {
962 return err
963 }
964
965 if err := unm.Unmarshal(buf, resp); err != nil {
966 return err
967 }
968
969 return nil
970 }, opts...)
971 if e != nil {
972 return nil, e
973 }
974 return resp, nil
975 }
976
977 // ListDeployments lists all deployments in a particular project.
978 func (c *restClient) ListDeployments(ctx context.Context, req *gsuiteaddonspb.ListDeploymentsRequest, opts ...gax.CallOption) *DeploymentIterator {
979 it := &DeploymentIterator{}
980 req = proto.Clone(req).(*gsuiteaddonspb.ListDeploymentsRequest)
981 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
982 it.InternalFetch = func(pageSize int, pageToken string) ([]*gsuiteaddonspb.Deployment, string, error) {
983 resp := &gsuiteaddonspb.ListDeploymentsResponse{}
984 if pageToken != "" {
985 req.PageToken = pageToken
986 }
987 if pageSize > math.MaxInt32 {
988 req.PageSize = math.MaxInt32
989 } else if pageSize != 0 {
990 req.PageSize = int32(pageSize)
991 }
992 baseUrl, err := url.Parse(c.endpoint)
993 if err != nil {
994 return nil, "", err
995 }
996 baseUrl.Path += fmt.Sprintf("/v1/%v/deployments", req.GetParent())
997
998 params := url.Values{}
999 params.Add("$alt", "json;enum-encoding=int")
1000 if req.GetPageSize() != 0 {
1001 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1002 }
1003 if req.GetPageToken() != "" {
1004 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1005 }
1006
1007 baseUrl.RawQuery = params.Encode()
1008
1009 // Build HTTP headers from client and context metadata.
1010 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1011 headers := gax.BuildHeaders(ctx, hds...)
1012 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1013 if settings.Path != "" {
1014 baseUrl.Path = settings.Path
1015 }
1016 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1017 if err != nil {
1018 return err
1019 }
1020 httpReq.Header = headers
1021
1022 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDeployments")
1023 if err != nil {
1024 return err
1025 }
1026 if err := unm.Unmarshal(buf, resp); err != nil {
1027 return err
1028 }
1029
1030 return nil
1031 }, opts...)
1032 if e != nil {
1033 return nil, "", e
1034 }
1035 it.Response = resp
1036 return resp.GetDeployments(), resp.GetNextPageToken(), nil
1037 }
1038
1039 fetch := func(pageSize int, pageToken string) (string, error) {
1040 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1041 if err != nil {
1042 return "", err
1043 }
1044 it.items = append(it.items, items...)
1045 return nextPageToken, nil
1046 }
1047
1048 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1049 it.pageInfo.MaxSize = int(req.GetPageSize())
1050 it.pageInfo.Token = req.GetPageToken()
1051
1052 return it
1053 }
1054
1055 // DeleteDeployment deletes the deployment with the given name.
1056 func (c *restClient) DeleteDeployment(ctx context.Context, req *gsuiteaddonspb.DeleteDeploymentRequest, opts ...gax.CallOption) error {
1057 baseUrl, err := url.Parse(c.endpoint)
1058 if err != nil {
1059 return err
1060 }
1061 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1062
1063 params := url.Values{}
1064 params.Add("$alt", "json;enum-encoding=int")
1065 if req.GetEtag() != "" {
1066 params.Add("etag", fmt.Sprintf("%v", req.GetEtag()))
1067 }
1068
1069 baseUrl.RawQuery = params.Encode()
1070
1071 // Build HTTP headers from client and context metadata.
1072 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1073
1074 hds = append(c.xGoogHeaders, hds...)
1075 hds = append(hds, "Content-Type", "application/json")
1076 headers := gax.BuildHeaders(ctx, hds...)
1077 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1078 if settings.Path != "" {
1079 baseUrl.Path = settings.Path
1080 }
1081 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1082 if err != nil {
1083 return err
1084 }
1085 httpReq = httpReq.WithContext(ctx)
1086 httpReq.Header = headers
1087
1088 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDeployment")
1089 return err
1090 }, opts...)
1091 }
1092
1093 // InstallDeployment installs a deployment in developer mode.
1094 // See:
1095 // https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons (at https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons).
1096 func (c *restClient) InstallDeployment(ctx context.Context, req *gsuiteaddonspb.InstallDeploymentRequest, opts ...gax.CallOption) error {
1097 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1098 jsonReq, err := m.Marshal(req)
1099 if err != nil {
1100 return err
1101 }
1102
1103 baseUrl, err := url.Parse(c.endpoint)
1104 if err != nil {
1105 return err
1106 }
1107 baseUrl.Path += fmt.Sprintf("/v1/%v:install", req.GetName())
1108
1109 params := url.Values{}
1110 params.Add("$alt", "json;enum-encoding=int")
1111
1112 baseUrl.RawQuery = params.Encode()
1113
1114 // Build HTTP headers from client and context metadata.
1115 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1116
1117 hds = append(c.xGoogHeaders, hds...)
1118 hds = append(hds, "Content-Type", "application/json")
1119 headers := gax.BuildHeaders(ctx, hds...)
1120 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1121 if settings.Path != "" {
1122 baseUrl.Path = settings.Path
1123 }
1124 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1125 if err != nil {
1126 return err
1127 }
1128 httpReq = httpReq.WithContext(ctx)
1129 httpReq.Header = headers
1130
1131 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "InstallDeployment")
1132 return err
1133 }, opts...)
1134 }
1135
1136 // UninstallDeployment uninstalls a developer mode deployment.
1137 // See:
1138 // https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons (at https://developers.google.com/gsuite/add-ons/how-tos/testing-gsuite-addons).
1139 func (c *restClient) UninstallDeployment(ctx context.Context, req *gsuiteaddonspb.UninstallDeploymentRequest, opts ...gax.CallOption) error {
1140 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1141 jsonReq, err := m.Marshal(req)
1142 if err != nil {
1143 return err
1144 }
1145
1146 baseUrl, err := url.Parse(c.endpoint)
1147 if err != nil {
1148 return err
1149 }
1150 baseUrl.Path += fmt.Sprintf("/v1/%v:uninstall", req.GetName())
1151
1152 params := url.Values{}
1153 params.Add("$alt", "json;enum-encoding=int")
1154
1155 baseUrl.RawQuery = params.Encode()
1156
1157 // Build HTTP headers from client and context metadata.
1158 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1159
1160 hds = append(c.xGoogHeaders, hds...)
1161 hds = append(hds, "Content-Type", "application/json")
1162 headers := gax.BuildHeaders(ctx, hds...)
1163 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1164 if settings.Path != "" {
1165 baseUrl.Path = settings.Path
1166 }
1167 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1168 if err != nil {
1169 return err
1170 }
1171 httpReq = httpReq.WithContext(ctx)
1172 httpReq.Header = headers
1173
1174 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UninstallDeployment")
1175 return err
1176 }, opts...)
1177 }
1178
1179 // GetInstallStatus fetches the install status of a developer mode deployment.
1180 func (c *restClient) GetInstallStatus(ctx context.Context, req *gsuiteaddonspb.GetInstallStatusRequest, opts ...gax.CallOption) (*gsuiteaddonspb.InstallStatus, error) {
1181 baseUrl, err := url.Parse(c.endpoint)
1182 if err != nil {
1183 return nil, err
1184 }
1185 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1186
1187 params := url.Values{}
1188 params.Add("$alt", "json;enum-encoding=int")
1189
1190 baseUrl.RawQuery = params.Encode()
1191
1192 // Build HTTP headers from client and context metadata.
1193 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1194
1195 hds = append(c.xGoogHeaders, hds...)
1196 hds = append(hds, "Content-Type", "application/json")
1197 headers := gax.BuildHeaders(ctx, hds...)
1198 opts = append((*c.CallOptions).GetInstallStatus[0:len((*c.CallOptions).GetInstallStatus):len((*c.CallOptions).GetInstallStatus)], opts...)
1199 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1200 resp := &gsuiteaddonspb.InstallStatus{}
1201 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1202 if settings.Path != "" {
1203 baseUrl.Path = settings.Path
1204 }
1205 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1206 if err != nil {
1207 return err
1208 }
1209 httpReq = httpReq.WithContext(ctx)
1210 httpReq.Header = headers
1211
1212 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetInstallStatus")
1213 if err != nil {
1214 return err
1215 }
1216
1217 if err := unm.Unmarshal(buf, resp); err != nil {
1218 return err
1219 }
1220
1221 return nil
1222 }, opts...)
1223 if e != nil {
1224 return nil, e
1225 }
1226 return resp, nil
1227 }