Yoshi Automation Bot | 18092a0 | 2022-01-06 10:03:07 -0800 | [diff] [blame] | 1 | // Copyright 2022 Google LLC |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Code generated by protoc-gen-go_gapic. DO NOT EDIT. |
| 16 | |
| 17 | package compute |
| 18 | |
| 19 | import ( |
| 20 | "bytes" |
| 21 | "context" |
| 22 | "fmt" |
| 23 | "io/ioutil" |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 24 | "math" |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 25 | "net/http" |
| 26 | "net/url" |
| 27 | |
| 28 | gax "github.com/googleapis/gax-go/v2" |
Yoshi Automation Bot | 799e6dc | 2021-08-20 07:18:20 -0700 | [diff] [blame] | 29 | "google.golang.org/api/googleapi" |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 30 | "google.golang.org/api/iterator" |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 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" |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 38 | "google.golang.org/protobuf/proto" |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 39 | ) |
| 40 | |
| 41 | var newFirewallPoliciesClientHook clientHook |
| 42 | |
| 43 | // FirewallPoliciesCallOptions contains the retry settings for each method of FirewallPoliciesClient. |
| 44 | type 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 65 | func 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 89 | type internalFirewallPoliciesClient interface { |
| 90 | Close() error |
| 91 | setGoogleClientInfo(...string) |
| 92 | Connection() *grpc.ClientConn |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 93 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 97 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 101 | Insert(context.Context, *computepb.InsertFirewallPolicyRequest, ...gax.CallOption) (*Operation, error) |
| 102 | List(context.Context, *computepb.ListFirewallPoliciesRequest, ...gax.CallOption) *FirewallPolicyIterator |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 103 | ListAssociations(context.Context, *computepb.ListAssociationsFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 104 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 109 | 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. |
| 117 | type 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. |
| 129 | func (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. |
| 136 | func (c *FirewallPoliciesClient) setGoogleClientInfo(keyval ...string) { |
| 137 | c.internalClient.setGoogleClientInfo(keyval...) |
| 138 | } |
| 139 | |
| 140 | // Connection returns a connection to the API service. |
| 141 | // |
| 142 | // Deprecated. |
| 143 | func (c *FirewallPoliciesClient) Connection() *grpc.ClientConn { |
| 144 | return c.internalClient.Connection() |
| 145 | } |
| 146 | |
| 147 | // AddAssociation inserts an association for the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 148 | func (c *FirewallPoliciesClient) AddAssociation(ctx context.Context, req *computepb.AddAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 149 | return c.internalClient.AddAssociation(ctx, req, opts...) |
| 150 | } |
| 151 | |
| 152 | // AddRule inserts a rule into a firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 153 | func (c *FirewallPoliciesClient) AddRule(ctx context.Context, req *computepb.AddRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 154 | return c.internalClient.AddRule(ctx, req, opts...) |
| 155 | } |
| 156 | |
| 157 | // CloneRules copies rules to the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 158 | func (c *FirewallPoliciesClient) CloneRules(ctx context.Context, req *computepb.CloneRulesFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 159 | return c.internalClient.CloneRules(ctx, req, opts...) |
| 160 | } |
| 161 | |
| 162 | // Delete deletes the specified policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 163 | func (c *FirewallPoliciesClient) Delete(ctx context.Context, req *computepb.DeleteFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 164 | return c.internalClient.Delete(ctx, req, opts...) |
| 165 | } |
| 166 | |
| 167 | // Get returns the specified firewall policy. |
| 168 | func (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. |
| 173 | func (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. |
| 178 | func (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. |
| 183 | func (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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 188 | func (c *FirewallPoliciesClient) Insert(ctx context.Context, req *computepb.InsertFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 189 | return c.internalClient.Insert(ctx, req, opts...) |
| 190 | } |
| 191 | |
Yoshi Automation Bot | 83b941c | 2021-11-04 14:52:20 -0700 | [diff] [blame] | 192 | // List lists all the policies that have been configured for the specified folder or organization. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 193 | func (c *FirewallPoliciesClient) List(ctx context.Context, req *computepb.ListFirewallPoliciesRequest, opts ...gax.CallOption) *FirewallPolicyIterator { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 194 | return c.internalClient.List(ctx, req, opts...) |
| 195 | } |
| 196 | |
| 197 | // ListAssociations lists associations of a specified target, i.e., organization or folder. |
| 198 | func (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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 203 | func (c *FirewallPoliciesClient) Move(ctx context.Context, req *computepb.MoveFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 204 | return c.internalClient.Move(ctx, req, opts...) |
| 205 | } |
| 206 | |
| 207 | // Patch patches the specified policy with the data included in the request. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 208 | func (c *FirewallPoliciesClient) Patch(ctx context.Context, req *computepb.PatchFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 209 | return c.internalClient.Patch(ctx, req, opts...) |
| 210 | } |
| 211 | |
| 212 | // PatchRule patches a rule of the specified priority. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 213 | func (c *FirewallPoliciesClient) PatchRule(ctx context.Context, req *computepb.PatchRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 214 | return c.internalClient.PatchRule(ctx, req, opts...) |
| 215 | } |
| 216 | |
| 217 | // RemoveAssociation removes an association for the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 218 | func (c *FirewallPoliciesClient) RemoveAssociation(ctx context.Context, req *computepb.RemoveAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 219 | return c.internalClient.RemoveAssociation(ctx, req, opts...) |
| 220 | } |
| 221 | |
| 222 | // RemoveRule deletes a rule of the specified priority. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 223 | func (c *FirewallPoliciesClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 224 | return c.internalClient.RemoveRule(ctx, req, opts...) |
| 225 | } |
| 226 | |
| 227 | // SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. |
| 228 | func (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. |
| 233 | func (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. |
| 238 | type firewallPoliciesRESTClient struct { |
| 239 | // The http endpoint to connect to. |
| 240 | endpoint string |
| 241 | |
| 242 | // The http client. |
| 243 | httpClient *http.Client |
| 244 | |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 245 | // operationClient is used to call the operation-specific management service. |
| 246 | operationClient *GlobalOrganizationOperationsClient |
| 247 | |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 248 | // The x-goog-* metadata to be sent with each request. |
| 249 | xGoogMetadata metadata.MD |
Yoshi Automation Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 250 | |
| 251 | // Points back to the CallOptions field of the containing FirewallPoliciesClient |
| 252 | CallOptions **FirewallPoliciesCallOptions |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | // NewFirewallPoliciesRESTClient creates a new firewall policies rest client. |
| 256 | // |
| 257 | // The FirewallPolicies API. |
| 258 | func 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 265 | callOpts := defaultFirewallPoliciesRESTCallOptions() |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 266 | c := &firewallPoliciesRESTClient{ |
Yoshi Automation Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 267 | endpoint: endpoint, |
| 268 | httpClient: httpClient, |
| 269 | CallOptions: &callOpts, |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 270 | } |
| 271 | c.setGoogleClientInfo() |
| 272 | |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 273 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 283 | return &FirewallPoliciesClient{internalClient: c, CallOptions: callOpts}, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | func defaultFirewallPoliciesRESTClientOptions() []option.ClientOption { |
| 287 | return []option.ClientOption{ |
Yoshi Automation Bot | 32d68ec | 2021-07-07 11:42:48 -0700 | [diff] [blame] | 288 | internaloption.WithDefaultEndpoint("https://compute.googleapis.com"), |
| 289 | internaloption.WithDefaultMTLSEndpoint("https://compute.mtls.googleapis.com"), |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 290 | 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. |
| 298 | func (c *firewallPoliciesRESTClient) setGoogleClientInfo(keyval ...string) { |
| 299 | kv := append([]string{"gl-go", versionGo()}, keyval...) |
Cody Oss | 55f0d92 | 2022-02-23 16:15:58 -0700 | [diff] [blame] | 300 | kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN") |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 301 | 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. |
| 306 | func (c *firewallPoliciesRESTClient) Close() error { |
| 307 | // Replace httpClient with nil to force cleanup. |
| 308 | c.httpClient = nil |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 309 | if err := c.operationClient.Close(); err != nil { |
| 310 | return err |
| 311 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 312 | return nil |
| 313 | } |
| 314 | |
| 315 | // Connection returns a connection to the API service. |
| 316 | // |
| 317 | // Deprecated. |
| 318 | func (c *firewallPoliciesRESTClient) Connection() *grpc.ClientConn { |
| 319 | return nil |
| 320 | } |
| 321 | |
| 322 | // AddAssociation inserts an association for the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 323 | func (c *firewallPoliciesRESTClient) AddAssociation(ctx context.Context, req *computepb.AddAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 324 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 325 | body := req.GetFirewallPolicyAssociationResource() |
| 326 | jsonReq, err := m.Marshal(body) |
| 327 | if err != nil { |
| 328 | return nil, err |
| 329 | } |
| 330 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 331 | baseUrl, err := url.Parse(c.endpoint) |
| 332 | if err != nil { |
| 333 | return nil, err |
| 334 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 335 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 347 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 348 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 351 | opts = append((*c.CallOptions).AddAssociation[0:len((*c.CallOptions).AddAssociation):len((*c.CallOptions).AddAssociation)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 352 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 353 | resp := &computepb.Operation{} |
| 354 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 355 | if settings.Path != "" { |
| 356 | baseUrl.Path = settings.Path |
| 357 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 358 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 364 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 365 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 388 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 389 | op := &Operation{ |
| 390 | &globalOrganizationOperationsHandle{ |
| 391 | c: c.operationClient, |
| 392 | proto: resp, |
| 393 | }, |
| 394 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 395 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // AddRule inserts a rule into a firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 399 | func (c *firewallPoliciesRESTClient) AddRule(ctx context.Context, req *computepb.AddRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 400 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 401 | body := req.GetFirewallPolicyRuleResource() |
| 402 | jsonReq, err := m.Marshal(body) |
| 403 | if err != nil { |
| 404 | return nil, err |
| 405 | } |
| 406 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 407 | baseUrl, err := url.Parse(c.endpoint) |
| 408 | if err != nil { |
| 409 | return nil, err |
| 410 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 411 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 420 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 421 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 424 | opts = append((*c.CallOptions).AddRule[0:len((*c.CallOptions).AddRule):len((*c.CallOptions).AddRule)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 425 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 426 | resp := &computepb.Operation{} |
| 427 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 428 | if settings.Path != "" { |
| 429 | baseUrl.Path = settings.Path |
| 430 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 431 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 437 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 438 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 461 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 462 | op := &Operation{ |
| 463 | &globalOrganizationOperationsHandle{ |
| 464 | c: c.operationClient, |
| 465 | proto: resp, |
| 466 | }, |
| 467 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 468 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | // CloneRules copies rules to the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 472 | func (c *firewallPoliciesRESTClient) CloneRules(ctx context.Context, req *computepb.CloneRulesFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 473 | baseUrl, err := url.Parse(c.endpoint) |
| 474 | if err != nil { |
| 475 | return nil, err |
| 476 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 477 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 489 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 490 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 493 | opts = append((*c.CallOptions).CloneRules[0:len((*c.CallOptions).CloneRules):len((*c.CallOptions).CloneRules)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 494 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 495 | resp := &computepb.Operation{} |
| 496 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 497 | if settings.Path != "" { |
| 498 | baseUrl.Path = settings.Path |
| 499 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 500 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 506 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 507 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 530 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 531 | op := &Operation{ |
| 532 | &globalOrganizationOperationsHandle{ |
| 533 | c: c.operationClient, |
| 534 | proto: resp, |
| 535 | }, |
| 536 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 537 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | // Delete deletes the specified policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 541 | func (c *firewallPoliciesRESTClient) Delete(ctx context.Context, req *computepb.DeleteFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 542 | baseUrl, err := url.Parse(c.endpoint) |
| 543 | if err != nil { |
| 544 | return nil, err |
| 545 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 546 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 555 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 556 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 559 | opts = append((*c.CallOptions).Delete[0:len((*c.CallOptions).Delete):len((*c.CallOptions).Delete)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 560 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 561 | resp := &computepb.Operation{} |
| 562 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 563 | if settings.Path != "" { |
| 564 | baseUrl.Path = settings.Path |
| 565 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 566 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 572 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 573 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 596 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 597 | op := &Operation{ |
| 598 | &globalOrganizationOperationsHandle{ |
| 599 | c: c.operationClient, |
| 600 | proto: resp, |
| 601 | }, |
| 602 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 603 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | // Get returns the specified firewall policy. |
| 607 | func (c *firewallPoliciesRESTClient) Get(ctx context.Context, req *computepb.GetFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicy, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 608 | baseUrl, err := url.Parse(c.endpoint) |
| 609 | if err != nil { |
| 610 | return nil, err |
| 611 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 612 | baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy()) |
| 613 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 614 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 615 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 618 | opts = append((*c.CallOptions).Get[0:len((*c.CallOptions).Get):len((*c.CallOptions).Get)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 619 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 620 | resp := &computepb.FirewallPolicy{} |
| 621 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 622 | if settings.Path != "" { |
| 623 | baseUrl.Path = settings.Path |
| 624 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 625 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 631 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 632 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 655 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 656 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | // GetAssociation gets an association with the specified name. |
| 660 | func (c *firewallPoliciesRESTClient) GetAssociation(ctx context.Context, req *computepb.GetAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 661 | baseUrl, err := url.Parse(c.endpoint) |
| 662 | if err != nil { |
| 663 | return nil, err |
| 664 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 665 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 674 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 675 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 678 | opts = append((*c.CallOptions).GetAssociation[0:len((*c.CallOptions).GetAssociation):len((*c.CallOptions).GetAssociation)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 679 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 680 | resp := &computepb.FirewallPolicyAssociation{} |
| 681 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 682 | if settings.Path != "" { |
| 683 | baseUrl.Path = settings.Path |
| 684 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 685 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 691 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 692 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 715 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 716 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | // GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. |
| 720 | func (c *firewallPoliciesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 721 | baseUrl, err := url.Parse(c.endpoint) |
| 722 | if err != nil { |
| 723 | return nil, err |
| 724 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 725 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 734 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 735 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 738 | opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 739 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 740 | resp := &computepb.Policy{} |
| 741 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 742 | if settings.Path != "" { |
| 743 | baseUrl.Path = settings.Path |
| 744 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 745 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 751 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 752 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 775 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 776 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | // GetRule gets a rule of the specified priority. |
| 780 | func (c *firewallPoliciesRESTClient) GetRule(ctx context.Context, req *computepb.GetRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyRule, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 781 | baseUrl, err := url.Parse(c.endpoint) |
| 782 | if err != nil { |
| 783 | return nil, err |
| 784 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 785 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 794 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 795 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 798 | opts = append((*c.CallOptions).GetRule[0:len((*c.CallOptions).GetRule):len((*c.CallOptions).GetRule)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 799 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 800 | resp := &computepb.FirewallPolicyRule{} |
| 801 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 802 | if settings.Path != "" { |
| 803 | baseUrl.Path = settings.Path |
| 804 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 805 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 811 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 812 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 835 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 836 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | // Insert creates a new policy in the specified project using the data included in the request. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 840 | func (c *firewallPoliciesRESTClient) Insert(ctx context.Context, req *computepb.InsertFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 841 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 842 | body := req.GetFirewallPolicyResource() |
| 843 | jsonReq, err := m.Marshal(body) |
| 844 | if err != nil { |
| 845 | return nil, err |
| 846 | } |
| 847 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 848 | baseUrl, err := url.Parse(c.endpoint) |
| 849 | if err != nil { |
| 850 | return nil, err |
| 851 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 852 | baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies") |
| 853 | |
| 854 | params := url.Values{} |
Yoshi Automation Bot | 19a9ef2 | 2022-04-14 10:21:44 -0700 | [diff] [blame] | 855 | params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 856 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 862 | // Build HTTP headers from client and context metadata. |
| 863 | headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) |
Yoshi Automation Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 864 | opts = append((*c.CallOptions).Insert[0:len((*c.CallOptions).Insert):len((*c.CallOptions).Insert)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 865 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 866 | resp := &computepb.Operation{} |
| 867 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 868 | if settings.Path != "" { |
| 869 | baseUrl.Path = settings.Path |
| 870 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 871 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 877 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 878 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 901 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 902 | op := &Operation{ |
| 903 | &globalOrganizationOperationsHandle{ |
| 904 | c: c.operationClient, |
| 905 | proto: resp, |
| 906 | }, |
| 907 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 908 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 909 | } |
| 910 | |
Yoshi Automation Bot | 83b941c | 2021-11-04 14:52:20 -0700 | [diff] [blame] | 911 | // List lists all the policies that have been configured for the specified folder or organization. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 912 | func (c *firewallPoliciesRESTClient) List(ctx context.Context, req *computepb.ListFirewallPoliciesRequest, opts ...gax.CallOption) *FirewallPolicyIterator { |
| 913 | it := &FirewallPolicyIterator{} |
| 914 | req = proto.Clone(req).(*computepb.ListFirewallPoliciesRequest) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 915 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 916 | 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 Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 926 | baseUrl, err := url.Parse(c.endpoint) |
| 927 | if err != nil { |
| 928 | return nil, "", err |
| 929 | } |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 930 | baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies") |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 931 | |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 932 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 954 | // 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 Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 957 | if settings.Path != "" { |
| 958 | baseUrl.Path = settings.Path |
| 959 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 960 | httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 961 | if err != nil { |
| 962 | return err |
| 963 | } |
| 964 | httpReq.Header = headers |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 965 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 966 | httpRsp, err := c.httpClient.Do(httpReq) |
| 967 | if err != nil { |
| 968 | return err |
| 969 | } |
| 970 | defer httpRsp.Body.Close() |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 971 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 972 | if err = googleapi.CheckResponse(httpRsp); err != nil { |
| 973 | return err |
| 974 | } |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 975 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 976 | buf, err := ioutil.ReadAll(httpRsp.Body) |
| 977 | if err != nil { |
| 978 | return err |
| 979 | } |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 980 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 981 | if err := unm.Unmarshal(buf, resp); err != nil { |
| 982 | return maybeUnknownEnum(err) |
| 983 | } |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 984 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 985 | return nil |
| 986 | }, opts...) |
| 987 | if e != nil { |
| 988 | return nil, "", e |
| 989 | } |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 990 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | // ListAssociations lists associations of a specified target, i.e., organization or folder. |
| 1011 | func (c *firewallPoliciesRESTClient) ListAssociations(ctx context.Context, req *computepb.ListAssociationsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1012 | baseUrl, err := url.Parse(c.endpoint) |
| 1013 | if err != nil { |
| 1014 | return nil, err |
| 1015 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1016 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1025 | // Build HTTP headers from client and context metadata. |
| 1026 | headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) |
Yoshi Automation Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1027 | opts = append((*c.CallOptions).ListAssociations[0:len((*c.CallOptions).ListAssociations):len((*c.CallOptions).ListAssociations)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1028 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1029 | resp := &computepb.FirewallPoliciesListAssociationsResponse{} |
| 1030 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1031 | if settings.Path != "" { |
| 1032 | baseUrl.Path = settings.Path |
| 1033 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1034 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1040 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1041 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 1064 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1065 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | // Move moves the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1069 | func (c *firewallPoliciesRESTClient) Move(ctx context.Context, req *computepb.MoveFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1070 | baseUrl, err := url.Parse(c.endpoint) |
| 1071 | if err != nil { |
| 1072 | return nil, err |
| 1073 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1074 | baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/move", req.GetFirewallPolicy()) |
| 1075 | |
| 1076 | params := url.Values{} |
Yoshi Automation Bot | d4ea7dd | 2022-04-21 09:48:45 -0700 | [diff] [blame] | 1077 | params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1078 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1084 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1085 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1088 | opts = append((*c.CallOptions).Move[0:len((*c.CallOptions).Move):len((*c.CallOptions).Move)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1089 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1090 | resp := &computepb.Operation{} |
| 1091 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1092 | if settings.Path != "" { |
| 1093 | baseUrl.Path = settings.Path |
| 1094 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1095 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1101 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1102 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1125 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 1126 | op := &Operation{ |
| 1127 | &globalOrganizationOperationsHandle{ |
| 1128 | c: c.operationClient, |
| 1129 | proto: resp, |
| 1130 | }, |
| 1131 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1132 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | // Patch patches the specified policy with the data included in the request. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1136 | func (c *firewallPoliciesRESTClient) Patch(ctx context.Context, req *computepb.PatchFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 1137 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1138 | body := req.GetFirewallPolicyResource() |
| 1139 | jsonReq, err := m.Marshal(body) |
| 1140 | if err != nil { |
| 1141 | return nil, err |
| 1142 | } |
| 1143 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1144 | baseUrl, err := url.Parse(c.endpoint) |
| 1145 | if err != nil { |
| 1146 | return nil, err |
| 1147 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1148 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1157 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1158 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1161 | opts = append((*c.CallOptions).Patch[0:len((*c.CallOptions).Patch):len((*c.CallOptions).Patch)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1162 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1163 | resp := &computepb.Operation{} |
| 1164 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1165 | if settings.Path != "" { |
| 1166 | baseUrl.Path = settings.Path |
| 1167 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1168 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1174 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1175 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1198 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 1199 | op := &Operation{ |
| 1200 | &globalOrganizationOperationsHandle{ |
| 1201 | c: c.operationClient, |
| 1202 | proto: resp, |
| 1203 | }, |
| 1204 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1205 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | // PatchRule patches a rule of the specified priority. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1209 | func (c *firewallPoliciesRESTClient) PatchRule(ctx context.Context, req *computepb.PatchRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 1210 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1211 | body := req.GetFirewallPolicyRuleResource() |
| 1212 | jsonReq, err := m.Marshal(body) |
| 1213 | if err != nil { |
| 1214 | return nil, err |
| 1215 | } |
| 1216 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1217 | baseUrl, err := url.Parse(c.endpoint) |
| 1218 | if err != nil { |
| 1219 | return nil, err |
| 1220 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1221 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1233 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1234 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1237 | opts = append((*c.CallOptions).PatchRule[0:len((*c.CallOptions).PatchRule):len((*c.CallOptions).PatchRule)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1238 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1239 | resp := &computepb.Operation{} |
| 1240 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1241 | if settings.Path != "" { |
| 1242 | baseUrl.Path = settings.Path |
| 1243 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1244 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1250 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1251 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1274 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 1275 | op := &Operation{ |
| 1276 | &globalOrganizationOperationsHandle{ |
| 1277 | c: c.operationClient, |
| 1278 | proto: resp, |
| 1279 | }, |
| 1280 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1281 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | // RemoveAssociation removes an association for the specified firewall policy. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1285 | func (c *firewallPoliciesRESTClient) RemoveAssociation(ctx context.Context, req *computepb.RemoveAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1286 | baseUrl, err := url.Parse(c.endpoint) |
| 1287 | if err != nil { |
| 1288 | return nil, err |
| 1289 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1290 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1302 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1303 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1306 | opts = append((*c.CallOptions).RemoveAssociation[0:len((*c.CallOptions).RemoveAssociation):len((*c.CallOptions).RemoveAssociation)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1307 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1308 | resp := &computepb.Operation{} |
| 1309 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1310 | if settings.Path != "" { |
| 1311 | baseUrl.Path = settings.Path |
| 1312 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1313 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1319 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1320 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1343 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 1344 | op := &Operation{ |
| 1345 | &globalOrganizationOperationsHandle{ |
| 1346 | c: c.operationClient, |
| 1347 | proto: resp, |
| 1348 | }, |
| 1349 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1350 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | // RemoveRule deletes a rule of the specified priority. |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1354 | func (c *firewallPoliciesRESTClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleFirewallPolicyRequest, opts ...gax.CallOption) (*Operation, error) { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1355 | baseUrl, err := url.Parse(c.endpoint) |
| 1356 | if err != nil { |
| 1357 | return nil, err |
| 1358 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1359 | 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 Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1371 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1372 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1375 | opts = append((*c.CallOptions).RemoveRule[0:len((*c.CallOptions).RemoveRule):len((*c.CallOptions).RemoveRule)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1376 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1377 | resp := &computepb.Operation{} |
| 1378 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1379 | if settings.Path != "" { |
| 1380 | baseUrl.Path = settings.Path |
| 1381 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1382 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1388 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1389 | 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 Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1412 | } |
Cody Oss | 95d3609 | 2022-02-02 16:22:27 -0700 | [diff] [blame] | 1413 | op := &Operation{ |
| 1414 | &globalOrganizationOperationsHandle{ |
| 1415 | c: c.operationClient, |
| 1416 | proto: resp, |
| 1417 | }, |
| 1418 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1419 | return op, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | // SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. |
| 1423 | func (c *firewallPoliciesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 1424 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1425 | body := req.GetGlobalOrganizationSetPolicyRequestResource() |
| 1426 | jsonReq, err := m.Marshal(body) |
| 1427 | if err != nil { |
| 1428 | return nil, err |
| 1429 | } |
| 1430 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1431 | baseUrl, err := url.Parse(c.endpoint) |
| 1432 | if err != nil { |
| 1433 | return nil, err |
| 1434 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1435 | baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/setIamPolicy", req.GetResource()) |
| 1436 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1437 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1438 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1441 | opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1442 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1443 | resp := &computepb.Policy{} |
| 1444 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1445 | if settings.Path != "" { |
| 1446 | baseUrl.Path = settings.Path |
| 1447 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1448 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1454 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1455 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 1478 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1479 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | // TestIamPermissions returns permissions that a caller has on the specified resource. |
| 1483 | func (c *firewallPoliciesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { |
Yoshi Automation Bot | 652d7c2 | 2021-07-08 07:56:23 -0700 | [diff] [blame] | 1484 | m := protojson.MarshalOptions{AllowPartial: true} |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1485 | body := req.GetTestPermissionsRequestResource() |
| 1486 | jsonReq, err := m.Marshal(body) |
| 1487 | if err != nil { |
| 1488 | return nil, err |
| 1489 | } |
| 1490 | |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1491 | baseUrl, err := url.Parse(c.endpoint) |
| 1492 | if err != nil { |
| 1493 | return nil, err |
| 1494 | } |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1495 | baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/testIamPermissions", req.GetResource()) |
| 1496 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1497 | // Build HTTP headers from client and context metadata. |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1498 | 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 Bot | 5e46068 | 2022-06-16 07:27:39 -0700 | [diff] [blame] | 1501 | opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1502 | unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1503 | resp := &computepb.TestPermissionsResponse{} |
| 1504 | e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
Yoshi Automation Bot | 689cad9 | 2022-04-20 13:50:22 -0700 | [diff] [blame] | 1505 | if settings.Path != "" { |
| 1506 | baseUrl.Path = settings.Path |
| 1507 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1508 | 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 Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1514 | |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1515 | 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 Bot | 8ffed36 | 2021-09-15 15:40:16 -0700 | [diff] [blame] | 1538 | } |
Yoshi Automation Bot | 6e56077 | 2022-02-01 14:18:45 -0800 | [diff] [blame] | 1539 | return resp, nil |
Cody Oss | 75e3d64 | 2021-07-01 14:46:06 -0500 | [diff] [blame] | 1540 | } |
Noah Dietz | 36f4649 | 2021-08-03 14:16:18 -0700 | [diff] [blame] | 1541 | |
| 1542 | // FirewallPolicyIterator manages a stream of *computepb.FirewallPolicy. |
| 1543 | type 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. |
| 1563 | func (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. |
| 1569 | func (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 | |
| 1579 | func (it *FirewallPolicyIterator) bufLen() int { |
| 1580 | return len(it.items) |
| 1581 | } |
| 1582 | |
| 1583 | func (it *FirewallPolicyIterator) takeBuf() interface{} { |
| 1584 | b := it.items |
| 1585 | it.items = nil |
| 1586 | return b |
| 1587 | } |