blob: 9e548c468ca631f411085e6bf3d4cb4110ab0353 [file] [log] [blame]
Yoshi Automation Bot18092a02022-01-06 10:03:07 -08001// Copyright 2022 Google LLC
Cody Oss75e3d642021-07-01 14:46:06 -05002//
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"
Noah Dietz36f46492021-08-03 14:16:18 -070024 "math"
Cody Oss75e3d642021-07-01 14:46:06 -050025 "net/http"
26 "net/url"
27
28 gax "github.com/googleapis/gax-go/v2"
Yoshi Automation Bot799e6dc2021-08-20 07:18:20 -070029 "google.golang.org/api/googleapi"
Noah Dietz36f46492021-08-03 14:16:18 -070030 "google.golang.org/api/iterator"
Cody Oss75e3d642021-07-01 14:46:06 -050031 "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"
Noah Dietz36f46492021-08-03 14:16:18 -070038 "google.golang.org/protobuf/proto"
Cody Oss75e3d642021-07-01 14:46:06 -050039)
40
41var newFirewallPoliciesClientHook clientHook
42
43// FirewallPoliciesCallOptions contains the retry settings for each method of FirewallPoliciesClient.
44type FirewallPoliciesCallOptions struct {
45 AddAssociation []gax.CallOption
46 AddRule []gax.CallOption
47 CloneRules []gax.CallOption
48 Delete []gax.CallOption
49 Get []gax.CallOption
50 GetAssociation []gax.CallOption
51 GetIamPolicy []gax.CallOption
52 GetRule []gax.CallOption
53 Insert []gax.CallOption
54 List []gax.CallOption
55 ListAssociations []gax.CallOption
56 Move []gax.CallOption
57 Patch []gax.CallOption
58 PatchRule []gax.CallOption
59 RemoveAssociation []gax.CallOption
60 RemoveRule []gax.CallOption
61 SetIamPolicy []gax.CallOption
62 TestIamPermissions []gax.CallOption
63}
64
Yoshi Automation Bot5e460682022-06-16 07:27:39 -070065func defaultFirewallPoliciesRESTCallOptions() *FirewallPoliciesCallOptions {
66 return &FirewallPoliciesCallOptions{
67 AddAssociation: []gax.CallOption{},
68 AddRule: []gax.CallOption{},
69 CloneRules: []gax.CallOption{},
70 Delete: []gax.CallOption{},
71 Get: []gax.CallOption{},
72 GetAssociation: []gax.CallOption{},
73 GetIamPolicy: []gax.CallOption{},
74 GetRule: []gax.CallOption{},
75 Insert: []gax.CallOption{},
76 List: []gax.CallOption{},
77 ListAssociations: []gax.CallOption{},
78 Move: []gax.CallOption{},
79 Patch: []gax.CallOption{},
80 PatchRule: []gax.CallOption{},
81 RemoveAssociation: []gax.CallOption{},
82 RemoveRule: []gax.CallOption{},
83 SetIamPolicy: []gax.CallOption{},
84 TestIamPermissions: []gax.CallOption{},
85 }
86}
87
88// internalFirewallPoliciesClient is an interface that defines the methods available from Google Compute Engine API.
Cody Oss75e3d642021-07-01 14:46:06 -050089type internalFirewallPoliciesClient interface {
90 Close() error
91 setGoogleClientInfo(...string)
92 Connection() *grpc.ClientConn
Noah Dietz36f46492021-08-03 14:16:18 -070093 AddAssociation(context.Context, *computepb.AddAssociationFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
94 AddRule(context.Context, *computepb.AddRuleFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
95 CloneRules(context.Context, *computepb.CloneRulesFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
96 Delete(context.Context, *computepb.DeleteFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
Cody Oss75e3d642021-07-01 14:46:06 -050097 Get(context.Context, *computepb.GetFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPolicy, error)
98 GetAssociation(context.Context, *computepb.GetAssociationFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error)
99 GetIamPolicy(context.Context, *computepb.GetIamPolicyFirewallPolicyRequest, ...gax.CallOption) (*computepb.Policy, error)
100 GetRule(context.Context, *computepb.GetRuleFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPolicyRule, error)
Noah Dietz36f46492021-08-03 14:16:18 -0700101 Insert(context.Context, *computepb.InsertFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
102 List(context.Context, *computepb.ListFirewallPoliciesRequest, ...gax.CallOption) *FirewallPolicyIterator
Cody Oss75e3d642021-07-01 14:46:06 -0500103 ListAssociations(context.Context, *computepb.ListAssociationsFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error)
Noah Dietz36f46492021-08-03 14:16:18 -0700104 Move(context.Context, *computepb.MoveFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
105 Patch(context.Context, *computepb.PatchFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
106 PatchRule(context.Context, *computepb.PatchRuleFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
107 RemoveAssociation(context.Context, *computepb.RemoveAssociationFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
108 RemoveRule(context.Context, *computepb.RemoveRuleFirewallPolicyRequest, ...gax.CallOption) (*Operation, error)
Cody Oss75e3d642021-07-01 14:46:06 -0500109 SetIamPolicy(context.Context, *computepb.SetIamPolicyFirewallPolicyRequest, ...gax.CallOption) (*computepb.Policy, error)
110 TestIamPermissions(context.Context, *computepb.TestIamPermissionsFirewallPolicyRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error)
111}
112
113// FirewallPoliciesClient is a client for interacting with Google Compute Engine API.
114// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
115//
116// The FirewallPolicies API.
117type FirewallPoliciesClient struct {
118 // The internal transport-dependent client.
119 internalClient internalFirewallPoliciesClient
120
121 // The call options for this service.
122 CallOptions *FirewallPoliciesCallOptions
123}
124
125// Wrapper methods routed to the internal client.
126
127// Close closes the connection to the API service. The user should invoke this when
128// the client is no longer required.
129func (c *FirewallPoliciesClient) Close() error {
130 return c.internalClient.Close()
131}
132
133// setGoogleClientInfo sets the name and version of the application in
134// the `x-goog-api-client` header passed on each request. Intended for
135// use by Google-written clients.
136func (c *FirewallPoliciesClient) setGoogleClientInfo(keyval ...string) {
137 c.internalClient.setGoogleClientInfo(keyval...)
138}
139
140// Connection returns a connection to the API service.
141//
142// Deprecated.
143func (c *FirewallPoliciesClient) Connection() *grpc.ClientConn {
144 return c.internalClient.Connection()
145}
146
147// AddAssociation inserts an association for the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700148func (c *FirewallPoliciesClient) AddAssociation(ctx context.Context, req *computepb.AddAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500149 return c.internalClient.AddAssociation(ctx, req, opts...)
150}
151
152// AddRule inserts a rule into a firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700153func (c *FirewallPoliciesClient) AddRule(ctx context.Context, req *computepb.AddRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500154 return c.internalClient.AddRule(ctx, req, opts...)
155}
156
157// CloneRules copies rules to the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700158func (c *FirewallPoliciesClient) CloneRules(ctx context.Context, req *computepb.CloneRulesFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500159 return c.internalClient.CloneRules(ctx, req, opts...)
160}
161
162// Delete deletes the specified policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700163func (c *FirewallPoliciesClient) Delete(ctx context.Context, req *computepb.DeleteFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500164 return c.internalClient.Delete(ctx, req, opts...)
165}
166
167// Get returns the specified firewall policy.
168func (c *FirewallPoliciesClient) Get(ctx context.Context, req *computepb.GetFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicy, error) {
169 return c.internalClient.Get(ctx, req, opts...)
170}
171
172// GetAssociation gets an association with the specified name.
173func (c *FirewallPoliciesClient) GetAssociation(ctx context.Context, req *computepb.GetAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error) {
174 return c.internalClient.GetAssociation(ctx, req, opts...)
175}
176
177// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists.
178func (c *FirewallPoliciesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
179 return c.internalClient.GetIamPolicy(ctx, req, opts...)
180}
181
182// GetRule gets a rule of the specified priority.
183func (c *FirewallPoliciesClient) GetRule(ctx context.Context, req *computepb.GetRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyRule, error) {
184 return c.internalClient.GetRule(ctx, req, opts...)
185}
186
187// Insert creates a new policy in the specified project using the data included in the request.
Noah Dietz36f46492021-08-03 14:16:18 -0700188func (c *FirewallPoliciesClient) Insert(ctx context.Context, req *computepb.InsertFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500189 return c.internalClient.Insert(ctx, req, opts...)
190}
191
Yoshi Automation Bot83b941c2021-11-04 14:52:20 -0700192// List lists all the policies that have been configured for the specified folder or organization.
Noah Dietz36f46492021-08-03 14:16:18 -0700193func (c *FirewallPoliciesClient) List(ctx context.Context, req *computepb.ListFirewallPoliciesRequest, opts ...gax.CallOption) *FirewallPolicyIterator {
Cody Oss75e3d642021-07-01 14:46:06 -0500194 return c.internalClient.List(ctx, req, opts...)
195}
196
197// ListAssociations lists associations of a specified target, i.e., organization or folder.
198func (c *FirewallPoliciesClient) ListAssociations(ctx context.Context, req *computepb.ListAssociationsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) {
199 return c.internalClient.ListAssociations(ctx, req, opts...)
200}
201
202// Move moves the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700203func (c *FirewallPoliciesClient) Move(ctx context.Context, req *computepb.MoveFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500204 return c.internalClient.Move(ctx, req, opts...)
205}
206
207// Patch patches the specified policy with the data included in the request.
Noah Dietz36f46492021-08-03 14:16:18 -0700208func (c *FirewallPoliciesClient) Patch(ctx context.Context, req *computepb.PatchFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500209 return c.internalClient.Patch(ctx, req, opts...)
210}
211
212// PatchRule patches a rule of the specified priority.
Noah Dietz36f46492021-08-03 14:16:18 -0700213func (c *FirewallPoliciesClient) PatchRule(ctx context.Context, req *computepb.PatchRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500214 return c.internalClient.PatchRule(ctx, req, opts...)
215}
216
217// RemoveAssociation removes an association for the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700218func (c *FirewallPoliciesClient) RemoveAssociation(ctx context.Context, req *computepb.RemoveAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500219 return c.internalClient.RemoveAssociation(ctx, req, opts...)
220}
221
222// RemoveRule deletes a rule of the specified priority.
Noah Dietz36f46492021-08-03 14:16:18 -0700223func (c *FirewallPoliciesClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Cody Oss75e3d642021-07-01 14:46:06 -0500224 return c.internalClient.RemoveRule(ctx, req, opts...)
225}
226
227// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
228func (c *FirewallPoliciesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
229 return c.internalClient.SetIamPolicy(ctx, req, opts...)
230}
231
232// TestIamPermissions returns permissions that a caller has on the specified resource.
233func (c *FirewallPoliciesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) {
234 return c.internalClient.TestIamPermissions(ctx, req, opts...)
235}
236
237// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
238type firewallPoliciesRESTClient struct {
239 // The http endpoint to connect to.
240 endpoint string
241
242 // The http client.
243 httpClient *http.Client
244
Cody Oss95d36092022-02-02 16:22:27 -0700245 // operationClient is used to call the operation-specific management service.
246 operationClient *GlobalOrganizationOperationsClient
247
Cody Oss75e3d642021-07-01 14:46:06 -0500248 // The x-goog-* metadata to be sent with each request.
249 xGoogMetadata metadata.MD
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700250
251 // Points back to the CallOptions field of the containing FirewallPoliciesClient
252 CallOptions **FirewallPoliciesCallOptions
Cody Oss75e3d642021-07-01 14:46:06 -0500253}
254
255// NewFirewallPoliciesRESTClient creates a new firewall policies rest client.
256//
257// The FirewallPolicies API.
258func NewFirewallPoliciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*FirewallPoliciesClient, error) {
259 clientOpts := append(defaultFirewallPoliciesRESTClientOptions(), opts...)
260 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
261 if err != nil {
262 return nil, err
263 }
264
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700265 callOpts := defaultFirewallPoliciesRESTCallOptions()
Cody Oss75e3d642021-07-01 14:46:06 -0500266 c := &firewallPoliciesRESTClient{
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700267 endpoint: endpoint,
268 httpClient: httpClient,
269 CallOptions: &callOpts,
Cody Oss75e3d642021-07-01 14:46:06 -0500270 }
271 c.setGoogleClientInfo()
272
Cody Oss95d36092022-02-02 16:22:27 -0700273 o := []option.ClientOption{
274 option.WithHTTPClient(httpClient),
275 option.WithEndpoint(endpoint),
276 }
277 opC, err := NewGlobalOrganizationOperationsRESTClient(ctx, o...)
278 if err != nil {
279 return nil, err
280 }
281 c.operationClient = opC
282
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700283 return &FirewallPoliciesClient{internalClient: c, CallOptions: callOpts}, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500284}
285
286func defaultFirewallPoliciesRESTClientOptions() []option.ClientOption {
287 return []option.ClientOption{
Yoshi Automation Bot32d68ec2021-07-07 11:42:48 -0700288 internaloption.WithDefaultEndpoint("https://compute.googleapis.com"),
289 internaloption.WithDefaultMTLSEndpoint("https://compute.mtls.googleapis.com"),
Cody Oss75e3d642021-07-01 14:46:06 -0500290 internaloption.WithDefaultAudience("https://compute.googleapis.com/"),
291 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
292 }
293}
294
295// setGoogleClientInfo sets the name and version of the application in
296// the `x-goog-api-client` header passed on each request. Intended for
297// use by Google-written clients.
298func (c *firewallPoliciesRESTClient) setGoogleClientInfo(keyval ...string) {
299 kv := append([]string{"gl-go", versionGo()}, keyval...)
Cody Oss55f0d922022-02-23 16:15:58 -0700300 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
Cody Oss75e3d642021-07-01 14:46:06 -0500301 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
302}
303
304// Close closes the connection to the API service. The user should invoke this when
305// the client is no longer required.
306func (c *firewallPoliciesRESTClient) Close() error {
307 // Replace httpClient with nil to force cleanup.
308 c.httpClient = nil
Cody Oss95d36092022-02-02 16:22:27 -0700309 if err := c.operationClient.Close(); err != nil {
310 return err
311 }
Cody Oss75e3d642021-07-01 14:46:06 -0500312 return nil
313}
314
315// Connection returns a connection to the API service.
316//
317// Deprecated.
318func (c *firewallPoliciesRESTClient) Connection() *grpc.ClientConn {
319 return nil
320}
321
322// AddAssociation inserts an association for the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700323func (c *firewallPoliciesRESTClient) AddAssociation(ctx context.Context, req *computepb.AddAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -0700324 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -0500325 body := req.GetFirewallPolicyAssociationResource()
326 jsonReq, err := m.Marshal(body)
327 if err != nil {
328 return nil, err
329 }
330
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700331 baseUrl, err := url.Parse(c.endpoint)
332 if err != nil {
333 return nil, err
334 }
Cody Oss75e3d642021-07-01 14:46:06 -0500335 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/addAssociation", req.GetFirewallPolicy())
336
337 params := url.Values{}
338 if req != nil && req.ReplaceExistingAssociation != nil {
339 params.Add("replaceExistingAssociation", fmt.Sprintf("%v", req.GetReplaceExistingAssociation()))
340 }
341 if req != nil && req.RequestId != nil {
342 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
343 }
344
345 baseUrl.RawQuery = params.Encode()
346
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800347 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700348 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
349
350 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700351 opts = append((*c.CallOptions).AddAssociation[0:len((*c.CallOptions).AddAssociation):len((*c.CallOptions).AddAssociation)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500352 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800353 resp := &computepb.Operation{}
354 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700355 if settings.Path != "" {
356 baseUrl.Path = settings.Path
357 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800358 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
359 if err != nil {
360 return err
361 }
362 httpReq = httpReq.WithContext(ctx)
363 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500364
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800365 httpRsp, err := c.httpClient.Do(httpReq)
366 if err != nil {
367 return err
368 }
369 defer httpRsp.Body.Close()
370
371 if err = googleapi.CheckResponse(httpRsp); err != nil {
372 return err
373 }
374
375 buf, err := ioutil.ReadAll(httpRsp.Body)
376 if err != nil {
377 return err
378 }
379
380 if err := unm.Unmarshal(buf, resp); err != nil {
381 return maybeUnknownEnum(err)
382 }
383
384 return nil
385 }, opts...)
386 if e != nil {
387 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -0700388 }
Cody Oss95d36092022-02-02 16:22:27 -0700389 op := &Operation{
390 &globalOrganizationOperationsHandle{
391 c: c.operationClient,
392 proto: resp,
393 },
394 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800395 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500396}
397
398// AddRule inserts a rule into a firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700399func (c *firewallPoliciesRESTClient) AddRule(ctx context.Context, req *computepb.AddRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -0700400 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -0500401 body := req.GetFirewallPolicyRuleResource()
402 jsonReq, err := m.Marshal(body)
403 if err != nil {
404 return nil, err
405 }
406
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700407 baseUrl, err := url.Parse(c.endpoint)
408 if err != nil {
409 return nil, err
410 }
Cody Oss75e3d642021-07-01 14:46:06 -0500411 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/addRule", req.GetFirewallPolicy())
412
413 params := url.Values{}
414 if req != nil && req.RequestId != nil {
415 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
416 }
417
418 baseUrl.RawQuery = params.Encode()
419
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800420 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700421 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
422
423 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700424 opts = append((*c.CallOptions).AddRule[0:len((*c.CallOptions).AddRule):len((*c.CallOptions).AddRule)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500425 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800426 resp := &computepb.Operation{}
427 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700428 if settings.Path != "" {
429 baseUrl.Path = settings.Path
430 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800431 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
432 if err != nil {
433 return err
434 }
435 httpReq = httpReq.WithContext(ctx)
436 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500437
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800438 httpRsp, err := c.httpClient.Do(httpReq)
439 if err != nil {
440 return err
441 }
442 defer httpRsp.Body.Close()
443
444 if err = googleapi.CheckResponse(httpRsp); err != nil {
445 return err
446 }
447
448 buf, err := ioutil.ReadAll(httpRsp.Body)
449 if err != nil {
450 return err
451 }
452
453 if err := unm.Unmarshal(buf, resp); err != nil {
454 return maybeUnknownEnum(err)
455 }
456
457 return nil
458 }, opts...)
459 if e != nil {
460 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -0700461 }
Cody Oss95d36092022-02-02 16:22:27 -0700462 op := &Operation{
463 &globalOrganizationOperationsHandle{
464 c: c.operationClient,
465 proto: resp,
466 },
467 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800468 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500469}
470
471// CloneRules copies rules to the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700472func (c *firewallPoliciesRESTClient) CloneRules(ctx context.Context, req *computepb.CloneRulesFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700473 baseUrl, err := url.Parse(c.endpoint)
474 if err != nil {
475 return nil, err
476 }
Cody Oss75e3d642021-07-01 14:46:06 -0500477 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/cloneRules", req.GetFirewallPolicy())
478
479 params := url.Values{}
480 if req != nil && req.RequestId != nil {
481 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
482 }
483 if req != nil && req.SourceFirewallPolicy != nil {
484 params.Add("sourceFirewallPolicy", fmt.Sprintf("%v", req.GetSourceFirewallPolicy()))
485 }
486
487 baseUrl.RawQuery = params.Encode()
488
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800489 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700490 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
491
492 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700493 opts = append((*c.CallOptions).CloneRules[0:len((*c.CallOptions).CloneRules):len((*c.CallOptions).CloneRules)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500494 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800495 resp := &computepb.Operation{}
496 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700497 if settings.Path != "" {
498 baseUrl.Path = settings.Path
499 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800500 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
501 if err != nil {
502 return err
503 }
504 httpReq = httpReq.WithContext(ctx)
505 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500506
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800507 httpRsp, err := c.httpClient.Do(httpReq)
508 if err != nil {
509 return err
510 }
511 defer httpRsp.Body.Close()
512
513 if err = googleapi.CheckResponse(httpRsp); err != nil {
514 return err
515 }
516
517 buf, err := ioutil.ReadAll(httpRsp.Body)
518 if err != nil {
519 return err
520 }
521
522 if err := unm.Unmarshal(buf, resp); err != nil {
523 return maybeUnknownEnum(err)
524 }
525
526 return nil
527 }, opts...)
528 if e != nil {
529 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -0700530 }
Cody Oss95d36092022-02-02 16:22:27 -0700531 op := &Operation{
532 &globalOrganizationOperationsHandle{
533 c: c.operationClient,
534 proto: resp,
535 },
536 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800537 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500538}
539
540// Delete deletes the specified policy.
Noah Dietz36f46492021-08-03 14:16:18 -0700541func (c *firewallPoliciesRESTClient) Delete(ctx context.Context, req *computepb.DeleteFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700542 baseUrl, err := url.Parse(c.endpoint)
543 if err != nil {
544 return nil, err
545 }
Cody Oss75e3d642021-07-01 14:46:06 -0500546 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy())
547
548 params := url.Values{}
549 if req != nil && req.RequestId != nil {
550 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
551 }
552
553 baseUrl.RawQuery = params.Encode()
554
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800555 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700556 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
557
558 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700559 opts = append((*c.CallOptions).Delete[0:len((*c.CallOptions).Delete):len((*c.CallOptions).Delete)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500560 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800561 resp := &computepb.Operation{}
562 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700563 if settings.Path != "" {
564 baseUrl.Path = settings.Path
565 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800566 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
567 if err != nil {
568 return err
569 }
570 httpReq = httpReq.WithContext(ctx)
571 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500572
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800573 httpRsp, err := c.httpClient.Do(httpReq)
574 if err != nil {
575 return err
576 }
577 defer httpRsp.Body.Close()
578
579 if err = googleapi.CheckResponse(httpRsp); err != nil {
580 return err
581 }
582
583 buf, err := ioutil.ReadAll(httpRsp.Body)
584 if err != nil {
585 return err
586 }
587
588 if err := unm.Unmarshal(buf, resp); err != nil {
589 return maybeUnknownEnum(err)
590 }
591
592 return nil
593 }, opts...)
594 if e != nil {
595 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -0700596 }
Cody Oss95d36092022-02-02 16:22:27 -0700597 op := &Operation{
598 &globalOrganizationOperationsHandle{
599 c: c.operationClient,
600 proto: resp,
601 },
602 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800603 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500604}
605
606// Get returns the specified firewall policy.
607func (c *firewallPoliciesRESTClient) Get(ctx context.Context, req *computepb.GetFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicy, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700608 baseUrl, err := url.Parse(c.endpoint)
609 if err != nil {
610 return nil, err
611 }
Cody Oss75e3d642021-07-01 14:46:06 -0500612 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy())
613
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800614 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700615 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
616
617 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700618 opts = append((*c.CallOptions).Get[0:len((*c.CallOptions).Get):len((*c.CallOptions).Get)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500619 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800620 resp := &computepb.FirewallPolicy{}
621 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700622 if settings.Path != "" {
623 baseUrl.Path = settings.Path
624 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800625 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
626 if err != nil {
627 return err
628 }
629 httpReq = httpReq.WithContext(ctx)
630 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500631
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800632 httpRsp, err := c.httpClient.Do(httpReq)
633 if err != nil {
634 return err
635 }
636 defer httpRsp.Body.Close()
637
638 if err = googleapi.CheckResponse(httpRsp); err != nil {
639 return err
640 }
641
642 buf, err := ioutil.ReadAll(httpRsp.Body)
643 if err != nil {
644 return err
645 }
646
647 if err := unm.Unmarshal(buf, resp); err != nil {
648 return maybeUnknownEnum(err)
649 }
650
651 return nil
652 }, opts...)
653 if e != nil {
654 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -0700655 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800656 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500657}
658
659// GetAssociation gets an association with the specified name.
660func (c *firewallPoliciesRESTClient) GetAssociation(ctx context.Context, req *computepb.GetAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700661 baseUrl, err := url.Parse(c.endpoint)
662 if err != nil {
663 return nil, err
664 }
Cody Oss75e3d642021-07-01 14:46:06 -0500665 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/getAssociation", req.GetFirewallPolicy())
666
667 params := url.Values{}
668 if req != nil && req.Name != nil {
669 params.Add("name", fmt.Sprintf("%v", req.GetName()))
670 }
671
672 baseUrl.RawQuery = params.Encode()
673
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800674 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700675 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
676
677 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700678 opts = append((*c.CallOptions).GetAssociation[0:len((*c.CallOptions).GetAssociation):len((*c.CallOptions).GetAssociation)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500679 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800680 resp := &computepb.FirewallPolicyAssociation{}
681 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700682 if settings.Path != "" {
683 baseUrl.Path = settings.Path
684 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800685 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
686 if err != nil {
687 return err
688 }
689 httpReq = httpReq.WithContext(ctx)
690 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500691
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800692 httpRsp, err := c.httpClient.Do(httpReq)
693 if err != nil {
694 return err
695 }
696 defer httpRsp.Body.Close()
697
698 if err = googleapi.CheckResponse(httpRsp); err != nil {
699 return err
700 }
701
702 buf, err := ioutil.ReadAll(httpRsp.Body)
703 if err != nil {
704 return err
705 }
706
707 if err := unm.Unmarshal(buf, resp); err != nil {
708 return maybeUnknownEnum(err)
709 }
710
711 return nil
712 }, opts...)
713 if e != nil {
714 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -0700715 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800716 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500717}
718
719// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists.
720func (c *firewallPoliciesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700721 baseUrl, err := url.Parse(c.endpoint)
722 if err != nil {
723 return nil, err
724 }
Cody Oss75e3d642021-07-01 14:46:06 -0500725 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/getIamPolicy", req.GetResource())
726
727 params := url.Values{}
728 if req != nil && req.OptionsRequestedPolicyVersion != nil {
729 params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion()))
730 }
731
732 baseUrl.RawQuery = params.Encode()
733
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800734 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700735 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
736
737 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700738 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500739 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800740 resp := &computepb.Policy{}
741 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700742 if settings.Path != "" {
743 baseUrl.Path = settings.Path
744 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800745 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
746 if err != nil {
747 return err
748 }
749 httpReq = httpReq.WithContext(ctx)
750 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500751
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800752 httpRsp, err := c.httpClient.Do(httpReq)
753 if err != nil {
754 return err
755 }
756 defer httpRsp.Body.Close()
757
758 if err = googleapi.CheckResponse(httpRsp); err != nil {
759 return err
760 }
761
762 buf, err := ioutil.ReadAll(httpRsp.Body)
763 if err != nil {
764 return err
765 }
766
767 if err := unm.Unmarshal(buf, resp); err != nil {
768 return maybeUnknownEnum(err)
769 }
770
771 return nil
772 }, opts...)
773 if e != nil {
774 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -0700775 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800776 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500777}
778
779// GetRule gets a rule of the specified priority.
780func (c *firewallPoliciesRESTClient) GetRule(ctx context.Context, req *computepb.GetRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyRule, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700781 baseUrl, err := url.Parse(c.endpoint)
782 if err != nil {
783 return nil, err
784 }
Cody Oss75e3d642021-07-01 14:46:06 -0500785 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/getRule", req.GetFirewallPolicy())
786
787 params := url.Values{}
788 if req != nil && req.Priority != nil {
789 params.Add("priority", fmt.Sprintf("%v", req.GetPriority()))
790 }
791
792 baseUrl.RawQuery = params.Encode()
793
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800794 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700795 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
796
797 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700798 opts = append((*c.CallOptions).GetRule[0:len((*c.CallOptions).GetRule):len((*c.CallOptions).GetRule)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500799 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800800 resp := &computepb.FirewallPolicyRule{}
801 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700802 if settings.Path != "" {
803 baseUrl.Path = settings.Path
804 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800805 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
806 if err != nil {
807 return err
808 }
809 httpReq = httpReq.WithContext(ctx)
810 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500811
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800812 httpRsp, err := c.httpClient.Do(httpReq)
813 if err != nil {
814 return err
815 }
816 defer httpRsp.Body.Close()
817
818 if err = googleapi.CheckResponse(httpRsp); err != nil {
819 return err
820 }
821
822 buf, err := ioutil.ReadAll(httpRsp.Body)
823 if err != nil {
824 return err
825 }
826
827 if err := unm.Unmarshal(buf, resp); err != nil {
828 return maybeUnknownEnum(err)
829 }
830
831 return nil
832 }, opts...)
833 if e != nil {
834 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -0700835 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800836 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500837}
838
839// Insert creates a new policy in the specified project using the data included in the request.
Noah Dietz36f46492021-08-03 14:16:18 -0700840func (c *firewallPoliciesRESTClient) Insert(ctx context.Context, req *computepb.InsertFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -0700841 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -0500842 body := req.GetFirewallPolicyResource()
843 jsonReq, err := m.Marshal(body)
844 if err != nil {
845 return nil, err
846 }
847
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700848 baseUrl, err := url.Parse(c.endpoint)
849 if err != nil {
850 return nil, err
851 }
Cody Oss75e3d642021-07-01 14:46:06 -0500852 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies")
853
854 params := url.Values{}
Yoshi Automation Bot19a9ef22022-04-14 10:21:44 -0700855 params.Add("parentId", fmt.Sprintf("%v", req.GetParentId()))
Cody Oss75e3d642021-07-01 14:46:06 -0500856 if req != nil && req.RequestId != nil {
857 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
858 }
859
860 baseUrl.RawQuery = params.Encode()
861
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800862 // Build HTTP headers from client and context metadata.
863 headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -0700864 opts = append((*c.CallOptions).Insert[0:len((*c.CallOptions).Insert):len((*c.CallOptions).Insert)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -0500865 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800866 resp := &computepb.Operation{}
867 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700868 if settings.Path != "" {
869 baseUrl.Path = settings.Path
870 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800871 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
872 if err != nil {
873 return err
874 }
875 httpReq = httpReq.WithContext(ctx)
876 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -0500877
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800878 httpRsp, err := c.httpClient.Do(httpReq)
879 if err != nil {
880 return err
881 }
882 defer httpRsp.Body.Close()
883
884 if err = googleapi.CheckResponse(httpRsp); err != nil {
885 return err
886 }
887
888 buf, err := ioutil.ReadAll(httpRsp.Body)
889 if err != nil {
890 return err
891 }
892
893 if err := unm.Unmarshal(buf, resp); err != nil {
894 return maybeUnknownEnum(err)
895 }
896
897 return nil
898 }, opts...)
899 if e != nil {
900 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -0700901 }
Cody Oss95d36092022-02-02 16:22:27 -0700902 op := &Operation{
903 &globalOrganizationOperationsHandle{
904 c: c.operationClient,
905 proto: resp,
906 },
907 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800908 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -0500909}
910
Yoshi Automation Bot83b941c2021-11-04 14:52:20 -0700911// List lists all the policies that have been configured for the specified folder or organization.
Noah Dietz36f46492021-08-03 14:16:18 -0700912func (c *firewallPoliciesRESTClient) List(ctx context.Context, req *computepb.ListFirewallPoliciesRequest, opts ...gax.CallOption) *FirewallPolicyIterator {
913 it := &FirewallPolicyIterator{}
914 req = proto.Clone(req).(*computepb.ListFirewallPoliciesRequest)
Cody Oss75e3d642021-07-01 14:46:06 -0500915 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Noah Dietz36f46492021-08-03 14:16:18 -0700916 it.InternalFetch = func(pageSize int, pageToken string) ([]*computepb.FirewallPolicy, string, error) {
917 resp := &computepb.FirewallPolicyList{}
918 if pageToken != "" {
919 req.PageToken = proto.String(pageToken)
920 }
921 if pageSize > math.MaxInt32 {
922 req.MaxResults = proto.Uint32(math.MaxInt32)
923 } else if pageSize != 0 {
924 req.MaxResults = proto.Uint32(uint32(pageSize))
925 }
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700926 baseUrl, err := url.Parse(c.endpoint)
927 if err != nil {
928 return nil, "", err
929 }
Noah Dietz36f46492021-08-03 14:16:18 -0700930 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies")
Cody Oss75e3d642021-07-01 14:46:06 -0500931
Noah Dietz36f46492021-08-03 14:16:18 -0700932 params := url.Values{}
933 if req != nil && req.Filter != nil {
934 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
935 }
936 if req != nil && req.MaxResults != nil {
937 params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults()))
938 }
939 if req != nil && req.OrderBy != nil {
940 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
941 }
942 if req != nil && req.PageToken != nil {
943 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
944 }
945 if req != nil && req.ParentId != nil {
946 params.Add("parentId", fmt.Sprintf("%v", req.GetParentId()))
947 }
948 if req != nil && req.ReturnPartialSuccess != nil {
949 params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
950 }
951
952 baseUrl.RawQuery = params.Encode()
953
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800954 // Build HTTP headers from client and context metadata.
955 headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json"))
956 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -0700957 if settings.Path != "" {
958 baseUrl.Path = settings.Path
959 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800960 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
961 if err != nil {
962 return err
963 }
964 httpReq.Header = headers
Noah Dietz36f46492021-08-03 14:16:18 -0700965
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800966 httpRsp, err := c.httpClient.Do(httpReq)
967 if err != nil {
968 return err
969 }
970 defer httpRsp.Body.Close()
Noah Dietz36f46492021-08-03 14:16:18 -0700971
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800972 if err = googleapi.CheckResponse(httpRsp); err != nil {
973 return err
974 }
Noah Dietz36f46492021-08-03 14:16:18 -0700975
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800976 buf, err := ioutil.ReadAll(httpRsp.Body)
977 if err != nil {
978 return err
979 }
Noah Dietz36f46492021-08-03 14:16:18 -0700980
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800981 if err := unm.Unmarshal(buf, resp); err != nil {
982 return maybeUnknownEnum(err)
983 }
Noah Dietz36f46492021-08-03 14:16:18 -0700984
Yoshi Automation Bot6e560772022-02-01 14:18:45 -0800985 return nil
986 }, opts...)
987 if e != nil {
988 return nil, "", e
989 }
Noah Dietz36f46492021-08-03 14:16:18 -0700990 it.Response = resp
991 return resp.GetItems(), resp.GetNextPageToken(), nil
992 }
993
994 fetch := func(pageSize int, pageToken string) (string, error) {
995 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
996 if err != nil {
997 return "", err
998 }
999 it.items = append(it.items, items...)
1000 return nextPageToken, nil
1001 }
1002
1003 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1004 it.pageInfo.MaxSize = int(req.GetMaxResults())
1005 it.pageInfo.Token = req.GetPageToken()
1006
1007 return it
Cody Oss75e3d642021-07-01 14:46:06 -05001008}
1009
1010// ListAssociations lists associations of a specified target, i.e., organization or folder.
1011func (c *firewallPoliciesRESTClient) ListAssociations(ctx context.Context, req *computepb.ListAssociationsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001012 baseUrl, err := url.Parse(c.endpoint)
1013 if err != nil {
1014 return nil, err
1015 }
Cody Oss75e3d642021-07-01 14:46:06 -05001016 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/listAssociations")
1017
1018 params := url.Values{}
1019 if req != nil && req.TargetResource != nil {
1020 params.Add("targetResource", fmt.Sprintf("%v", req.GetTargetResource()))
1021 }
1022
1023 baseUrl.RawQuery = params.Encode()
1024
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001025 // Build HTTP headers from client and context metadata.
1026 headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001027 opts = append((*c.CallOptions).ListAssociations[0:len((*c.CallOptions).ListAssociations):len((*c.CallOptions).ListAssociations)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001028 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001029 resp := &computepb.FirewallPoliciesListAssociationsResponse{}
1030 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001031 if settings.Path != "" {
1032 baseUrl.Path = settings.Path
1033 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001034 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1035 if err != nil {
1036 return err
1037 }
1038 httpReq = httpReq.WithContext(ctx)
1039 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001040
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001041 httpRsp, err := c.httpClient.Do(httpReq)
1042 if err != nil {
1043 return err
1044 }
1045 defer httpRsp.Body.Close()
1046
1047 if err = googleapi.CheckResponse(httpRsp); err != nil {
1048 return err
1049 }
1050
1051 buf, err := ioutil.ReadAll(httpRsp.Body)
1052 if err != nil {
1053 return err
1054 }
1055
1056 if err := unm.Unmarshal(buf, resp); err != nil {
1057 return maybeUnknownEnum(err)
1058 }
1059
1060 return nil
1061 }, opts...)
1062 if e != nil {
1063 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -07001064 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001065 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001066}
1067
1068// Move moves the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -07001069func (c *firewallPoliciesRESTClient) Move(ctx context.Context, req *computepb.MoveFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001070 baseUrl, err := url.Parse(c.endpoint)
1071 if err != nil {
1072 return nil, err
1073 }
Cody Oss75e3d642021-07-01 14:46:06 -05001074 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/move", req.GetFirewallPolicy())
1075
1076 params := url.Values{}
Yoshi Automation Botd4ea7dd2022-04-21 09:48:45 -07001077 params.Add("parentId", fmt.Sprintf("%v", req.GetParentId()))
Cody Oss75e3d642021-07-01 14:46:06 -05001078 if req != nil && req.RequestId != nil {
1079 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1080 }
1081
1082 baseUrl.RawQuery = params.Encode()
1083
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001084 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001085 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
1086
1087 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001088 opts = append((*c.CallOptions).Move[0:len((*c.CallOptions).Move):len((*c.CallOptions).Move)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001089 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001090 resp := &computepb.Operation{}
1091 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001092 if settings.Path != "" {
1093 baseUrl.Path = settings.Path
1094 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001095 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
1096 if err != nil {
1097 return err
1098 }
1099 httpReq = httpReq.WithContext(ctx)
1100 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001101
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001102 httpRsp, err := c.httpClient.Do(httpReq)
1103 if err != nil {
1104 return err
1105 }
1106 defer httpRsp.Body.Close()
1107
1108 if err = googleapi.CheckResponse(httpRsp); err != nil {
1109 return err
1110 }
1111
1112 buf, err := ioutil.ReadAll(httpRsp.Body)
1113 if err != nil {
1114 return err
1115 }
1116
1117 if err := unm.Unmarshal(buf, resp); err != nil {
1118 return maybeUnknownEnum(err)
1119 }
1120
1121 return nil
1122 }, opts...)
1123 if e != nil {
1124 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -07001125 }
Cody Oss95d36092022-02-02 16:22:27 -07001126 op := &Operation{
1127 &globalOrganizationOperationsHandle{
1128 c: c.operationClient,
1129 proto: resp,
1130 },
1131 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001132 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001133}
1134
1135// Patch patches the specified policy with the data included in the request.
Noah Dietz36f46492021-08-03 14:16:18 -07001136func (c *firewallPoliciesRESTClient) Patch(ctx context.Context, req *computepb.PatchFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -07001137 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -05001138 body := req.GetFirewallPolicyResource()
1139 jsonReq, err := m.Marshal(body)
1140 if err != nil {
1141 return nil, err
1142 }
1143
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001144 baseUrl, err := url.Parse(c.endpoint)
1145 if err != nil {
1146 return nil, err
1147 }
Cody Oss75e3d642021-07-01 14:46:06 -05001148 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy())
1149
1150 params := url.Values{}
1151 if req != nil && req.RequestId != nil {
1152 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1153 }
1154
1155 baseUrl.RawQuery = params.Encode()
1156
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001157 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001158 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
1159
1160 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001161 opts = append((*c.CallOptions).Patch[0:len((*c.CallOptions).Patch):len((*c.CallOptions).Patch)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001162 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001163 resp := &computepb.Operation{}
1164 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001165 if settings.Path != "" {
1166 baseUrl.Path = settings.Path
1167 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001168 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1169 if err != nil {
1170 return err
1171 }
1172 httpReq = httpReq.WithContext(ctx)
1173 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001174
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001175 httpRsp, err := c.httpClient.Do(httpReq)
1176 if err != nil {
1177 return err
1178 }
1179 defer httpRsp.Body.Close()
1180
1181 if err = googleapi.CheckResponse(httpRsp); err != nil {
1182 return err
1183 }
1184
1185 buf, err := ioutil.ReadAll(httpRsp.Body)
1186 if err != nil {
1187 return err
1188 }
1189
1190 if err := unm.Unmarshal(buf, resp); err != nil {
1191 return maybeUnknownEnum(err)
1192 }
1193
1194 return nil
1195 }, opts...)
1196 if e != nil {
1197 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -07001198 }
Cody Oss95d36092022-02-02 16:22:27 -07001199 op := &Operation{
1200 &globalOrganizationOperationsHandle{
1201 c: c.operationClient,
1202 proto: resp,
1203 },
1204 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001205 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001206}
1207
1208// PatchRule patches a rule of the specified priority.
Noah Dietz36f46492021-08-03 14:16:18 -07001209func (c *firewallPoliciesRESTClient) PatchRule(ctx context.Context, req *computepb.PatchRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -07001210 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -05001211 body := req.GetFirewallPolicyRuleResource()
1212 jsonReq, err := m.Marshal(body)
1213 if err != nil {
1214 return nil, err
1215 }
1216
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001217 baseUrl, err := url.Parse(c.endpoint)
1218 if err != nil {
1219 return nil, err
1220 }
Cody Oss75e3d642021-07-01 14:46:06 -05001221 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/patchRule", req.GetFirewallPolicy())
1222
1223 params := url.Values{}
1224 if req != nil && req.Priority != nil {
1225 params.Add("priority", fmt.Sprintf("%v", req.GetPriority()))
1226 }
1227 if req != nil && req.RequestId != nil {
1228 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1229 }
1230
1231 baseUrl.RawQuery = params.Encode()
1232
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001233 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001234 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
1235
1236 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001237 opts = append((*c.CallOptions).PatchRule[0:len((*c.CallOptions).PatchRule):len((*c.CallOptions).PatchRule)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001238 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001239 resp := &computepb.Operation{}
1240 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001241 if settings.Path != "" {
1242 baseUrl.Path = settings.Path
1243 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001244 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1245 if err != nil {
1246 return err
1247 }
1248 httpReq = httpReq.WithContext(ctx)
1249 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001250
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001251 httpRsp, err := c.httpClient.Do(httpReq)
1252 if err != nil {
1253 return err
1254 }
1255 defer httpRsp.Body.Close()
1256
1257 if err = googleapi.CheckResponse(httpRsp); err != nil {
1258 return err
1259 }
1260
1261 buf, err := ioutil.ReadAll(httpRsp.Body)
1262 if err != nil {
1263 return err
1264 }
1265
1266 if err := unm.Unmarshal(buf, resp); err != nil {
1267 return maybeUnknownEnum(err)
1268 }
1269
1270 return nil
1271 }, opts...)
1272 if e != nil {
1273 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -07001274 }
Cody Oss95d36092022-02-02 16:22:27 -07001275 op := &Operation{
1276 &globalOrganizationOperationsHandle{
1277 c: c.operationClient,
1278 proto: resp,
1279 },
1280 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001281 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001282}
1283
1284// RemoveAssociation removes an association for the specified firewall policy.
Noah Dietz36f46492021-08-03 14:16:18 -07001285func (c *firewallPoliciesRESTClient) RemoveAssociation(ctx context.Context, req *computepb.RemoveAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001286 baseUrl, err := url.Parse(c.endpoint)
1287 if err != nil {
1288 return nil, err
1289 }
Cody Oss75e3d642021-07-01 14:46:06 -05001290 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/removeAssociation", req.GetFirewallPolicy())
1291
1292 params := url.Values{}
1293 if req != nil && req.Name != nil {
1294 params.Add("name", fmt.Sprintf("%v", req.GetName()))
1295 }
1296 if req != nil && req.RequestId != nil {
1297 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1298 }
1299
1300 baseUrl.RawQuery = params.Encode()
1301
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001302 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001303 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
1304
1305 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001306 opts = append((*c.CallOptions).RemoveAssociation[0:len((*c.CallOptions).RemoveAssociation):len((*c.CallOptions).RemoveAssociation)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001307 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001308 resp := &computepb.Operation{}
1309 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001310 if settings.Path != "" {
1311 baseUrl.Path = settings.Path
1312 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001313 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
1314 if err != nil {
1315 return err
1316 }
1317 httpReq = httpReq.WithContext(ctx)
1318 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001319
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001320 httpRsp, err := c.httpClient.Do(httpReq)
1321 if err != nil {
1322 return err
1323 }
1324 defer httpRsp.Body.Close()
1325
1326 if err = googleapi.CheckResponse(httpRsp); err != nil {
1327 return err
1328 }
1329
1330 buf, err := ioutil.ReadAll(httpRsp.Body)
1331 if err != nil {
1332 return err
1333 }
1334
1335 if err := unm.Unmarshal(buf, resp); err != nil {
1336 return maybeUnknownEnum(err)
1337 }
1338
1339 return nil
1340 }, opts...)
1341 if e != nil {
1342 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -07001343 }
Cody Oss95d36092022-02-02 16:22:27 -07001344 op := &Operation{
1345 &globalOrganizationOperationsHandle{
1346 c: c.operationClient,
1347 proto: resp,
1348 },
1349 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001350 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001351}
1352
1353// RemoveRule deletes a rule of the specified priority.
Noah Dietz36f46492021-08-03 14:16:18 -07001354func (c *firewallPoliciesRESTClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001355 baseUrl, err := url.Parse(c.endpoint)
1356 if err != nil {
1357 return nil, err
1358 }
Cody Oss75e3d642021-07-01 14:46:06 -05001359 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/removeRule", req.GetFirewallPolicy())
1360
1361 params := url.Values{}
1362 if req != nil && req.Priority != nil {
1363 params.Add("priority", fmt.Sprintf("%v", req.GetPriority()))
1364 }
1365 if req != nil && req.RequestId != nil {
1366 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1367 }
1368
1369 baseUrl.RawQuery = params.Encode()
1370
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001371 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001372 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "firewall_policy", url.QueryEscape(req.GetFirewallPolicy())))
1373
1374 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001375 opts = append((*c.CallOptions).RemoveRule[0:len((*c.CallOptions).RemoveRule):len((*c.CallOptions).RemoveRule)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001376 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001377 resp := &computepb.Operation{}
1378 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001379 if settings.Path != "" {
1380 baseUrl.Path = settings.Path
1381 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001382 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
1383 if err != nil {
1384 return err
1385 }
1386 httpReq = httpReq.WithContext(ctx)
1387 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001388
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001389 httpRsp, err := c.httpClient.Do(httpReq)
1390 if err != nil {
1391 return err
1392 }
1393 defer httpRsp.Body.Close()
1394
1395 if err = googleapi.CheckResponse(httpRsp); err != nil {
1396 return err
1397 }
1398
1399 buf, err := ioutil.ReadAll(httpRsp.Body)
1400 if err != nil {
1401 return err
1402 }
1403
1404 if err := unm.Unmarshal(buf, resp); err != nil {
1405 return maybeUnknownEnum(err)
1406 }
1407
1408 return nil
1409 }, opts...)
1410 if e != nil {
1411 return nil, e
Noah Dietz36f46492021-08-03 14:16:18 -07001412 }
Cody Oss95d36092022-02-02 16:22:27 -07001413 op := &Operation{
1414 &globalOrganizationOperationsHandle{
1415 c: c.operationClient,
1416 proto: resp,
1417 },
1418 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001419 return op, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001420}
1421
1422// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
1423func (c *firewallPoliciesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -07001424 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -05001425 body := req.GetGlobalOrganizationSetPolicyRequestResource()
1426 jsonReq, err := m.Marshal(body)
1427 if err != nil {
1428 return nil, err
1429 }
1430
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001431 baseUrl, err := url.Parse(c.endpoint)
1432 if err != nil {
1433 return nil, err
1434 }
Cody Oss75e3d642021-07-01 14:46:06 -05001435 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/setIamPolicy", req.GetResource())
1436
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001437 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001438 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
1439
1440 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001441 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001442 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001443 resp := &computepb.Policy{}
1444 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001445 if settings.Path != "" {
1446 baseUrl.Path = settings.Path
1447 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001448 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1449 if err != nil {
1450 return err
1451 }
1452 httpReq = httpReq.WithContext(ctx)
1453 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001454
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001455 httpRsp, err := c.httpClient.Do(httpReq)
1456 if err != nil {
1457 return err
1458 }
1459 defer httpRsp.Body.Close()
1460
1461 if err = googleapi.CheckResponse(httpRsp); err != nil {
1462 return err
1463 }
1464
1465 buf, err := ioutil.ReadAll(httpRsp.Body)
1466 if err != nil {
1467 return err
1468 }
1469
1470 if err := unm.Unmarshal(buf, resp); err != nil {
1471 return maybeUnknownEnum(err)
1472 }
1473
1474 return nil
1475 }, opts...)
1476 if e != nil {
1477 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -07001478 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001479 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001480}
1481
1482// TestIamPermissions returns permissions that a caller has on the specified resource.
1483func (c *firewallPoliciesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) {
Yoshi Automation Bot652d7c22021-07-08 07:56:23 -07001484 m := protojson.MarshalOptions{AllowPartial: true}
Cody Oss75e3d642021-07-01 14:46:06 -05001485 body := req.GetTestPermissionsRequestResource()
1486 jsonReq, err := m.Marshal(body)
1487 if err != nil {
1488 return nil, err
1489 }
1490
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001491 baseUrl, err := url.Parse(c.endpoint)
1492 if err != nil {
1493 return nil, err
1494 }
Cody Oss75e3d642021-07-01 14:46:06 -05001495 baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/testIamPermissions", req.GetResource())
1496
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001497 // Build HTTP headers from client and context metadata.
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001498 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource())))
1499
1500 headers := buildHeaders(ctx, c.xGoogMetadata, md, metadata.Pairs("Content-Type", "application/json"))
Yoshi Automation Bot5e460682022-06-16 07:27:39 -07001501 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
Cody Oss75e3d642021-07-01 14:46:06 -05001502 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001503 resp := &computepb.TestPermissionsResponse{}
1504 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
Yoshi Automation Bot689cad92022-04-20 13:50:22 -07001505 if settings.Path != "" {
1506 baseUrl.Path = settings.Path
1507 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001508 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1509 if err != nil {
1510 return err
1511 }
1512 httpReq = httpReq.WithContext(ctx)
1513 httpReq.Header = headers
Cody Oss75e3d642021-07-01 14:46:06 -05001514
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001515 httpRsp, err := c.httpClient.Do(httpReq)
1516 if err != nil {
1517 return err
1518 }
1519 defer httpRsp.Body.Close()
1520
1521 if err = googleapi.CheckResponse(httpRsp); err != nil {
1522 return err
1523 }
1524
1525 buf, err := ioutil.ReadAll(httpRsp.Body)
1526 if err != nil {
1527 return err
1528 }
1529
1530 if err := unm.Unmarshal(buf, resp); err != nil {
1531 return maybeUnknownEnum(err)
1532 }
1533
1534 return nil
1535 }, opts...)
1536 if e != nil {
1537 return nil, e
Yoshi Automation Bot8ffed362021-09-15 15:40:16 -07001538 }
Yoshi Automation Bot6e560772022-02-01 14:18:45 -08001539 return resp, nil
Cody Oss75e3d642021-07-01 14:46:06 -05001540}
Noah Dietz36f46492021-08-03 14:16:18 -07001541
1542// FirewallPolicyIterator manages a stream of *computepb.FirewallPolicy.
1543type FirewallPolicyIterator struct {
1544 items []*computepb.FirewallPolicy
1545 pageInfo *iterator.PageInfo
1546 nextFunc func() error
1547
1548 // Response is the raw response for the current page.
1549 // It must be cast to the RPC response type.
1550 // Calling Next() or InternalFetch() updates this value.
1551 Response interface{}
1552
1553 // InternalFetch is for use by the Google Cloud Libraries only.
1554 // It is not part of the stable interface of this package.
1555 //
1556 // InternalFetch returns results from a single call to the underlying RPC.
1557 // The number of results is no greater than pageSize.
1558 // If there are no more results, nextPageToken is empty and err is nil.
1559 InternalFetch func(pageSize int, pageToken string) (results []*computepb.FirewallPolicy, nextPageToken string, err error)
1560}
1561
1562// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
1563func (it *FirewallPolicyIterator) PageInfo() *iterator.PageInfo {
1564 return it.pageInfo
1565}
1566
1567// Next returns the next result. Its second return value is iterator.Done if there are no more
1568// results. Once Next returns Done, all subsequent calls will return Done.
1569func (it *FirewallPolicyIterator) Next() (*computepb.FirewallPolicy, error) {
1570 var item *computepb.FirewallPolicy
1571 if err := it.nextFunc(); err != nil {
1572 return item, err
1573 }
1574 item = it.items[0]
1575 it.items = it.items[1:]
1576 return item, nil
1577}
1578
1579func (it *FirewallPolicyIterator) bufLen() int {
1580 return len(it.items)
1581}
1582
1583func (it *FirewallPolicyIterator) takeBuf() interface{} {
1584 b := it.items
1585 it.items = nil
1586 return b
1587}