1// Copyright 2021 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
17package compute
18
19import (
20	"bytes"
21	"context"
22	"fmt"
23	"io/ioutil"
24	"math"
25	"net/http"
26	"net/url"
27	"sort"
28
29	gax "github.com/googleapis/gax-go/v2"
30	"google.golang.org/api/iterator"
31	"google.golang.org/api/option"
32	"google.golang.org/api/option/internaloption"
33	httptransport "google.golang.org/api/transport/http"
34	computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"
35	"google.golang.org/grpc"
36	"google.golang.org/grpc/metadata"
37	"google.golang.org/protobuf/encoding/protojson"
38	"google.golang.org/protobuf/proto"
39)
40
41var newUrlMapsClientHook clientHook
42
43// UrlMapsCallOptions contains the retry settings for each method of UrlMapsClient.
44type UrlMapsCallOptions struct {
45	AggregatedList  []gax.CallOption
46	Delete          []gax.CallOption
47	Get             []gax.CallOption
48	Insert          []gax.CallOption
49	InvalidateCache []gax.CallOption
50	List            []gax.CallOption
51	Patch           []gax.CallOption
52	Update          []gax.CallOption
53	Validate        []gax.CallOption
54}
55
56// internalUrlMapsClient is an interface that defines the methods availaible from Google Compute Engine API.
57type internalUrlMapsClient interface {
58	Close() error
59	setGoogleClientInfo(...string)
60	Connection() *grpc.ClientConn
61	AggregatedList(context.Context, *computepb.AggregatedListUrlMapsRequest, ...gax.CallOption) *UrlMapsScopedListPairIterator
62	Delete(context.Context, *computepb.DeleteUrlMapRequest, ...gax.CallOption) (*Operation, error)
63	Get(context.Context, *computepb.GetUrlMapRequest, ...gax.CallOption) (*computepb.UrlMap, error)
64	Insert(context.Context, *computepb.InsertUrlMapRequest, ...gax.CallOption) (*Operation, error)
65	InvalidateCache(context.Context, *computepb.InvalidateCacheUrlMapRequest, ...gax.CallOption) (*Operation, error)
66	List(context.Context, *computepb.ListUrlMapsRequest, ...gax.CallOption) *UrlMapIterator
67	Patch(context.Context, *computepb.PatchUrlMapRequest, ...gax.CallOption) (*Operation, error)
68	Update(context.Context, *computepb.UpdateUrlMapRequest, ...gax.CallOption) (*Operation, error)
69	Validate(context.Context, *computepb.ValidateUrlMapRequest, ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error)
70}
71
72// UrlMapsClient is a client for interacting with Google Compute Engine API.
73// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
74//
75// The UrlMaps API.
76type UrlMapsClient struct {
77	// The internal transport-dependent client.
78	internalClient internalUrlMapsClient
79
80	// The call options for this service.
81	CallOptions *UrlMapsCallOptions
82}
83
84// Wrapper methods routed to the internal client.
85
86// Close closes the connection to the API service. The user should invoke this when
87// the client is no longer required.
88func (c *UrlMapsClient) Close() error {
89	return c.internalClient.Close()
90}
91
92// setGoogleClientInfo sets the name and version of the application in
93// the `x-goog-api-client` header passed on each request. Intended for
94// use by Google-written clients.
95func (c *UrlMapsClient) setGoogleClientInfo(keyval ...string) {
96	c.internalClient.setGoogleClientInfo(keyval...)
97}
98
99// Connection returns a connection to the API service.
100//
101// Deprecated.
102func (c *UrlMapsClient) Connection() *grpc.ClientConn {
103	return c.internalClient.Connection()
104}
105
106// AggregatedList retrieves the list of all UrlMap resources, regional and global, available to the specified project.
107func (c *UrlMapsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListUrlMapsRequest, opts ...gax.CallOption) *UrlMapsScopedListPairIterator {
108	return c.internalClient.AggregatedList(ctx, req, opts...)
109}
110
111// Delete deletes the specified UrlMap resource.
112func (c *UrlMapsClient) Delete(ctx context.Context, req *computepb.DeleteUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
113	return c.internalClient.Delete(ctx, req, opts...)
114}
115
116// Get returns the specified UrlMap resource. Gets a list of available URL maps by making a list() request.
117func (c *UrlMapsClient) Get(ctx context.Context, req *computepb.GetUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMap, error) {
118	return c.internalClient.Get(ctx, req, opts...)
119}
120
121// Insert creates a UrlMap resource in the specified project using the data included in the request.
122func (c *UrlMapsClient) Insert(ctx context.Context, req *computepb.InsertUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
123	return c.internalClient.Insert(ctx, req, opts...)
124}
125
126// InvalidateCache initiates a cache invalidation operation, invalidating the specified path, scoped to the specified UrlMap.
127//
128// For more information, see Invalidating cached content (at /cdn/docs/invalidating-cached-content).
129func (c *UrlMapsClient) InvalidateCache(ctx context.Context, req *computepb.InvalidateCacheUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
130	return c.internalClient.InvalidateCache(ctx, req, opts...)
131}
132
133// List retrieves the list of UrlMap resources available to the specified project.
134func (c *UrlMapsClient) List(ctx context.Context, req *computepb.ListUrlMapsRequest, opts ...gax.CallOption) *UrlMapIterator {
135	return c.internalClient.List(ctx, req, opts...)
136}
137
138// Patch patches the specified UrlMap resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
139func (c *UrlMapsClient) Patch(ctx context.Context, req *computepb.PatchUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
140	return c.internalClient.Patch(ctx, req, opts...)
141}
142
143// Update updates the specified UrlMap resource with the data included in the request.
144func (c *UrlMapsClient) Update(ctx context.Context, req *computepb.UpdateUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
145	return c.internalClient.Update(ctx, req, opts...)
146}
147
148// Validate runs static validation for the UrlMap. In particular, the tests of the provided UrlMap will be run. Calling this method does NOT create the UrlMap.
149func (c *UrlMapsClient) Validate(ctx context.Context, req *computepb.ValidateUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) {
150	return c.internalClient.Validate(ctx, req, opts...)
151}
152
153// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
154type urlMapsRESTClient struct {
155	// The http endpoint to connect to.
156	endpoint string
157
158	// The http client.
159	httpClient *http.Client
160
161	// The x-goog-* metadata to be sent with each request.
162	xGoogMetadata metadata.MD
163}
164
165// NewUrlMapsRESTClient creates a new url maps rest client.
166//
167// The UrlMaps API.
168func NewUrlMapsRESTClient(ctx context.Context, opts ...option.ClientOption) (*UrlMapsClient, error) {
169	clientOpts := append(defaultUrlMapsRESTClientOptions(), opts...)
170	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
171	if err != nil {
172		return nil, err
173	}
174
175	c := &urlMapsRESTClient{
176		endpoint:   endpoint,
177		httpClient: httpClient,
178	}
179	c.setGoogleClientInfo()
180
181	return &UrlMapsClient{internalClient: c, CallOptions: &UrlMapsCallOptions{}}, nil
182}
183
184func defaultUrlMapsRESTClientOptions() []option.ClientOption {
185	return []option.ClientOption{
186		internaloption.WithDefaultEndpoint("https://compute.googleapis.com"),
187		internaloption.WithDefaultMTLSEndpoint("https://compute.mtls.googleapis.com"),
188		internaloption.WithDefaultAudience("https://compute.googleapis.com/"),
189		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
190	}
191}
192
193// setGoogleClientInfo sets the name and version of the application in
194// the `x-goog-api-client` header passed on each request. Intended for
195// use by Google-written clients.
196func (c *urlMapsRESTClient) setGoogleClientInfo(keyval ...string) {
197	kv := append([]string{"gl-go", versionGo()}, keyval...)
198	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN")
199	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
200}
201
202// Close closes the connection to the API service. The user should invoke this when
203// the client is no longer required.
204func (c *urlMapsRESTClient) Close() error {
205	// Replace httpClient with nil to force cleanup.
206	c.httpClient = nil
207	return nil
208}
209
210// Connection returns a connection to the API service.
211//
212// Deprecated.
213func (c *urlMapsRESTClient) Connection() *grpc.ClientConn {
214	return nil
215}
216
217// AggregatedList retrieves the list of all UrlMap resources, regional and global, available to the specified project.
218func (c *urlMapsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListUrlMapsRequest, opts ...gax.CallOption) *UrlMapsScopedListPairIterator {
219	it := &UrlMapsScopedListPairIterator{}
220	req = proto.Clone(req).(*computepb.AggregatedListUrlMapsRequest)
221	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
222	it.InternalFetch = func(pageSize int, pageToken string) ([]UrlMapsScopedListPair, string, error) {
223		resp := &computepb.UrlMapsAggregatedList{}
224		if pageToken != "" {
225			req.PageToken = proto.String(pageToken)
226		}
227		if pageSize > math.MaxInt32 {
228			req.MaxResults = proto.Uint32(math.MaxInt32)
229		} else if pageSize != 0 {
230			req.MaxResults = proto.Uint32(uint32(pageSize))
231		}
232		baseUrl, _ := url.Parse(c.endpoint)
233		baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/urlMaps", req.GetProject())
234
235		params := url.Values{}
236		if req != nil && req.Filter != nil {
237			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
238		}
239		if req != nil && req.IncludeAllScopes != nil {
240			params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes()))
241		}
242		if req != nil && req.MaxResults != nil {
243			params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults()))
244		}
245		if req != nil && req.OrderBy != nil {
246			params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
247		}
248		if req != nil && req.PageToken != nil {
249			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
250		}
251		if req != nil && req.ReturnPartialSuccess != nil {
252			params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
253		}
254
255		baseUrl.RawQuery = params.Encode()
256
257		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
258		if err != nil {
259			return nil, "", err
260		}
261
262		// Set the headers
263		for k, v := range c.xGoogMetadata {
264			httpReq.Header[k] = v
265		}
266
267		httpReq.Header["Content-Type"] = []string{"application/json"}
268		httpRsp, err := c.httpClient.Do(httpReq)
269		if err != nil {
270			return nil, "", err
271		}
272		defer httpRsp.Body.Close()
273
274		if httpRsp.StatusCode != http.StatusOK {
275			return nil, "", fmt.Errorf(httpRsp.Status)
276		}
277
278		buf, err := ioutil.ReadAll(httpRsp.Body)
279		if err != nil {
280			return nil, "", err
281		}
282
283		unm.Unmarshal(buf, resp)
284		it.Response = resp
285
286		elems := make([]UrlMapsScopedListPair, 0, len(resp.GetItems()))
287		for k, v := range resp.GetItems() {
288			elems = append(elems, UrlMapsScopedListPair{k, v})
289		}
290		sort.Slice(elems, func(i, j int) bool { return elems[i].Key < elems[j].Key })
291
292		return elems, resp.GetNextPageToken(), nil
293	}
294
295	fetch := func(pageSize int, pageToken string) (string, error) {
296		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
297		if err != nil {
298			return "", err
299		}
300		it.items = append(it.items, items...)
301		return nextPageToken, nil
302	}
303
304	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
305	it.pageInfo.MaxSize = int(req.GetMaxResults())
306	it.pageInfo.Token = req.GetPageToken()
307
308	return it
309}
310
311// Delete deletes the specified UrlMap resource.
312func (c *urlMapsRESTClient) Delete(ctx context.Context, req *computepb.DeleteUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
313	baseUrl, _ := url.Parse(c.endpoint)
314	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap())
315
316	params := url.Values{}
317	if req != nil && req.RequestId != nil {
318		params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
319	}
320
321	baseUrl.RawQuery = params.Encode()
322
323	httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
324	if err != nil {
325		return nil, err
326	}
327	httpReq = httpReq.WithContext(ctx)
328	// Set the headers
329	for k, v := range c.xGoogMetadata {
330		httpReq.Header[k] = v
331	}
332	httpReq.Header["Content-Type"] = []string{"application/json"}
333
334	httpRsp, err := c.httpClient.Do(httpReq)
335	if err != nil {
336		return nil, err
337	}
338	defer httpRsp.Body.Close()
339
340	if httpRsp.StatusCode != http.StatusOK {
341		return nil, fmt.Errorf(httpRsp.Status)
342	}
343
344	buf, err := ioutil.ReadAll(httpRsp.Body)
345	if err != nil {
346		return nil, err
347	}
348
349	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
350	rsp := &computepb.Operation{}
351
352	if err := unm.Unmarshal(buf, rsp); err != nil {
353		return nil, err
354	}
355	op := &Operation{proto: rsp}
356	return op, err
357}
358
359// Get returns the specified UrlMap resource. Gets a list of available URL maps by making a list() request.
360func (c *urlMapsRESTClient) Get(ctx context.Context, req *computepb.GetUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMap, error) {
361	baseUrl, _ := url.Parse(c.endpoint)
362	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap())
363
364	httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
365	if err != nil {
366		return nil, err
367	}
368	httpReq = httpReq.WithContext(ctx)
369	// Set the headers
370	for k, v := range c.xGoogMetadata {
371		httpReq.Header[k] = v
372	}
373	httpReq.Header["Content-Type"] = []string{"application/json"}
374
375	httpRsp, err := c.httpClient.Do(httpReq)
376	if err != nil {
377		return nil, err
378	}
379	defer httpRsp.Body.Close()
380
381	if httpRsp.StatusCode != http.StatusOK {
382		return nil, fmt.Errorf(httpRsp.Status)
383	}
384
385	buf, err := ioutil.ReadAll(httpRsp.Body)
386	if err != nil {
387		return nil, err
388	}
389
390	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
391	rsp := &computepb.UrlMap{}
392
393	return rsp, unm.Unmarshal(buf, rsp)
394}
395
396// Insert creates a UrlMap resource in the specified project using the data included in the request.
397func (c *urlMapsRESTClient) Insert(ctx context.Context, req *computepb.InsertUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
398	m := protojson.MarshalOptions{AllowPartial: true}
399	body := req.GetUrlMapResource()
400	jsonReq, err := m.Marshal(body)
401	if err != nil {
402		return nil, err
403	}
404
405	baseUrl, _ := url.Parse(c.endpoint)
406	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps", req.GetProject())
407
408	params := url.Values{}
409	if req != nil && req.RequestId != nil {
410		params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
411	}
412
413	baseUrl.RawQuery = params.Encode()
414
415	httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
416	if err != nil {
417		return nil, err
418	}
419	httpReq = httpReq.WithContext(ctx)
420	// Set the headers
421	for k, v := range c.xGoogMetadata {
422		httpReq.Header[k] = v
423	}
424	httpReq.Header["Content-Type"] = []string{"application/json"}
425
426	httpRsp, err := c.httpClient.Do(httpReq)
427	if err != nil {
428		return nil, err
429	}
430	defer httpRsp.Body.Close()
431
432	if httpRsp.StatusCode != http.StatusOK {
433		return nil, fmt.Errorf(httpRsp.Status)
434	}
435
436	buf, err := ioutil.ReadAll(httpRsp.Body)
437	if err != nil {
438		return nil, err
439	}
440
441	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
442	rsp := &computepb.Operation{}
443
444	if err := unm.Unmarshal(buf, rsp); err != nil {
445		return nil, err
446	}
447	op := &Operation{proto: rsp}
448	return op, err
449}
450
451// InvalidateCache initiates a cache invalidation operation, invalidating the specified path, scoped to the specified UrlMap.
452//
453// For more information, see Invalidating cached content (at /cdn/docs/invalidating-cached-content).
454func (c *urlMapsRESTClient) InvalidateCache(ctx context.Context, req *computepb.InvalidateCacheUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
455	m := protojson.MarshalOptions{AllowPartial: true}
456	body := req.GetCacheInvalidationRuleResource()
457	jsonReq, err := m.Marshal(body)
458	if err != nil {
459		return nil, err
460	}
461
462	baseUrl, _ := url.Parse(c.endpoint)
463	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v/invalidateCache", req.GetProject(), req.GetUrlMap())
464
465	params := url.Values{}
466	if req != nil && req.RequestId != nil {
467		params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
468	}
469
470	baseUrl.RawQuery = params.Encode()
471
472	httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
473	if err != nil {
474		return nil, err
475	}
476	httpReq = httpReq.WithContext(ctx)
477	// Set the headers
478	for k, v := range c.xGoogMetadata {
479		httpReq.Header[k] = v
480	}
481	httpReq.Header["Content-Type"] = []string{"application/json"}
482
483	httpRsp, err := c.httpClient.Do(httpReq)
484	if err != nil {
485		return nil, err
486	}
487	defer httpRsp.Body.Close()
488
489	if httpRsp.StatusCode != http.StatusOK {
490		return nil, fmt.Errorf(httpRsp.Status)
491	}
492
493	buf, err := ioutil.ReadAll(httpRsp.Body)
494	if err != nil {
495		return nil, err
496	}
497
498	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
499	rsp := &computepb.Operation{}
500
501	if err := unm.Unmarshal(buf, rsp); err != nil {
502		return nil, err
503	}
504	op := &Operation{proto: rsp}
505	return op, err
506}
507
508// List retrieves the list of UrlMap resources available to the specified project.
509func (c *urlMapsRESTClient) List(ctx context.Context, req *computepb.ListUrlMapsRequest, opts ...gax.CallOption) *UrlMapIterator {
510	it := &UrlMapIterator{}
511	req = proto.Clone(req).(*computepb.ListUrlMapsRequest)
512	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
513	it.InternalFetch = func(pageSize int, pageToken string) ([]*computepb.UrlMap, string, error) {
514		resp := &computepb.UrlMapList{}
515		if pageToken != "" {
516			req.PageToken = proto.String(pageToken)
517		}
518		if pageSize > math.MaxInt32 {
519			req.MaxResults = proto.Uint32(math.MaxInt32)
520		} else if pageSize != 0 {
521			req.MaxResults = proto.Uint32(uint32(pageSize))
522		}
523		baseUrl, _ := url.Parse(c.endpoint)
524		baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps", req.GetProject())
525
526		params := url.Values{}
527		if req != nil && req.Filter != nil {
528			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
529		}
530		if req != nil && req.MaxResults != nil {
531			params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults()))
532		}
533		if req != nil && req.OrderBy != nil {
534			params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
535		}
536		if req != nil && req.PageToken != nil {
537			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
538		}
539		if req != nil && req.ReturnPartialSuccess != nil {
540			params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
541		}
542
543		baseUrl.RawQuery = params.Encode()
544
545		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
546		if err != nil {
547			return nil, "", err
548		}
549
550		// Set the headers
551		for k, v := range c.xGoogMetadata {
552			httpReq.Header[k] = v
553		}
554
555		httpReq.Header["Content-Type"] = []string{"application/json"}
556		httpRsp, err := c.httpClient.Do(httpReq)
557		if err != nil {
558			return nil, "", err
559		}
560		defer httpRsp.Body.Close()
561
562		if httpRsp.StatusCode != http.StatusOK {
563			return nil, "", fmt.Errorf(httpRsp.Status)
564		}
565
566		buf, err := ioutil.ReadAll(httpRsp.Body)
567		if err != nil {
568			return nil, "", err
569		}
570
571		unm.Unmarshal(buf, resp)
572		it.Response = resp
573		return resp.GetItems(), resp.GetNextPageToken(), nil
574	}
575
576	fetch := func(pageSize int, pageToken string) (string, error) {
577		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
578		if err != nil {
579			return "", err
580		}
581		it.items = append(it.items, items...)
582		return nextPageToken, nil
583	}
584
585	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
586	it.pageInfo.MaxSize = int(req.GetMaxResults())
587	it.pageInfo.Token = req.GetPageToken()
588
589	return it
590}
591
592// Patch patches the specified UrlMap resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
593func (c *urlMapsRESTClient) Patch(ctx context.Context, req *computepb.PatchUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
594	m := protojson.MarshalOptions{AllowPartial: true}
595	body := req.GetUrlMapResource()
596	jsonReq, err := m.Marshal(body)
597	if err != nil {
598		return nil, err
599	}
600
601	baseUrl, _ := url.Parse(c.endpoint)
602	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap())
603
604	params := url.Values{}
605	if req != nil && req.RequestId != nil {
606		params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
607	}
608
609	baseUrl.RawQuery = params.Encode()
610
611	httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
612	if err != nil {
613		return nil, err
614	}
615	httpReq = httpReq.WithContext(ctx)
616	// Set the headers
617	for k, v := range c.xGoogMetadata {
618		httpReq.Header[k] = v
619	}
620	httpReq.Header["Content-Type"] = []string{"application/json"}
621
622	httpRsp, err := c.httpClient.Do(httpReq)
623	if err != nil {
624		return nil, err
625	}
626	defer httpRsp.Body.Close()
627
628	if httpRsp.StatusCode != http.StatusOK {
629		return nil, fmt.Errorf(httpRsp.Status)
630	}
631
632	buf, err := ioutil.ReadAll(httpRsp.Body)
633	if err != nil {
634		return nil, err
635	}
636
637	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
638	rsp := &computepb.Operation{}
639
640	if err := unm.Unmarshal(buf, rsp); err != nil {
641		return nil, err
642	}
643	op := &Operation{proto: rsp}
644	return op, err
645}
646
647// Update updates the specified UrlMap resource with the data included in the request.
648func (c *urlMapsRESTClient) Update(ctx context.Context, req *computepb.UpdateUrlMapRequest, opts ...gax.CallOption) (*Operation, error) {
649	m := protojson.MarshalOptions{AllowPartial: true}
650	body := req.GetUrlMapResource()
651	jsonReq, err := m.Marshal(body)
652	if err != nil {
653		return nil, err
654	}
655
656	baseUrl, _ := url.Parse(c.endpoint)
657	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap())
658
659	params := url.Values{}
660	if req != nil && req.RequestId != nil {
661		params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
662	}
663
664	baseUrl.RawQuery = params.Encode()
665
666	httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
667	if err != nil {
668		return nil, err
669	}
670	httpReq = httpReq.WithContext(ctx)
671	// Set the headers
672	for k, v := range c.xGoogMetadata {
673		httpReq.Header[k] = v
674	}
675	httpReq.Header["Content-Type"] = []string{"application/json"}
676
677	httpRsp, err := c.httpClient.Do(httpReq)
678	if err != nil {
679		return nil, err
680	}
681	defer httpRsp.Body.Close()
682
683	if httpRsp.StatusCode != http.StatusOK {
684		return nil, fmt.Errorf(httpRsp.Status)
685	}
686
687	buf, err := ioutil.ReadAll(httpRsp.Body)
688	if err != nil {
689		return nil, err
690	}
691
692	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
693	rsp := &computepb.Operation{}
694
695	if err := unm.Unmarshal(buf, rsp); err != nil {
696		return nil, err
697	}
698	op := &Operation{proto: rsp}
699	return op, err
700}
701
702// Validate runs static validation for the UrlMap. In particular, the tests of the provided UrlMap will be run. Calling this method does NOT create the UrlMap.
703func (c *urlMapsRESTClient) Validate(ctx context.Context, req *computepb.ValidateUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) {
704	m := protojson.MarshalOptions{AllowPartial: true}
705	body := req.GetUrlMapsValidateRequestResource()
706	jsonReq, err := m.Marshal(body)
707	if err != nil {
708		return nil, err
709	}
710
711	baseUrl, _ := url.Parse(c.endpoint)
712	baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v/validate", req.GetProject(), req.GetUrlMap())
713
714	httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
715	if err != nil {
716		return nil, err
717	}
718	httpReq = httpReq.WithContext(ctx)
719	// Set the headers
720	for k, v := range c.xGoogMetadata {
721		httpReq.Header[k] = v
722	}
723	httpReq.Header["Content-Type"] = []string{"application/json"}
724
725	httpRsp, err := c.httpClient.Do(httpReq)
726	if err != nil {
727		return nil, err
728	}
729	defer httpRsp.Body.Close()
730
731	if httpRsp.StatusCode != http.StatusOK {
732		return nil, fmt.Errorf(httpRsp.Status)
733	}
734
735	buf, err := ioutil.ReadAll(httpRsp.Body)
736	if err != nil {
737		return nil, err
738	}
739
740	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
741	rsp := &computepb.UrlMapsValidateResponse{}
742
743	return rsp, unm.Unmarshal(buf, rsp)
744}
745
746// UrlMapsScopedListPair is a holder type for string/*computepb.UrlMapsScopedList map entries
747type UrlMapsScopedListPair struct {
748	Key   string
749	Value *computepb.UrlMapsScopedList
750}
751
752// UrlMapsScopedListPairIterator manages a stream of UrlMapsScopedListPair.
753type UrlMapsScopedListPairIterator struct {
754	items    []UrlMapsScopedListPair
755	pageInfo *iterator.PageInfo
756	nextFunc func() error
757
758	// Response is the raw response for the current page.
759	// It must be cast to the RPC response type.
760	// Calling Next() or InternalFetch() updates this value.
761	Response interface{}
762
763	// InternalFetch is for use by the Google Cloud Libraries only.
764	// It is not part of the stable interface of this package.
765	//
766	// InternalFetch returns results from a single call to the underlying RPC.
767	// The number of results is no greater than pageSize.
768	// If there are no more results, nextPageToken is empty and err is nil.
769	InternalFetch func(pageSize int, pageToken string) (results []UrlMapsScopedListPair, nextPageToken string, err error)
770}
771
772// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
773func (it *UrlMapsScopedListPairIterator) PageInfo() *iterator.PageInfo {
774	return it.pageInfo
775}
776
777// Next returns the next result. Its second return value is iterator.Done if there are no more
778// results. Once Next returns Done, all subsequent calls will return Done.
779func (it *UrlMapsScopedListPairIterator) Next() (UrlMapsScopedListPair, error) {
780	var item UrlMapsScopedListPair
781	if err := it.nextFunc(); err != nil {
782		return item, err
783	}
784	item = it.items[0]
785	it.items = it.items[1:]
786	return item, nil
787}
788
789func (it *UrlMapsScopedListPairIterator) bufLen() int {
790	return len(it.items)
791}
792
793func (it *UrlMapsScopedListPairIterator) takeBuf() interface{} {
794	b := it.items
795	it.items = nil
796	return b
797}
798