Debian Codegraph @

apihub/apiv1/runtime_project_attachment_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 apihub
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 apihubpb "cloud.google.com/go/apihub/apiv1/apihubpb"
30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 httptransport "google.golang.org/api/transport/http"
36 locationpb "google.golang.org/genproto/googleapis/cloud/location"
37 "google.golang.org/grpc"
38 "google.golang.org/protobuf/encoding/protojson"
39 "google.golang.org/protobuf/proto"
40 )
41
42 var newRuntimeProjectAttachmentClientHook clientHook
43
44 // RuntimeProjectAttachmentCallOptions contains the retry settings for each method of RuntimeProjectAttachmentClient.
45 type RuntimeProjectAttachmentCallOptions struct {
46 CreateRuntimeProjectAttachment []gax.CallOption
47 GetRuntimeProjectAttachment []gax.CallOption
48 ListRuntimeProjectAttachments []gax.CallOption
49 DeleteRuntimeProjectAttachment []gax.CallOption
50 LookupRuntimeProjectAttachment []gax.CallOption
51 GetLocation []gax.CallOption
52 ListLocations []gax.CallOption
53 CancelOperation []gax.CallOption
54 DeleteOperation []gax.CallOption
55 GetOperation []gax.CallOption
56 ListOperations []gax.CallOption
57 }
58
59 func defaultRuntimeProjectAttachmentRESTCallOptions() *RuntimeProjectAttachmentCallOptions {
60 return &RuntimeProjectAttachmentCallOptions{
61 CreateRuntimeProjectAttachment: []gax.CallOption{
62 gax.WithTimeout(60000 * time.Millisecond),
63 },
64 GetRuntimeProjectAttachment: []gax.CallOption{
65 gax.WithTimeout(60000 * time.Millisecond),
66 gax.WithRetry(func() gax.Retryer {
67 return gax.OnHTTPCodes(gax.Backoff{
68 Initial: 1000 * time.Millisecond,
69 Max: 10000 * time.Millisecond,
70 Multiplier: 1.30,
71 },
72 http.StatusServiceUnavailable)
73 }),
74 },
75 ListRuntimeProjectAttachments: []gax.CallOption{
76 gax.WithTimeout(60000 * time.Millisecond),
77 gax.WithRetry(func() gax.Retryer {
78 return gax.OnHTTPCodes(gax.Backoff{
79 Initial: 1000 * time.Millisecond,
80 Max: 10000 * time.Millisecond,
81 Multiplier: 1.30,
82 },
83 http.StatusServiceUnavailable)
84 }),
85 },
86 DeleteRuntimeProjectAttachment: []gax.CallOption{
87 gax.WithTimeout(60000 * time.Millisecond),
88 },
89 LookupRuntimeProjectAttachment: []gax.CallOption{
90 gax.WithTimeout(60000 * time.Millisecond),
91 gax.WithRetry(func() gax.Retryer {
92 return gax.OnHTTPCodes(gax.Backoff{
93 Initial: 1000 * time.Millisecond,
94 Max: 10000 * time.Millisecond,
95 Multiplier: 1.30,
96 },
97 http.StatusServiceUnavailable)
98 }),
99 },
100 GetLocation: []gax.CallOption{},
101 ListLocations: []gax.CallOption{},
102 CancelOperation: []gax.CallOption{},
103 DeleteOperation: []gax.CallOption{},
104 GetOperation: []gax.CallOption{},
105 ListOperations: []gax.CallOption{},
106 }
107 }
108
109 // internalRuntimeProjectAttachmentClient is an interface that defines the methods available from API hub API.
110 type internalRuntimeProjectAttachmentClient interface {
111 Close() error
112 setGoogleClientInfo(...string)
113 Connection() *grpc.ClientConn
114 CreateRuntimeProjectAttachment(context.Context, *apihubpb.CreateRuntimeProjectAttachmentRequest, ...gax.CallOption) (*apihubpb.RuntimeProjectAttachment, error)
115 GetRuntimeProjectAttachment(context.Context, *apihubpb.GetRuntimeProjectAttachmentRequest, ...gax.CallOption) (*apihubpb.RuntimeProjectAttachment, error)
116 ListRuntimeProjectAttachments(context.Context, *apihubpb.ListRuntimeProjectAttachmentsRequest, ...gax.CallOption) *RuntimeProjectAttachmentIterator
117 DeleteRuntimeProjectAttachment(context.Context, *apihubpb.DeleteRuntimeProjectAttachmentRequest, ...gax.CallOption) error
118 LookupRuntimeProjectAttachment(context.Context, *apihubpb.LookupRuntimeProjectAttachmentRequest, ...gax.CallOption) (*apihubpb.LookupRuntimeProjectAttachmentResponse, error)
119 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
120 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
121 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
122 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
123 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
124 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
125 }
126
127 // RuntimeProjectAttachmentClient is a client for interacting with API hub API.
128 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
129 //
130 // This service is used for managing the runtime project attachments.
131 type RuntimeProjectAttachmentClient struct {
132 // The internal transport-dependent client.
133 internalClient internalRuntimeProjectAttachmentClient
134
135 // The call options for this service.
136 CallOptions *RuntimeProjectAttachmentCallOptions
137 }
138
139 // Wrapper methods routed to the internal client.
140
141 // Close closes the connection to the API service. The user should invoke this when
142 // the client is no longer required.
143 func (c *RuntimeProjectAttachmentClient) Close() error {
144 return c.internalClient.Close()
145 }
146
147 // setGoogleClientInfo sets the name and version of the application in
148 // the `x-goog-api-client` header passed on each request. Intended for
149 // use by Google-written clients.
150 func (c *RuntimeProjectAttachmentClient) setGoogleClientInfo(keyval ...string) {
151 c.internalClient.setGoogleClientInfo(keyval...)
152 }
153
154 // Connection returns a connection to the API service.
155 //
156 // Deprecated: Connections are now pooled so this method does not always
157 // return the same resource.
158 func (c *RuntimeProjectAttachmentClient) Connection() *grpc.ClientConn {
159 return c.internalClient.Connection()
160 }
161
162 // CreateRuntimeProjectAttachment attaches a runtime project to the host project.
163 func (c *RuntimeProjectAttachmentClient) CreateRuntimeProjectAttachment(ctx context.Context, req *apihubpb.CreateRuntimeProjectAttachmentRequest, opts ...gax.CallOption) (*apihubpb.RuntimeProjectAttachment, error) {
164 return c.internalClient.CreateRuntimeProjectAttachment(ctx, req, opts...)
165 }
166
167 // GetRuntimeProjectAttachment gets a runtime project attachment.
168 func (c *RuntimeProjectAttachmentClient) GetRuntimeProjectAttachment(ctx context.Context, req *apihubpb.GetRuntimeProjectAttachmentRequest, opts ...gax.CallOption) (*apihubpb.RuntimeProjectAttachment, error) {
169 return c.internalClient.GetRuntimeProjectAttachment(ctx, req, opts...)
170 }
171
172 // ListRuntimeProjectAttachments list runtime projects attached to the host project.
173 func (c *RuntimeProjectAttachmentClient) ListRuntimeProjectAttachments(ctx context.Context, req *apihubpb.ListRuntimeProjectAttachmentsRequest, opts ...gax.CallOption) *RuntimeProjectAttachmentIterator {
174 return c.internalClient.ListRuntimeProjectAttachments(ctx, req, opts...)
175 }
176
177 // DeleteRuntimeProjectAttachment delete a runtime project attachment in the API Hub. This call will detach
178 // the runtime project from the host project.
179 func (c *RuntimeProjectAttachmentClient) DeleteRuntimeProjectAttachment(ctx context.Context, req *apihubpb.DeleteRuntimeProjectAttachmentRequest, opts ...gax.CallOption) error {
180 return c.internalClient.DeleteRuntimeProjectAttachment(ctx, req, opts...)
181 }
182
183 // LookupRuntimeProjectAttachment look up a runtime project attachment. This API can be called in the context
184 // of any project.
185 func (c *RuntimeProjectAttachmentClient) LookupRuntimeProjectAttachment(ctx context.Context, req *apihubpb.LookupRuntimeProjectAttachmentRequest, opts ...gax.CallOption) (*apihubpb.LookupRuntimeProjectAttachmentResponse, error) {
186 return c.internalClient.LookupRuntimeProjectAttachment(ctx, req, opts...)
187 }
188
189 // GetLocation gets information about a location.
190 func (c *RuntimeProjectAttachmentClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
191 return c.internalClient.GetLocation(ctx, req, opts...)
192 }
193
194 // ListLocations lists information about the supported locations for this service.
195 func (c *RuntimeProjectAttachmentClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
196 return c.internalClient.ListLocations(ctx, req, opts...)
197 }
198
199 // CancelOperation is a utility method from google.longrunning.Operations.
200 func (c *RuntimeProjectAttachmentClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
201 return c.internalClient.CancelOperation(ctx, req, opts...)
202 }
203
204 // DeleteOperation is a utility method from google.longrunning.Operations.
205 func (c *RuntimeProjectAttachmentClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
206 return c.internalClient.DeleteOperation(ctx, req, opts...)
207 }
208
209 // GetOperation is a utility method from google.longrunning.Operations.
210 func (c *RuntimeProjectAttachmentClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
211 return c.internalClient.GetOperation(ctx, req, opts...)
212 }
213
214 // ListOperations is a utility method from google.longrunning.Operations.
215 func (c *RuntimeProjectAttachmentClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
216 return c.internalClient.ListOperations(ctx, req, opts...)
217 }
218
219 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
220 type runtimeProjectAttachmentRESTClient struct {
221 // The http endpoint to connect to.
222 endpoint string
223
224 // The http client.
225 httpClient *http.Client
226
227 // The x-goog-* headers to be sent with each request.
228 xGoogHeaders []string
229
230 // Points back to the CallOptions field of the containing RuntimeProjectAttachmentClient
231 CallOptions **RuntimeProjectAttachmentCallOptions
232
233 logger *slog.Logger
234 }
235
236 // NewRuntimeProjectAttachmentRESTClient creates a new runtime project attachment service rest client.
237 //
238 // This service is used for managing the runtime project attachments.
239 func NewRuntimeProjectAttachmentRESTClient(ctx context.Context, opts ...option.ClientOption) (*RuntimeProjectAttachmentClient, error) {
240 clientOpts := append(defaultRuntimeProjectAttachmentRESTClientOptions(), opts...)
241 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
242 if err != nil {
243 return nil, err
244 }
245
246 callOpts := defaultRuntimeProjectAttachmentRESTCallOptions()
247 c := &runtimeProjectAttachmentRESTClient{
248 endpoint: endpoint,
249 httpClient: httpClient,
250 CallOptions: &callOpts,
251 logger: internaloption.GetLogger(opts),
252 }
253 c.setGoogleClientInfo()
254
255 return &RuntimeProjectAttachmentClient{internalClient: c, CallOptions: callOpts}, nil
256 }
257
258 func defaultRuntimeProjectAttachmentRESTClientOptions() []option.ClientOption {
259 return []option.ClientOption{
260 internaloption.WithDefaultEndpoint("https://apihub.googleapis.com"),
261 internaloption.WithDefaultEndpointTemplate("https://apihub.UNIVERSE_DOMAIN"),
262 internaloption.WithDefaultMTLSEndpoint("https://apihub.mtls.googleapis.com"),
263 internaloption.WithDefaultUniverseDomain("googleapis.com"),
264 internaloption.WithDefaultAudience("https://apihub.googleapis.com/"),
265 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
266 internaloption.EnableNewAuthLibrary(),
267 }
268 }
269
270 // setGoogleClientInfo sets the name and version of the application in
271 // the `x-goog-api-client` header passed on each request. Intended for
272 // use by Google-written clients.
273 func (c *runtimeProjectAttachmentRESTClient) setGoogleClientInfo(keyval ...string) {
274 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
275 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
276 c.xGoogHeaders = []string{
277 "x-goog-api-client", gax.XGoogHeader(kv...),
278 }
279 }
280
281 // Close closes the connection to the API service. The user should invoke this when
282 // the client is no longer required.
283 func (c *runtimeProjectAttachmentRESTClient) Close() error {
284 // Replace httpClient with nil to force cleanup.
285 c.httpClient = nil
286 return nil
287 }
288
289 // Connection returns a connection to the API service.
290 //
291 // Deprecated: This method always returns nil.
292 func (c *runtimeProjectAttachmentRESTClient) Connection() *grpc.ClientConn {
293 return nil
294 }
295
296 // CreateRuntimeProjectAttachment attaches a runtime project to the host project.
297 func (c *runtimeProjectAttachmentRESTClient) CreateRuntimeProjectAttachment(ctx context.Context, req *apihubpb.CreateRuntimeProjectAttachmentRequest, opts ...gax.CallOption) (*apihubpb.RuntimeProjectAttachment, error) {
298 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
299 body := req.GetRuntimeProjectAttachment()
300 jsonReq, err := m.Marshal(body)
301 if err != nil {
302 return nil, err
303 }
304
305 baseUrl, err := url.Parse(c.endpoint)
306 if err != nil {
307 return nil, err
308 }
309 baseUrl.Path += fmt.Sprintf("/v1/%v/runtimeProjectAttachments", req.GetParent())
310
311 params := url.Values{}
312 params.Add("$alt", "json;enum-encoding=int")
313 params.Add("runtimeProjectAttachmentId", fmt.Sprintf("%v", req.GetRuntimeProjectAttachmentId()))
314
315 baseUrl.RawQuery = params.Encode()
316
317 // Build HTTP headers from client and context metadata.
318 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
319
320 hds = append(c.xGoogHeaders, hds...)
321 hds = append(hds, "Content-Type", "application/json")
322 headers := gax.BuildHeaders(ctx, hds...)
323 opts = append((*c.CallOptions).CreateRuntimeProjectAttachment[0:len((*c.CallOptions).CreateRuntimeProjectAttachment):len((*c.CallOptions).CreateRuntimeProjectAttachment)], opts...)
324 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
325 resp := &apihubpb.RuntimeProjectAttachment{}
326 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
327 if settings.Path != "" {
328 baseUrl.Path = settings.Path
329 }
330 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
331 if err != nil {
332 return err
333 }
334 httpReq = httpReq.WithContext(ctx)
335 httpReq.Header = headers
336
337 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateRuntimeProjectAttachment")
338 if err != nil {
339 return err
340 }
341
342 if err := unm.Unmarshal(buf, resp); err != nil {
343 return err
344 }
345
346 return nil
347 }, opts...)
348 if e != nil {
349 return nil, e
350 }
351 return resp, nil
352 }
353
354 // GetRuntimeProjectAttachment gets a runtime project attachment.
355 func (c *runtimeProjectAttachmentRESTClient) GetRuntimeProjectAttachment(ctx context.Context, req *apihubpb.GetRuntimeProjectAttachmentRequest, opts ...gax.CallOption) (*apihubpb.RuntimeProjectAttachment, error) {
356 baseUrl, err := url.Parse(c.endpoint)
357 if err != nil {
358 return nil, err
359 }
360 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
361
362 params := url.Values{}
363 params.Add("$alt", "json;enum-encoding=int")
364
365 baseUrl.RawQuery = params.Encode()
366
367 // Build HTTP headers from client and context metadata.
368 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
369
370 hds = append(c.xGoogHeaders, hds...)
371 hds = append(hds, "Content-Type", "application/json")
372 headers := gax.BuildHeaders(ctx, hds...)
373 opts = append((*c.CallOptions).GetRuntimeProjectAttachment[0:len((*c.CallOptions).GetRuntimeProjectAttachment):len((*c.CallOptions).GetRuntimeProjectAttachment)], opts...)
374 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
375 resp := &apihubpb.RuntimeProjectAttachment{}
376 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
377 if settings.Path != "" {
378 baseUrl.Path = settings.Path
379 }
380 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
381 if err != nil {
382 return err
383 }
384 httpReq = httpReq.WithContext(ctx)
385 httpReq.Header = headers
386
387 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetRuntimeProjectAttachment")
388 if err != nil {
389 return err
390 }
391
392 if err := unm.Unmarshal(buf, resp); err != nil {
393 return err
394 }
395
396 return nil
397 }, opts...)
398 if e != nil {
399 return nil, e
400 }
401 return resp, nil
402 }
403
404 // ListRuntimeProjectAttachments list runtime projects attached to the host project.
405 func (c *runtimeProjectAttachmentRESTClient) ListRuntimeProjectAttachments(ctx context.Context, req *apihubpb.ListRuntimeProjectAttachmentsRequest, opts ...gax.CallOption) *RuntimeProjectAttachmentIterator {
406 it := &RuntimeProjectAttachmentIterator{}
407 req = proto.Clone(req).(*apihubpb.ListRuntimeProjectAttachmentsRequest)
408 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
409 it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.RuntimeProjectAttachment, string, error) {
410 resp := &apihubpb.ListRuntimeProjectAttachmentsResponse{}
411 if pageToken != "" {
412 req.PageToken = pageToken
413 }
414 if pageSize > math.MaxInt32 {
415 req.PageSize = math.MaxInt32
416 } else if pageSize != 0 {
417 req.PageSize = int32(pageSize)
418 }
419 baseUrl, err := url.Parse(c.endpoint)
420 if err != nil {
421 return nil, "", err
422 }
423 baseUrl.Path += fmt.Sprintf("/v1/%v/runtimeProjectAttachments", req.GetParent())
424
425 params := url.Values{}
426 params.Add("$alt", "json;enum-encoding=int")
427 if req.GetFilter() != "" {
428 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
429 }
430 if req.GetOrderBy() != "" {
431 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
432 }
433 if req.GetPageSize() != 0 {
434 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
435 }
436 if req.GetPageToken() != "" {
437 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
438 }
439
440 baseUrl.RawQuery = params.Encode()
441
442 // Build HTTP headers from client and context metadata.
443 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
444 headers := gax.BuildHeaders(ctx, hds...)
445 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
446 if settings.Path != "" {
447 baseUrl.Path = settings.Path
448 }
449 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
450 if err != nil {
451 return err
452 }
453 httpReq.Header = headers
454
455 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListRuntimeProjectAttachments")
456 if err != nil {
457 return err
458 }
459 if err := unm.Unmarshal(buf, resp); err != nil {
460 return err
461 }
462
463 return nil
464 }, opts...)
465 if e != nil {
466 return nil, "", e
467 }
468 it.Response = resp
469 return resp.GetRuntimeProjectAttachments(), resp.GetNextPageToken(), nil
470 }
471
472 fetch := func(pageSize int, pageToken string) (string, error) {
473 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
474 if err != nil {
475 return "", err
476 }
477 it.items = append(it.items, items...)
478 return nextPageToken, nil
479 }
480
481 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
482 it.pageInfo.MaxSize = int(req.GetPageSize())
483 it.pageInfo.Token = req.GetPageToken()
484
485 return it
486 }
487
488 // DeleteRuntimeProjectAttachment delete a runtime project attachment in the API Hub. This call will detach
489 // the runtime project from the host project.
490 func (c *runtimeProjectAttachmentRESTClient) DeleteRuntimeProjectAttachment(ctx context.Context, req *apihubpb.DeleteRuntimeProjectAttachmentRequest, opts ...gax.CallOption) error {
491 baseUrl, err := url.Parse(c.endpoint)
492 if err != nil {
493 return err
494 }
495 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
496
497 params := url.Values{}
498 params.Add("$alt", "json;enum-encoding=int")
499
500 baseUrl.RawQuery = params.Encode()
501
502 // Build HTTP headers from client and context metadata.
503 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
504
505 hds = append(c.xGoogHeaders, hds...)
506 hds = append(hds, "Content-Type", "application/json")
507 headers := gax.BuildHeaders(ctx, hds...)
508 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
509 if settings.Path != "" {
510 baseUrl.Path = settings.Path
511 }
512 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
513 if err != nil {
514 return err
515 }
516 httpReq = httpReq.WithContext(ctx)
517 httpReq.Header = headers
518
519 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteRuntimeProjectAttachment")
520 return err
521 }, opts...)
522 }
523
524 // LookupRuntimeProjectAttachment look up a runtime project attachment. This API can be called in the context
525 // of any project.
526 func (c *runtimeProjectAttachmentRESTClient) LookupRuntimeProjectAttachment(ctx context.Context, req *apihubpb.LookupRuntimeProjectAttachmentRequest, opts ...gax.CallOption) (*apihubpb.LookupRuntimeProjectAttachmentResponse, error) {
527 baseUrl, err := url.Parse(c.endpoint)
528 if err != nil {
529 return nil, err
530 }
531 baseUrl.Path += fmt.Sprintf("/v1/%v:lookupRuntimeProjectAttachment", req.GetName())
532
533 params := url.Values{}
534 params.Add("$alt", "json;enum-encoding=int")
535
536 baseUrl.RawQuery = params.Encode()
537
538 // Build HTTP headers from client and context metadata.
539 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
540
541 hds = append(c.xGoogHeaders, hds...)
542 hds = append(hds, "Content-Type", "application/json")
543 headers := gax.BuildHeaders(ctx, hds...)
544 opts = append((*c.CallOptions).LookupRuntimeProjectAttachment[0:len((*c.CallOptions).LookupRuntimeProjectAttachment):len((*c.CallOptions).LookupRuntimeProjectAttachment)], opts...)
545 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
546 resp := &apihubpb.LookupRuntimeProjectAttachmentResponse{}
547 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
548 if settings.Path != "" {
549 baseUrl.Path = settings.Path
550 }
551 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
552 if err != nil {
553 return err
554 }
555 httpReq = httpReq.WithContext(ctx)
556 httpReq.Header = headers
557
558 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "LookupRuntimeProjectAttachment")
559 if err != nil {
560 return err
561 }
562
563 if err := unm.Unmarshal(buf, resp); err != nil {
564 return err
565 }
566
567 return nil
568 }, opts...)
569 if e != nil {
570 return nil, e
571 }
572 return resp, nil
573 }
574
575 // GetLocation gets information about a location.
576 func (c *runtimeProjectAttachmentRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
577 baseUrl, err := url.Parse(c.endpoint)
578 if err != nil {
579 return nil, err
580 }
581 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
582
583 params := url.Values{}
584 params.Add("$alt", "json;enum-encoding=int")
585
586 baseUrl.RawQuery = params.Encode()
587
588 // Build HTTP headers from client and context metadata.
589 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
590
591 hds = append(c.xGoogHeaders, hds...)
592 hds = append(hds, "Content-Type", "application/json")
593 headers := gax.BuildHeaders(ctx, hds...)
594 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
595 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
596 resp := &locationpb.Location{}
597 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
598 if settings.Path != "" {
599 baseUrl.Path = settings.Path
600 }
601 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
602 if err != nil {
603 return err
604 }
605 httpReq = httpReq.WithContext(ctx)
606 httpReq.Header = headers
607
608 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
609 if err != nil {
610 return err
611 }
612
613 if err := unm.Unmarshal(buf, resp); err != nil {
614 return err
615 }
616
617 return nil
618 }, opts...)
619 if e != nil {
620 return nil, e
621 }
622 return resp, nil
623 }
624
625 // ListLocations lists information about the supported locations for this service.
626 func (c *runtimeProjectAttachmentRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
627 it := &LocationIterator{}
628 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
629 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
630 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
631 resp := &locationpb.ListLocationsResponse{}
632 if pageToken != "" {
633 req.PageToken = pageToken
634 }
635 if pageSize > math.MaxInt32 {
636 req.PageSize = math.MaxInt32
637 } else if pageSize != 0 {
638 req.PageSize = int32(pageSize)
639 }
640 baseUrl, err := url.Parse(c.endpoint)
641 if err != nil {
642 return nil, "", err
643 }
644 baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName())
645
646 params := url.Values{}
647 params.Add("$alt", "json;enum-encoding=int")
648 if req.GetFilter() != "" {
649 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
650 }
651 if req.GetPageSize() != 0 {
652 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
653 }
654 if req.GetPageToken() != "" {
655 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
656 }
657
658 baseUrl.RawQuery = params.Encode()
659
660 // Build HTTP headers from client and context metadata.
661 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
662 headers := gax.BuildHeaders(ctx, hds...)
663 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
664 if settings.Path != "" {
665 baseUrl.Path = settings.Path
666 }
667 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
668 if err != nil {
669 return err
670 }
671 httpReq.Header = headers
672
673 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
674 if err != nil {
675 return err
676 }
677 if err := unm.Unmarshal(buf, resp); err != nil {
678 return err
679 }
680
681 return nil
682 }, opts...)
683 if e != nil {
684 return nil, "", e
685 }
686 it.Response = resp
687 return resp.GetLocations(), resp.GetNextPageToken(), nil
688 }
689
690 fetch := func(pageSize int, pageToken string) (string, error) {
691 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
692 if err != nil {
693 return "", err
694 }
695 it.items = append(it.items, items...)
696 return nextPageToken, nil
697 }
698
699 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
700 it.pageInfo.MaxSize = int(req.GetPageSize())
701 it.pageInfo.Token = req.GetPageToken()
702
703 return it
704 }
705
706 // CancelOperation is a utility method from google.longrunning.Operations.
707 func (c *runtimeProjectAttachmentRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
708 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
709 jsonReq, err := m.Marshal(req)
710 if err != nil {
711 return err
712 }
713
714 baseUrl, err := url.Parse(c.endpoint)
715 if err != nil {
716 return err
717 }
718 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
719
720 params := url.Values{}
721 params.Add("$alt", "json;enum-encoding=int")
722
723 baseUrl.RawQuery = params.Encode()
724
725 // Build HTTP headers from client and context metadata.
726 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
727
728 hds = append(c.xGoogHeaders, hds...)
729 hds = append(hds, "Content-Type", "application/json")
730 headers := gax.BuildHeaders(ctx, hds...)
731 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
732 if settings.Path != "" {
733 baseUrl.Path = settings.Path
734 }
735 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
736 if err != nil {
737 return err
738 }
739 httpReq = httpReq.WithContext(ctx)
740 httpReq.Header = headers
741
742 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
743 return err
744 }, opts...)
745 }
746
747 // DeleteOperation is a utility method from google.longrunning.Operations.
748 func (c *runtimeProjectAttachmentRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
749 baseUrl, err := url.Parse(c.endpoint)
750 if err != nil {
751 return err
752 }
753 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
754
755 params := url.Values{}
756 params.Add("$alt", "json;enum-encoding=int")
757
758 baseUrl.RawQuery = params.Encode()
759
760 // Build HTTP headers from client and context metadata.
761 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
762
763 hds = append(c.xGoogHeaders, hds...)
764 hds = append(hds, "Content-Type", "application/json")
765 headers := gax.BuildHeaders(ctx, hds...)
766 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
767 if settings.Path != "" {
768 baseUrl.Path = settings.Path
769 }
770 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
771 if err != nil {
772 return err
773 }
774 httpReq = httpReq.WithContext(ctx)
775 httpReq.Header = headers
776
777 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
778 return err
779 }, opts...)
780 }
781
782 // GetOperation is a utility method from google.longrunning.Operations.
783 func (c *runtimeProjectAttachmentRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
784 baseUrl, err := url.Parse(c.endpoint)
785 if err != nil {
786 return nil, err
787 }
788 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
789
790 params := url.Values{}
791 params.Add("$alt", "json;enum-encoding=int")
792
793 baseUrl.RawQuery = params.Encode()
794
795 // Build HTTP headers from client and context metadata.
796 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
797
798 hds = append(c.xGoogHeaders, hds...)
799 hds = append(hds, "Content-Type", "application/json")
800 headers := gax.BuildHeaders(ctx, hds...)
801 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
802 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
803 resp := &longrunningpb.Operation{}
804 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
805 if settings.Path != "" {
806 baseUrl.Path = settings.Path
807 }
808 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
809 if err != nil {
810 return err
811 }
812 httpReq = httpReq.WithContext(ctx)
813 httpReq.Header = headers
814
815 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
816 if err != nil {
817 return err
818 }
819
820 if err := unm.Unmarshal(buf, resp); err != nil {
821 return err
822 }
823
824 return nil
825 }, opts...)
826 if e != nil {
827 return nil, e
828 }
829 return resp, nil
830 }
831
832 // ListOperations is a utility method from google.longrunning.Operations.
833 func (c *runtimeProjectAttachmentRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
834 it := &OperationIterator{}
835 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
836 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
837 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
838 resp := &longrunningpb.ListOperationsResponse{}
839 if pageToken != "" {
840 req.PageToken = pageToken
841 }
842 if pageSize > math.MaxInt32 {
843 req.PageSize = math.MaxInt32
844 } else if pageSize != 0 {
845 req.PageSize = int32(pageSize)
846 }
847 baseUrl, err := url.Parse(c.endpoint)
848 if err != nil {
849 return nil, "", err
850 }
851 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
852
853 params := url.Values{}
854 params.Add("$alt", "json;enum-encoding=int")
855 if req.GetFilter() != "" {
856 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
857 }
858 if req.GetPageSize() != 0 {
859 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
860 }
861 if req.GetPageToken() != "" {
862 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
863 }
864
865 baseUrl.RawQuery = params.Encode()
866
867 // Build HTTP headers from client and context metadata.
868 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
869 headers := gax.BuildHeaders(ctx, hds...)
870 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
871 if settings.Path != "" {
872 baseUrl.Path = settings.Path
873 }
874 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
875 if err != nil {
876 return err
877 }
878 httpReq.Header = headers
879
880 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
881 if err != nil {
882 return err
883 }
884 if err := unm.Unmarshal(buf, resp); err != nil {
885 return err
886 }
887
888 return nil
889 }, opts...)
890 if e != nil {
891 return nil, "", e
892 }
893 it.Response = resp
894 return resp.GetOperations(), resp.GetNextPageToken(), nil
895 }
896
897 fetch := func(pageSize int, pageToken string) (string, error) {
898 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
899 if err != nil {
900 return "", err
901 }
902 it.items = append(it.items, items...)
903 return nextPageToken, nil
904 }
905
906 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
907 it.pageInfo.MaxSize = int(req.GetPageSize())
908 it.pageInfo.Token = req.GetPageToken()
909
910 return it
911 }