diff --git a/compute/apiv1/backend_buckets_client.go b/compute/apiv1/backend_buckets_client.go index 9c674c8897bc..80e312b8e519 100644 --- a/compute/apiv1/backend_buckets_client.go +++ b/compute/apiv1/backend_buckets_client.go @@ -42,14 +42,15 @@ var newBackendBucketsClientHook clientHook // BackendBucketsCallOptions contains the retry settings for each method of BackendBucketsClient. type BackendBucketsCallOptions struct { - AddSignedUrlKey []gax.CallOption - Delete []gax.CallOption - DeleteSignedUrlKey []gax.CallOption - Get []gax.CallOption - Insert []gax.CallOption - List []gax.CallOption - Patch []gax.CallOption - Update []gax.CallOption + AddSignedUrlKey []gax.CallOption + Delete []gax.CallOption + DeleteSignedUrlKey []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetEdgeSecurityPolicy []gax.CallOption + Update []gax.CallOption } // internalBackendBucketsClient is an interface that defines the methods availaible from Google Compute Engine API. @@ -64,6 +65,7 @@ type internalBackendBucketsClient interface { Insert(context.Context, *computepb.InsertBackendBucketRequest, ...gax.CallOption) (*Operation, error) List(context.Context, *computepb.ListBackendBucketsRequest, ...gax.CallOption) *BackendBucketIterator Patch(context.Context, *computepb.PatchBackendBucketRequest, ...gax.CallOption) (*Operation, error) + SetEdgeSecurityPolicy(context.Context, *computepb.SetEdgeSecurityPolicyBackendBucketRequest, ...gax.CallOption) (*Operation, error) Update(context.Context, *computepb.UpdateBackendBucketRequest, ...gax.CallOption) (*Operation, error) } @@ -136,6 +138,11 @@ func (c *BackendBucketsClient) Patch(ctx context.Context, req *computepb.PatchBa return c.internalClient.Patch(ctx, req, opts...) } +// SetEdgeSecurityPolicy sets the edge security policy for the specified backend bucket. +func (c *BackendBucketsClient) SetEdgeSecurityPolicy(ctx context.Context, req *computepb.SetEdgeSecurityPolicyBackendBucketRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.SetEdgeSecurityPolicy(ctx, req, opts...) +} + // Update updates the specified BackendBucket resource with the data included in the request. func (c *BackendBucketsClient) Update(ctx context.Context, req *computepb.UpdateBackendBucketRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.Update(ctx, req, opts...) @@ -667,6 +674,71 @@ func (c *backendBucketsRESTClient) Patch(ctx context.Context, req *computepb.Pat return op, nil } +// SetEdgeSecurityPolicy sets the edge security policy for the specified backend bucket. +func (c *backendBucketsRESTClient) SetEdgeSecurityPolicy(ctx context.Context, req *computepb.SetEdgeSecurityPolicyBackendBucketRequest, opts ...gax.CallOption) (*Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetSecurityPolicyReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets/%v/setEdgeSecurityPolicy", req.GetProject(), req.GetBackendBucket()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &globalOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + }, + } + return op, nil +} + // Update updates the specified BackendBucket resource with the data included in the request. func (c *backendBucketsRESTClient) Update(ctx context.Context, req *computepb.UpdateBackendBucketRequest, opts ...gax.CallOption) (*Operation, error) { m := protojson.MarshalOptions{AllowPartial: true} diff --git a/compute/apiv1/backend_buckets_client_example_test.go b/compute/apiv1/backend_buckets_client_example_test.go index 8756a27b669f..377840ea5062 100644 --- a/compute/apiv1/backend_buckets_client_example_test.go +++ b/compute/apiv1/backend_buckets_client_example_test.go @@ -197,6 +197,29 @@ func ExampleBackendBucketsClient_Patch() { } } +func ExampleBackendBucketsClient_SetEdgeSecurityPolicy() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetEdgeSecurityPolicyBackendBucketRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SetEdgeSecurityPolicyBackendBucketRequest. + } + op, err := c.SetEdgeSecurityPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + func ExampleBackendBucketsClient_Update() { ctx := context.Background() c, err := compute.NewBackendBucketsRESTClient(ctx) diff --git a/compute/apiv1/backend_services_client.go b/compute/apiv1/backend_services_client.go index ea4f57155603..1c4ba38492e5 100644 --- a/compute/apiv1/backend_services_client.go +++ b/compute/apiv1/backend_services_client.go @@ -43,17 +43,18 @@ var newBackendServicesClientHook clientHook // BackendServicesCallOptions contains the retry settings for each method of BackendServicesClient. type BackendServicesCallOptions struct { - AddSignedUrlKey []gax.CallOption - AggregatedList []gax.CallOption - Delete []gax.CallOption - DeleteSignedUrlKey []gax.CallOption - Get []gax.CallOption - GetHealth []gax.CallOption - Insert []gax.CallOption - List []gax.CallOption - Patch []gax.CallOption - SetSecurityPolicy []gax.CallOption - Update []gax.CallOption + AddSignedUrlKey []gax.CallOption + AggregatedList []gax.CallOption + Delete []gax.CallOption + DeleteSignedUrlKey []gax.CallOption + Get []gax.CallOption + GetHealth []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetEdgeSecurityPolicy []gax.CallOption + SetSecurityPolicy []gax.CallOption + Update []gax.CallOption } // internalBackendServicesClient is an interface that defines the methods availaible from Google Compute Engine API. @@ -70,6 +71,7 @@ type internalBackendServicesClient interface { Insert(context.Context, *computepb.InsertBackendServiceRequest, ...gax.CallOption) (*Operation, error) List(context.Context, *computepb.ListBackendServicesRequest, ...gax.CallOption) *BackendServiceIterator Patch(context.Context, *computepb.PatchBackendServiceRequest, ...gax.CallOption) (*Operation, error) + SetEdgeSecurityPolicy(context.Context, *computepb.SetEdgeSecurityPolicyBackendServiceRequest, ...gax.CallOption) (*Operation, error) SetSecurityPolicy(context.Context, *computepb.SetSecurityPolicyBackendServiceRequest, ...gax.CallOption) (*Operation, error) Update(context.Context, *computepb.UpdateBackendServiceRequest, ...gax.CallOption) (*Operation, error) } @@ -153,6 +155,11 @@ func (c *BackendServicesClient) Patch(ctx context.Context, req *computepb.PatchB return c.internalClient.Patch(ctx, req, opts...) } +// SetEdgeSecurityPolicy sets the edge security policy for the specified backend service. +func (c *BackendServicesClient) SetEdgeSecurityPolicy(ctx context.Context, req *computepb.SetEdgeSecurityPolicyBackendServiceRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.SetEdgeSecurityPolicy(ctx, req, opts...) +} + // SetSecurityPolicy sets the Google Cloud Armor security policy for the specified backend service. For more information, see Google Cloud Armor Overview func (c *BackendServicesClient) SetSecurityPolicy(ctx context.Context, req *computepb.SetSecurityPolicyBackendServiceRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.SetSecurityPolicy(ctx, req, opts...) @@ -840,6 +847,71 @@ func (c *backendServicesRESTClient) Patch(ctx context.Context, req *computepb.Pa return op, nil } +// SetEdgeSecurityPolicy sets the edge security policy for the specified backend service. +func (c *backendServicesRESTClient) SetEdgeSecurityPolicy(ctx context.Context, req *computepb.SetEdgeSecurityPolicyBackendServiceRequest, opts ...gax.CallOption) (*Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetSecurityPolicyReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v/setEdgeSecurityPolicy", req.GetProject(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &globalOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + }, + } + return op, nil +} + // SetSecurityPolicy sets the Google Cloud Armor security policy for the specified backend service. For more information, see Google Cloud Armor Overview func (c *backendServicesRESTClient) SetSecurityPolicy(ctx context.Context, req *computepb.SetSecurityPolicyBackendServiceRequest, opts ...gax.CallOption) (*Operation, error) { m := protojson.MarshalOptions{AllowPartial: true} diff --git a/compute/apiv1/backend_services_client_example_test.go b/compute/apiv1/backend_services_client_example_test.go index ce3a822d89f1..92818209ee2e 100644 --- a/compute/apiv1/backend_services_client_example_test.go +++ b/compute/apiv1/backend_services_client_example_test.go @@ -243,6 +243,29 @@ func ExampleBackendServicesClient_Patch() { } } +func ExampleBackendServicesClient_SetEdgeSecurityPolicy() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetEdgeSecurityPolicyBackendServiceRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SetEdgeSecurityPolicyBackendServiceRequest. + } + op, err := c.SetEdgeSecurityPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + func ExampleBackendServicesClient_SetSecurityPolicy() { ctx := context.Background() c, err := compute.NewBackendServicesRESTClient(ctx) diff --git a/compute/apiv1/disks_client.go b/compute/apiv1/disks_client.go index 1084dedea6d2..b24002864d19 100644 --- a/compute/apiv1/disks_client.go +++ b/compute/apiv1/disks_client.go @@ -122,7 +122,7 @@ func (c *DisksClient) AggregatedList(ctx context.Context, req *computepb.Aggrega return c.internalClient.AggregatedList(ctx, req, opts...) } -// CreateSnapshot creates a snapshot of a specified persistent disk. +// CreateSnapshot creates a snapshot of a specified persistent disk. For regular snapshot creation, consider using snapshots.insert instead, as that method supports more features, such as creating snapshots in a project different from the source disk project. func (c *DisksClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotDiskRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.CreateSnapshot(ctx, req, opts...) } @@ -423,7 +423,7 @@ func (c *disksRESTClient) AggregatedList(ctx context.Context, req *computepb.Agg return it } -// CreateSnapshot creates a snapshot of a specified persistent disk. +// CreateSnapshot creates a snapshot of a specified persistent disk. For regular snapshot creation, consider using snapshots.insert instead, as that method supports more features, such as creating snapshots in a project different from the source disk project. func (c *disksRESTClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotDiskRequest, opts ...gax.CallOption) (*Operation, error) { m := protojson.MarshalOptions{AllowPartial: true} body := req.GetSnapshotResource() diff --git a/compute/apiv1/doc.go b/compute/apiv1/doc.go index 54baf855b484..cd50979ad9b1 100644 --- a/compute/apiv1/doc.go +++ b/compute/apiv1/doc.go @@ -90,7 +90,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/compute/apiv1/firewall_policies_client.go b/compute/apiv1/firewall_policies_client.go index 89c2f6457a79..b6218d6da33c 100644 --- a/compute/apiv1/firewall_policies_client.go +++ b/compute/apiv1/firewall_policies_client.go @@ -749,7 +749,9 @@ func (c *firewallPoliciesRESTClient) Insert(ctx context.Context, req *computepb. baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies") params := url.Values{} - params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } if req != nil && req.RequestId != nil { params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) } @@ -951,7 +953,9 @@ func (c *firewallPoliciesRESTClient) Move(ctx context.Context, req *computepb.Mo baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/move", req.GetFirewallPolicy()) params := url.Values{} - params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } if req != nil && req.RequestId != nil { params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) } diff --git a/compute/apiv1/gapic_metadata.json b/compute/apiv1/gapic_metadata.json index 7df71c72a732..2f512b0d0f5a 100644 --- a/compute/apiv1/gapic_metadata.json +++ b/compute/apiv1/gapic_metadata.json @@ -147,6 +147,11 @@ "Patch" ] }, + "SetEdgeSecurityPolicy": { + "methods": [ + "SetEdgeSecurityPolicy" + ] + }, "Update": { "methods": [ "Update" @@ -206,6 +211,11 @@ "Patch" ] }, + "SetEdgeSecurityPolicy": { + "methods": [ + "SetEdgeSecurityPolicy" + ] + }, "SetSecurityPolicy": { "methods": [ "SetSecurityPolicy" @@ -1187,6 +1197,11 @@ "Reset" ] }, + "Resume": { + "methods": [ + "Resume" + ] + }, "SendDiagnosticInterrupt": { "methods": [ "SendDiagnosticInterrupt" @@ -1272,6 +1287,11 @@ "Stop" ] }, + "Suspend": { + "methods": [ + "Suspend" + ] + }, "TestIamPermissions": { "methods": [ "TestIamPermissions" @@ -1466,6 +1486,50 @@ } } }, + "MachineImages": { + "clients": { + "rest": { + "libraryClient": "MachineImagesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, "MachineTypes": { "clients": { "rest": { @@ -2053,6 +2117,11 @@ "methods": [ "List" ] + }, + "Update": { + "methods": [ + "Update" + ] } } } @@ -2667,6 +2736,11 @@ "methods": [ "TestIamPermissions" ] + }, + "Update": { + "methods": [ + "Update" + ] } } } @@ -2942,6 +3016,11 @@ "GetIamPolicy" ] }, + "Insert": { + "methods": [ + "Insert" + ] + }, "List": { "methods": [ "List" diff --git a/compute/apiv1/instances_client.go b/compute/apiv1/instances_client.go index c831487a1cdc..e640fd2aae48 100644 --- a/compute/apiv1/instances_client.go +++ b/compute/apiv1/instances_client.go @@ -63,6 +63,7 @@ type InstancesCallOptions struct { ListReferrers []gax.CallOption RemoveResourcePolicies []gax.CallOption Reset []gax.CallOption + Resume []gax.CallOption SendDiagnosticInterrupt []gax.CallOption SetDeletionProtection []gax.CallOption SetDiskAutoDelete []gax.CallOption @@ -80,6 +81,7 @@ type InstancesCallOptions struct { Start []gax.CallOption StartWithEncryptionKey []gax.CallOption Stop []gax.CallOption + Suspend []gax.CallOption TestIamPermissions []gax.CallOption Update []gax.CallOption UpdateAccessConfig []gax.CallOption @@ -113,6 +115,7 @@ type internalInstancesClient interface { ListReferrers(context.Context, *computepb.ListReferrersInstancesRequest, ...gax.CallOption) *ReferenceIterator RemoveResourcePolicies(context.Context, *computepb.RemoveResourcePoliciesInstanceRequest, ...gax.CallOption) (*Operation, error) Reset(context.Context, *computepb.ResetInstanceRequest, ...gax.CallOption) (*Operation, error) + Resume(context.Context, *computepb.ResumeInstanceRequest, ...gax.CallOption) (*Operation, error) SendDiagnosticInterrupt(context.Context, *computepb.SendDiagnosticInterruptInstanceRequest, ...gax.CallOption) (*computepb.SendDiagnosticInterruptInstanceResponse, error) SetDeletionProtection(context.Context, *computepb.SetDeletionProtectionInstanceRequest, ...gax.CallOption) (*Operation, error) SetDiskAutoDelete(context.Context, *computepb.SetDiskAutoDeleteInstanceRequest, ...gax.CallOption) (*Operation, error) @@ -130,6 +133,7 @@ type internalInstancesClient interface { Start(context.Context, *computepb.StartInstanceRequest, ...gax.CallOption) (*Operation, error) StartWithEncryptionKey(context.Context, *computepb.StartWithEncryptionKeyInstanceRequest, ...gax.CallOption) (*Operation, error) Stop(context.Context, *computepb.StopInstanceRequest, ...gax.CallOption) (*Operation, error) + Suspend(context.Context, *computepb.SuspendInstanceRequest, ...gax.CallOption) (*Operation, error) TestIamPermissions(context.Context, *computepb.TestIamPermissionsInstanceRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) Update(context.Context, *computepb.UpdateInstanceRequest, ...gax.CallOption) (*Operation, error) UpdateAccessConfig(context.Context, *computepb.UpdateAccessConfigInstanceRequest, ...gax.CallOption) (*Operation, error) @@ -272,6 +276,11 @@ func (c *InstancesClient) Reset(ctx context.Context, req *computepb.ResetInstanc return c.internalClient.Reset(ctx, req, opts...) } +// Resume resumes an instance that was suspended using the instances().suspend method. +func (c *InstancesClient) Resume(ctx context.Context, req *computepb.ResumeInstanceRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Resume(ctx, req, opts...) +} + // SendDiagnosticInterrupt sends diagnostic interrupt to the instance. func (c *InstancesClient) SendDiagnosticInterrupt(ctx context.Context, req *computepb.SendDiagnosticInterruptInstanceRequest, opts ...gax.CallOption) (*computepb.SendDiagnosticInterruptInstanceResponse, error) { return c.internalClient.SendDiagnosticInterrupt(ctx, req, opts...) @@ -317,7 +326,7 @@ func (c *InstancesClient) SetMinCpuPlatform(ctx context.Context, req *computepb. return c.internalClient.SetMinCpuPlatform(ctx, req, opts...) } -// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. +// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. For more information about setting scheduling options for a VM, see Set VM availability policies. func (c *InstancesClient) SetScheduling(ctx context.Context, req *computepb.SetSchedulingInstanceRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.SetScheduling(ctx, req, opts...) } @@ -337,7 +346,7 @@ func (c *InstancesClient) SetTags(ctx context.Context, req *computepb.SetTagsIns return c.internalClient.SetTags(ctx, req, opts...) } -// SimulateMaintenanceEvent simulates a maintenance event on the instance. +// SimulateMaintenanceEvent simulates a host maintenance event on a VM. For more information, see Simulate a host maintenance event. func (c *InstancesClient) SimulateMaintenanceEvent(ctx context.Context, req *computepb.SimulateMaintenanceEventInstanceRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.SimulateMaintenanceEvent(ctx, req, opts...) } @@ -357,6 +366,11 @@ func (c *InstancesClient) Stop(ctx context.Context, req *computepb.StopInstanceR return c.internalClient.Stop(ctx, req, opts...) } +// Suspend this method suspends a running instance, saving its state to persistent storage, and allows you to resume the instance at a later time. Suspended instances have no compute costs (cores or RAM), and incur only storage charges for the saved VM memory and localSSD data. Any charged resources the virtual machine was using, such as persistent disks and static IP addresses, will continue to be charged while the instance is suspended. For more information, see Suspending and resuming an instance. +func (c *InstancesClient) Suspend(ctx context.Context, req *computepb.SuspendInstanceRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Suspend(ctx, req, opts...) +} + // TestIamPermissions returns permissions that a caller has on the specified resource. func (c *InstancesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { return c.internalClient.TestIamPermissions(ctx, req, opts...) @@ -1374,6 +1388,9 @@ func (c *instancesRESTClient) Insert(ctx context.Context, req *computepb.InsertI if req != nil && req.SourceInstanceTemplate != nil { params.Add("sourceInstanceTemplate", fmt.Sprintf("%v", req.GetSourceInstanceTemplate())) } + if req != nil && req.SourceMachineImage != nil { + params.Add("sourceMachineImage", fmt.Sprintf("%v", req.GetSourceMachineImage())) + } baseUrl.RawQuery = params.Encode() @@ -1729,6 +1746,65 @@ func (c *instancesRESTClient) Reset(ctx context.Context, req *computepb.ResetIns return op, nil } +// Resume resumes an instance that was suspended using the instances().suspend method. +func (c *instancesRESTClient) Resume(ctx context.Context, req *computepb.ResumeInstanceRequest, opts ...gax.CallOption) (*Operation, error) { + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/resume", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &zoneOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + zone: req.GetZone(), + }, + } + return op, nil +} + // SendDiagnosticInterrupt sends diagnostic interrupt to the instance. func (c *instancesRESTClient) SendDiagnosticInterrupt(ctx context.Context, req *computepb.SendDiagnosticInterruptInstanceRequest, opts ...gax.CallOption) (*computepb.SendDiagnosticInterruptInstanceResponse, error) { baseUrl, _ := url.Parse(c.endpoint) @@ -2277,7 +2353,7 @@ func (c *instancesRESTClient) SetMinCpuPlatform(ctx context.Context, req *comput return op, nil } -// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. +// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. For more information about setting scheduling options for a VM, see Set VM availability policies. func (c *instancesRESTClient) SetScheduling(ctx context.Context, req *computepb.SetSchedulingInstanceRequest, opts ...gax.CallOption) (*Operation, error) { m := protojson.MarshalOptions{AllowPartial: true} body := req.GetSchedulingResource() @@ -2541,7 +2617,7 @@ func (c *instancesRESTClient) SetTags(ctx context.Context, req *computepb.SetTag return op, nil } -// SimulateMaintenanceEvent simulates a maintenance event on the instance. +// SimulateMaintenanceEvent simulates a host maintenance event on a VM. For more information, see Simulate a host maintenance event. func (c *instancesRESTClient) SimulateMaintenanceEvent(ctx context.Context, req *computepb.SimulateMaintenanceEventInstanceRequest, opts ...gax.CallOption) (*Operation, error) { baseUrl, _ := url.Parse(c.endpoint) baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/simulateMaintenanceEvent", req.GetProject(), req.GetZone(), req.GetInstance()) @@ -2777,6 +2853,65 @@ func (c *instancesRESTClient) Stop(ctx context.Context, req *computepb.StopInsta return op, nil } +// Suspend this method suspends a running instance, saving its state to persistent storage, and allows you to resume the instance at a later time. Suspended instances have no compute costs (cores or RAM), and incur only storage charges for the saved VM memory and localSSD data. Any charged resources the virtual machine was using, such as persistent disks and static IP addresses, will continue to be charged while the instance is suspended. For more information, see Suspending and resuming an instance. +func (c *instancesRESTClient) Suspend(ctx context.Context, req *computepb.SuspendInstanceRequest, opts ...gax.CallOption) (*Operation, error) { + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/suspend", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &zoneOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + zone: req.GetZone(), + }, + } + return op, nil +} + // TestIamPermissions returns permissions that a caller has on the specified resource. func (c *instancesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { m := protojson.MarshalOptions{AllowPartial: true} diff --git a/compute/apiv1/instances_client_example_test.go b/compute/apiv1/instances_client_example_test.go index 7275fb06f15e..9c144acc52fb 100644 --- a/compute/apiv1/instances_client_example_test.go +++ b/compute/apiv1/instances_client_example_test.go @@ -484,6 +484,29 @@ func ExampleInstancesClient_Reset() { } } +func ExampleInstancesClient_Resume() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResumeInstanceRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#ResumeInstanceRequest. + } + op, err := c.Resume(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + func ExampleInstancesClient_SendDiagnosticInterrupt() { ctx := context.Background() c, err := compute.NewInstancesRESTClient(ctx) @@ -869,6 +892,29 @@ func ExampleInstancesClient_Stop() { } } +func ExampleInstancesClient_Suspend() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SuspendInstanceRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SuspendInstanceRequest. + } + op, err := c.Suspend(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + func ExampleInstancesClient_TestIamPermissions() { ctx := context.Background() c, err := compute.NewInstancesRESTClient(ctx) diff --git a/compute/apiv1/machine_images_client.go b/compute/apiv1/machine_images_client.go new file mode 100644 index 000000000000..82412ccd39e7 --- /dev/null +++ b/compute/apiv1/machine_images_client.go @@ -0,0 +1,675 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "math" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/googleapi" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" +) + +var newMachineImagesClientHook clientHook + +// MachineImagesCallOptions contains the retry settings for each method of MachineImagesClient. +type MachineImagesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalMachineImagesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalMachineImagesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteMachineImageRequest, ...gax.CallOption) (*Operation, error) + Get(context.Context, *computepb.GetMachineImageRequest, ...gax.CallOption) (*computepb.MachineImage, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyMachineImageRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertMachineImageRequest, ...gax.CallOption) (*Operation, error) + List(context.Context, *computepb.ListMachineImagesRequest, ...gax.CallOption) *MachineImageIterator + SetIamPolicy(context.Context, *computepb.SetIamPolicyMachineImageRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsMachineImageRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// MachineImagesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The MachineImages API. +type MachineImagesClient struct { + // The internal transport-dependent client. + internalClient internalMachineImagesClient + + // The call options for this service. + CallOptions *MachineImagesCallOptions +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *MachineImagesClient) Close() error { + return c.internalClient.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *MachineImagesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *MachineImagesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified machine image. Deleting a machine image is permanent and cannot be undone. +func (c *MachineImagesClient) Delete(ctx context.Context, req *computepb.DeleteMachineImageRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified machine image. Gets a list of available machine images by making a list() request. +func (c *MachineImagesClient) Get(ctx context.Context, req *computepb.GetMachineImageRequest, opts ...gax.CallOption) (*computepb.MachineImage, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *MachineImagesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyMachineImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a machine image in the specified project using the data that is included in the request. If you are creating a new machine image to update an existing instance, your new machine image should use the same network or, if applicable, the same subnetwork as the original instance. +func (c *MachineImagesClient) Insert(ctx context.Context, req *computepb.InsertMachineImageRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of machine images that are contained within the specified project. +func (c *MachineImagesClient) List(ctx context.Context, req *computepb.ListMachineImagesRequest, opts ...gax.CallOption) *MachineImageIterator { + return c.internalClient.List(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *MachineImagesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyMachineImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *MachineImagesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsMachineImageRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type machineImagesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // operationClient is used to call the operation-specific management service. + operationClient *GlobalOperationsClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewMachineImagesRESTClient creates a new machine images rest client. +// +// The MachineImages API. +func NewMachineImagesRESTClient(ctx context.Context, opts ...option.ClientOption) (*MachineImagesClient, error) { + clientOpts := append(defaultMachineImagesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &machineImagesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + o := []option.ClientOption{ + option.WithHTTPClient(httpClient), + option.WithEndpoint(endpoint), + } + opC, err := NewGlobalOperationsRESTClient(ctx, o...) + if err != nil { + return nil, err + } + c.operationClient = opC + + return &MachineImagesClient{internalClient: c, CallOptions: &MachineImagesCallOptions{}}, nil +} + +func defaultMachineImagesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("https://compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("https://compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *machineImagesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *machineImagesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + if err := c.operationClient.Close(); err != nil { + return err + } + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *machineImagesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified machine image. Deleting a machine image is permanent and cannot be undone. +func (c *machineImagesRESTClient) Delete(ctx context.Context, req *computepb.DeleteMachineImageRequest, opts ...gax.CallOption) (*Operation, error) { + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages/%v", req.GetProject(), req.GetMachineImage()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &globalOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + }, + } + return op, nil +} + +// Get returns the specified machine image. Gets a list of available machine images by making a list() request. +func (c *machineImagesRESTClient) Get(ctx context.Context, req *computepb.GetMachineImageRequest, opts ...gax.CallOption) (*computepb.MachineImage, error) { + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages/%v", req.GetProject(), req.GetMachineImage()) + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.MachineImage{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + return resp, nil +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *machineImagesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyMachineImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages/%v/getIamPolicy", req.GetProject(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Policy{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + return resp, nil +} + +// Insert creates a machine image in the specified project using the data that is included in the request. If you are creating a new machine image to update an existing instance, your new machine image should use the same network or, if applicable, the same subnetwork as the original instance. +func (c *machineImagesRESTClient) Insert(ctx context.Context, req *computepb.InsertMachineImageRequest, opts ...gax.CallOption) (*Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetMachineImageResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.SourceInstance != nil { + params.Add("sourceInstance", fmt.Sprintf("%v", req.GetSourceInstance())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &globalOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + }, + } + return op, nil +} + +// List retrieves a list of machine images that are contained within the specified project. +func (c *machineImagesRESTClient) List(ctx context.Context, req *computepb.ListMachineImagesRequest, opts ...gax.CallOption) *MachineImageIterator { + it := &MachineImageIterator{} + req = proto.Clone(req).(*computepb.ListMachineImagesRequest) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + it.InternalFetch = func(pageSize int, pageToken string) ([]*computepb.MachineImage, string, error) { + resp := &computepb.MachineImageList{} + if pageToken != "" { + req.PageToken = proto.String(pageToken) + } + if pageSize > math.MaxInt32 { + req.MaxResults = proto.Uint32(math.MaxInt32) + } else if pageSize != 0 { + req.MaxResults = proto.Uint32(uint32(pageSize)) + } + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) + if err != nil { + return err + } + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, "", e + } + it.Response = resp + return resp.GetItems(), resp.GetNextPageToken(), nil + } + + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetMaxResults()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *machineImagesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyMachineImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetGlobalSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages/%v/setIamPolicy", req.GetProject(), req.GetResource()) + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Policy{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + return resp, nil +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *machineImagesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsMachineImageRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/machineImages/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.TestPermissionsResponse{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + return resp, nil +} + +// MachineImageIterator manages a stream of *computepb.MachineImage. +type MachineImageIterator struct { + items []*computepb.MachineImage + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*computepb.MachineImage, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *MachineImageIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *MachineImageIterator) Next() (*computepb.MachineImage, error) { + var item *computepb.MachineImage + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *MachineImageIterator) bufLen() int { + return len(it.items) +} + +func (it *MachineImageIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/compute/apiv1/machine_images_client_example_test.go b/compute/apiv1/machine_images_client_example_test.go new file mode 100644 index 000000000000..31b85f67138b --- /dev/null +++ b/compute/apiv1/machine_images_client_example_test.go @@ -0,0 +1,189 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + "google.golang.org/api/iterator" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewMachineImagesRESTClient() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleMachineImagesClient_Delete() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#DeleteMachineImageRequest. + } + op, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleMachineImagesClient_Get() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#GetMachineImageRequest. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleMachineImagesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#GetIamPolicyMachineImageRequest. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleMachineImagesClient_Insert() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#InsertMachineImageRequest. + } + op, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleMachineImagesClient_List() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListMachineImagesRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#ListMachineImagesRequest. + } + it := c.List(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleMachineImagesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SetIamPolicyMachineImageRequest. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleMachineImagesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#TestIamPermissionsMachineImageRequest. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/projects_client.go b/compute/apiv1/projects_client.go index 279e5bda76e6..168755a7d7f7 100644 --- a/compute/apiv1/projects_client.go +++ b/compute/apiv1/projects_client.go @@ -131,7 +131,7 @@ func (c *ProjectsClient) EnableXpnResource(ctx context.Context, req *computepb.E return c.internalClient.EnableXpnResource(ctx, req, opts...) } -// Get returns the specified Project resource. +// Get returns the specified Project resource. To decrease latency for this method, you can optionally omit any unneeded information from the response by using a field mask. This practice is especially recommended for unused quota information (the quotas field). To exclude one or more fields, set your request’s fields query parameter to only include the fields you need. For example, to only include the id and selfLink fields, add the query parameter ?fields=id,selfLink to your request. func (c *ProjectsClient) Get(ctx context.Context, req *computepb.GetProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) { return c.internalClient.Get(ctx, req, opts...) } @@ -156,7 +156,7 @@ func (c *ProjectsClient) MoveDisk(ctx context.Context, req *computepb.MoveDiskPr return c.internalClient.MoveDisk(ctx, req, opts...) } -// MoveInstance moves an instance and its attached persistent disks from one zone to another. +// MoveInstance moves an instance and its attached persistent disks from one zone to another. Note: Moving VMs or disks by using this method might cause unexpected behavior. For more information, see the known issue (at /compute/docs/troubleshooting/known-issues#moving_vms_or_disks_using_the_moveinstance_api_or_the_causes_unexpected_behavior). func (c *ProjectsClient) MoveInstance(ctx context.Context, req *computepb.MoveInstanceProjectRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.MoveInstance(ctx, req, opts...) } @@ -502,7 +502,7 @@ func (c *projectsRESTClient) EnableXpnResource(ctx context.Context, req *compute return op, nil } -// Get returns the specified Project resource. +// Get returns the specified Project resource. To decrease latency for this method, you can optionally omit any unneeded information from the response by using a field mask. This practice is especially recommended for unused quota information (the quotas field). To exclude one or more fields, set your request’s fields query parameter to only include the fields you need. For example, to only include the id and selfLink fields, add the query parameter ?fields=id,selfLink to your request. func (c *projectsRESTClient) Get(ctx context.Context, req *computepb.GetProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) { baseUrl, _ := url.Parse(c.endpoint) baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v", req.GetProject()) @@ -841,7 +841,7 @@ func (c *projectsRESTClient) MoveDisk(ctx context.Context, req *computepb.MoveDi return op, nil } -// MoveInstance moves an instance and its attached persistent disks from one zone to another. +// MoveInstance moves an instance and its attached persistent disks from one zone to another. Note: Moving VMs or disks by using this method might cause unexpected behavior. For more information, see the known issue (at /compute/docs/troubleshooting/known-issues#moving_vms_or_disks_using_the_moveinstance_api_or_the_causes_unexpected_behavior). func (c *projectsRESTClient) MoveInstance(ctx context.Context, req *computepb.MoveInstanceProjectRequest, opts ...gax.CallOption) (*Operation, error) { m := protojson.MarshalOptions{AllowPartial: true} body := req.GetInstanceMoveRequestResource() diff --git a/compute/apiv1/region_commitments_client.go b/compute/apiv1/region_commitments_client.go index c868fc1da34b..77d5262d9d81 100644 --- a/compute/apiv1/region_commitments_client.go +++ b/compute/apiv1/region_commitments_client.go @@ -47,6 +47,7 @@ type RegionCommitmentsCallOptions struct { Get []gax.CallOption Insert []gax.CallOption List []gax.CallOption + Update []gax.CallOption } // internalRegionCommitmentsClient is an interface that defines the methods availaible from Google Compute Engine API. @@ -58,6 +59,7 @@ type internalRegionCommitmentsClient interface { Get(context.Context, *computepb.GetRegionCommitmentRequest, ...gax.CallOption) (*computepb.Commitment, error) Insert(context.Context, *computepb.InsertRegionCommitmentRequest, ...gax.CallOption) (*Operation, error) List(context.Context, *computepb.ListRegionCommitmentsRequest, ...gax.CallOption) *CommitmentIterator + Update(context.Context, *computepb.UpdateRegionCommitmentRequest, ...gax.CallOption) (*Operation, error) } // RegionCommitmentsClient is a client for interacting with Google Compute Engine API. @@ -114,6 +116,11 @@ func (c *RegionCommitmentsClient) List(ctx context.Context, req *computepb.ListR return c.internalClient.List(ctx, req, opts...) } +// Update updates the specified commitment with the data included in the request. Update is performed only on selected fields included as part of update-mask. Only the following fields can be modified: auto_renew. +func (c *RegionCommitmentsClient) Update(ctx context.Context, req *computepb.UpdateRegionCommitmentRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. type regionCommitmentsRESTClient struct { // The http endpoint to connect to. @@ -494,6 +501,78 @@ func (c *regionCommitmentsRESTClient) List(ctx context.Context, req *computepb.L return it } +// Update updates the specified commitment with the data included in the request. Update is performed only on selected fields included as part of update-mask. Only the following fields can be modified: auto_renew. +func (c *regionCommitmentsRESTClient) Update(ctx context.Context, req *computepb.UpdateRegionCommitmentRequest, opts ...gax.CallOption) (*Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetCommitmentResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/commitments/%v", req.GetProject(), req.GetRegion(), req.GetCommitment()) + + params := url.Values{} + if req != nil && req.Paths != nil { + params.Add("paths", fmt.Sprintf("%v", req.GetPaths())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.UpdateMask != nil { + params.Add("updateMask", fmt.Sprintf("%v", req.GetUpdateMask())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + ®ionOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + region: req.GetRegion(), + }, + } + return op, nil +} + // CommitmentIterator manages a stream of *computepb.Commitment. type CommitmentIterator struct { items []*computepb.Commitment diff --git a/compute/apiv1/region_commitments_client_example_test.go b/compute/apiv1/region_commitments_client_example_test.go index 0e3747f9a10c..1b7ab080c79c 100644 --- a/compute/apiv1/region_commitments_client_example_test.go +++ b/compute/apiv1/region_commitments_client_example_test.go @@ -130,3 +130,26 @@ func ExampleRegionCommitmentsClient_List() { _ = resp } } + +func ExampleRegionCommitmentsClient_Update() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRegionCommitmentRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#UpdateRegionCommitmentRequest. + } + op, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/compute/apiv1/region_disks_client.go b/compute/apiv1/region_disks_client.go index ca8bdd9e5618..2a750fdc5ce3 100644 --- a/compute/apiv1/region_disks_client.go +++ b/compute/apiv1/region_disks_client.go @@ -114,7 +114,7 @@ func (c *RegionDisksClient) AddResourcePolicies(ctx context.Context, req *comput return c.internalClient.AddResourcePolicies(ctx, req, opts...) } -// CreateSnapshot creates a snapshot of this regional disk. +// CreateSnapshot creates a snapshot of a specified persistent disk. For regular snapshot creation, consider using snapshots.insert instead, as that method supports more features, such as creating snapshots in a project different from the source disk project. func (c *RegionDisksClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotRegionDiskRequest, opts ...gax.CallOption) (*Operation, error) { return c.internalClient.CreateSnapshot(ctx, req, opts...) } @@ -315,7 +315,7 @@ func (c *regionDisksRESTClient) AddResourcePolicies(ctx context.Context, req *co return op, nil } -// CreateSnapshot creates a snapshot of this regional disk. +// CreateSnapshot creates a snapshot of a specified persistent disk. For regular snapshot creation, consider using snapshots.insert instead, as that method supports more features, such as creating snapshots in a project different from the source disk project. func (c *regionDisksRESTClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotRegionDiskRequest, opts ...gax.CallOption) (*Operation, error) { m := protojson.MarshalOptions{AllowPartial: true} body := req.GetSnapshotResource() diff --git a/compute/apiv1/regions_client.go b/compute/apiv1/regions_client.go index a0e9d6e96f91..43be4557a6a2 100644 --- a/compute/apiv1/regions_client.go +++ b/compute/apiv1/regions_client.go @@ -88,12 +88,12 @@ func (c *RegionsClient) Connection() *grpc.ClientConn { return c.internalClient.Connection() } -// Get returns the specified Region resource. Gets a list of available regions by making a list() request. +// Get returns the specified Region resource. Gets a list of available regions by making a list() request. To decrease latency for this method, you can optionally omit any unneeded information from the response by using a field mask. This practice is especially recommended for unused quota information (the quotas field). To exclude one or more fields, set your request’s fields query parameter to only include the fields you need. For example, to only include the id and selfLink fields, add the query parameter ?fields=id,selfLink to your request. func (c *RegionsClient) Get(ctx context.Context, req *computepb.GetRegionRequest, opts ...gax.CallOption) (*computepb.Region, error) { return c.internalClient.Get(ctx, req, opts...) } -// List retrieves the list of region resources available to the specified project. +// List retrieves the list of region resources available to the specified project. To decrease latency for this method, you can optionally omit any unneeded information from the response by using a field mask. This practice is especially recommended for unused quota information (the items.quotas field). To exclude one or more fields, set your request’s fields query parameter to only include the fields you need. For example, to only include the id and selfLink fields, add the query parameter ?fields=id,selfLink to your request. func (c *RegionsClient) List(ctx context.Context, req *computepb.ListRegionsRequest, opts ...gax.CallOption) *RegionIterator { return c.internalClient.List(ctx, req, opts...) } @@ -162,7 +162,7 @@ func (c *regionsRESTClient) Connection() *grpc.ClientConn { return nil } -// Get returns the specified Region resource. Gets a list of available regions by making a list() request. +// Get returns the specified Region resource. Gets a list of available regions by making a list() request. To decrease latency for this method, you can optionally omit any unneeded information from the response by using a field mask. This practice is especially recommended for unused quota information (the quotas field). To exclude one or more fields, set your request’s fields query parameter to only include the fields you need. For example, to only include the id and selfLink fields, add the query parameter ?fields=id,selfLink to your request. func (c *regionsRESTClient) Get(ctx context.Context, req *computepb.GetRegionRequest, opts ...gax.CallOption) (*computepb.Region, error) { baseUrl, _ := url.Parse(c.endpoint) baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v", req.GetProject(), req.GetRegion()) @@ -206,7 +206,7 @@ func (c *regionsRESTClient) Get(ctx context.Context, req *computepb.GetRegionReq return resp, nil } -// List retrieves the list of region resources available to the specified project. +// List retrieves the list of region resources available to the specified project. To decrease latency for this method, you can optionally omit any unneeded information from the response by using a field mask. This practice is especially recommended for unused quota information (the items.quotas field). To exclude one or more fields, set your request’s fields query parameter to only include the fields you need. For example, to only include the id and selfLink fields, add the query parameter ?fields=id,selfLink to your request. func (c *regionsRESTClient) List(ctx context.Context, req *computepb.ListRegionsRequest, opts ...gax.CallOption) *RegionIterator { it := &RegionIterator{} req = proto.Clone(req).(*computepb.ListRegionsRequest) diff --git a/compute/apiv1/reservations_client.go b/compute/apiv1/reservations_client.go index 00a2acaf4a55..2da53792dab4 100644 --- a/compute/apiv1/reservations_client.go +++ b/compute/apiv1/reservations_client.go @@ -52,6 +52,7 @@ type ReservationsCallOptions struct { Resize []gax.CallOption SetIamPolicy []gax.CallOption TestIamPermissions []gax.CallOption + Update []gax.CallOption } // internalReservationsClient is an interface that defines the methods availaible from Google Compute Engine API. @@ -68,6 +69,7 @@ type internalReservationsClient interface { Resize(context.Context, *computepb.ResizeReservationRequest, ...gax.CallOption) (*Operation, error) SetIamPolicy(context.Context, *computepb.SetIamPolicyReservationRequest, ...gax.CallOption) (*computepb.Policy, error) TestIamPermissions(context.Context, *computepb.TestIamPermissionsReservationRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) + Update(context.Context, *computepb.UpdateReservationRequest, ...gax.CallOption) (*Operation, error) } // ReservationsClient is a client for interacting with Google Compute Engine API. @@ -149,6 +151,11 @@ func (c *ReservationsClient) TestIamPermissions(ctx context.Context, req *comput return c.internalClient.TestIamPermissions(ctx, req, opts...) } +// Update update share settings of the reservation. +func (c *ReservationsClient) Update(ctx context.Context, req *computepb.UpdateReservationRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. type reservationsRESTClient struct { // The http endpoint to connect to. @@ -807,6 +814,78 @@ func (c *reservationsRESTClient) TestIamPermissions(ctx context.Context, req *co return resp, nil } +// Update update share settings of the reservation. +func (c *reservationsRESTClient) Update(ctx context.Context, req *computepb.UpdateReservationRequest, opts ...gax.CallOption) (*Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetReservationResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v", req.GetProject(), req.GetZone(), req.GetReservation()) + + params := url.Values{} + if req != nil && req.Paths != nil { + params.Add("paths", fmt.Sprintf("%v", req.GetPaths())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.UpdateMask != nil { + params.Add("updateMask", fmt.Sprintf("%v", req.GetUpdateMask())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &zoneOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + zone: req.GetZone(), + }, + } + return op, nil +} + // ReservationIterator manages a stream of *computepb.Reservation. type ReservationIterator struct { items []*computepb.Reservation diff --git a/compute/apiv1/reservations_client_example_test.go b/compute/apiv1/reservations_client_example_test.go index 89a78d5c2565..d8f42abb275b 100644 --- a/compute/apiv1/reservations_client_example_test.go +++ b/compute/apiv1/reservations_client_example_test.go @@ -236,3 +236,26 @@ func ExampleReservationsClient_TestIamPermissions() { // TODO: Use resp. _ = resp } + +func ExampleReservationsClient_Update() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateReservationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#UpdateReservationRequest. + } + op, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/compute/apiv1/snapshots_client.go b/compute/apiv1/snapshots_client.go index b4aa951902bf..bc04ca9ba222 100644 --- a/compute/apiv1/snapshots_client.go +++ b/compute/apiv1/snapshots_client.go @@ -45,6 +45,7 @@ type SnapshotsCallOptions struct { Delete []gax.CallOption Get []gax.CallOption GetIamPolicy []gax.CallOption + Insert []gax.CallOption List []gax.CallOption SetIamPolicy []gax.CallOption SetLabels []gax.CallOption @@ -59,6 +60,7 @@ type internalSnapshotsClient interface { Delete(context.Context, *computepb.DeleteSnapshotRequest, ...gax.CallOption) (*Operation, error) Get(context.Context, *computepb.GetSnapshotRequest, ...gax.CallOption) (*computepb.Snapshot, error) GetIamPolicy(context.Context, *computepb.GetIamPolicySnapshotRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertSnapshotRequest, ...gax.CallOption) (*Operation, error) List(context.Context, *computepb.ListSnapshotsRequest, ...gax.CallOption) *SnapshotIterator SetIamPolicy(context.Context, *computepb.SetIamPolicySnapshotRequest, ...gax.CallOption) (*computepb.Policy, error) SetLabels(context.Context, *computepb.SetLabelsSnapshotRequest, ...gax.CallOption) (*Operation, error) @@ -114,6 +116,11 @@ func (c *SnapshotsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIa return c.internalClient.GetIamPolicy(ctx, req, opts...) } +// Insert creates a snapshot in the specified project using the data included in the request. For regular snapshot creation, consider using this method instead of disks.createSnapshot, as this method supports more features, such as creating snapshots in a project different from the source disk project. +func (c *SnapshotsClient) Insert(ctx context.Context, req *computepb.InsertSnapshotRequest, opts ...gax.CallOption) (*Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + // List retrieves the list of Snapshot resources contained within the specified project. func (c *SnapshotsClient) List(ctx context.Context, req *computepb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator { return c.internalClient.List(ctx, req, opts...) @@ -367,6 +374,71 @@ func (c *snapshotsRESTClient) GetIamPolicy(ctx context.Context, req *computepb.G return resp, nil } +// Insert creates a snapshot in the specified project using the data included in the request. For regular snapshot creation, consider using this method instead of disks.createSnapshot, as this method supports more features, such as creating snapshots in a project different from the source disk project. +func (c *snapshotsRESTClient) Insert(ctx context.Context, req *computepb.InsertSnapshotRequest, opts ...gax.CallOption) (*Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true} + body := req.GetSnapshotResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + // Build HTTP headers from client and context metadata. + headers := buildHeaders(ctx, c.xGoogMetadata, metadata.Pairs("Content-Type", "application/json")) + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + resp := &computepb.Operation{} + e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return err + } + httpReq = httpReq.WithContext(ctx) + httpReq.Header = headers + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return err + } + defer httpRsp.Body.Close() + + if err = googleapi.CheckResponse(httpRsp); err != nil { + return err + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return err + } + + if err := unm.Unmarshal(buf, resp); err != nil { + return maybeUnknownEnum(err) + } + + return nil + }, opts...) + if e != nil { + return nil, e + } + op := &Operation{ + &globalOperationsHandle{ + c: c.operationClient, + proto: resp, + project: req.GetProject(), + }, + } + return op, nil +} + // List retrieves the list of Snapshot resources contained within the specified project. func (c *snapshotsRESTClient) List(ctx context.Context, req *computepb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator { it := &SnapshotIterator{} diff --git a/compute/apiv1/snapshots_client_example_test.go b/compute/apiv1/snapshots_client_example_test.go index 366470813457..091e8b114806 100644 --- a/compute/apiv1/snapshots_client_example_test.go +++ b/compute/apiv1/snapshots_client_example_test.go @@ -99,6 +99,29 @@ func ExampleSnapshotsClient_GetIamPolicy() { _ = resp } +func ExampleSnapshotsClient_Insert() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertSnapshotRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#InsertSnapshotRequest. + } + op, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + func ExampleSnapshotsClient_List() { ctx := context.Background() c, err := compute.NewSnapshotsRESTClient(ctx) diff --git a/dataplex/apiv1/doc.go b/dataplex/apiv1/doc.go index 2926539b8ffc..a3f6da14a009 100644 --- a/dataplex/apiv1/doc.go +++ b/dataplex/apiv1/doc.go @@ -86,7 +86,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index a41f86f351bc..24d57bae7321 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -964,7 +964,7 @@ }, "cloud.google.com/go/osconfig/agentendpoint/apiv1beta": { "distribution_name": "cloud.google.com/go/osconfig/agentendpoint/apiv1beta", - "description": "Cloud OS Config API", + "description": "OS Config API", "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/osconfig/latest/agentendpoint/apiv1beta", diff --git a/internal/generated/snippets/compute/apiv1/BackendBucketsClient/SetEdgeSecurityPolicy/main.go b/internal/generated/snippets/compute/apiv1/BackendBucketsClient/SetEdgeSecurityPolicy/main.go new file mode 100644 index 000000000000..bc8e589a25bf --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/BackendBucketsClient/SetEdgeSecurityPolicy/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_BackendBuckets_SetEdgeSecurityPolicy_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetEdgeSecurityPolicyBackendBucketRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SetEdgeSecurityPolicyBackendBucketRequest. + } + op, err := c.SetEdgeSecurityPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_BackendBuckets_SetEdgeSecurityPolicy_sync] diff --git a/internal/generated/snippets/compute/apiv1/BackendServicesClient/SetEdgeSecurityPolicy/main.go b/internal/generated/snippets/compute/apiv1/BackendServicesClient/SetEdgeSecurityPolicy/main.go new file mode 100644 index 000000000000..0aefe807248b --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/BackendServicesClient/SetEdgeSecurityPolicy/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_BackendServices_SetEdgeSecurityPolicy_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetEdgeSecurityPolicyBackendServiceRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SetEdgeSecurityPolicyBackendServiceRequest. + } + op, err := c.SetEdgeSecurityPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_BackendServices_SetEdgeSecurityPolicy_sync] diff --git a/internal/generated/snippets/compute/apiv1/InstancesClient/Resume/main.go b/internal/generated/snippets/compute/apiv1/InstancesClient/Resume/main.go new file mode 100644 index 000000000000..7bdf682915a9 --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/InstancesClient/Resume/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_Instances_Resume_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResumeInstanceRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#ResumeInstanceRequest. + } + op, err := c.Resume(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_Instances_Resume_sync] diff --git a/internal/generated/snippets/compute/apiv1/InstancesClient/Suspend/main.go b/internal/generated/snippets/compute/apiv1/InstancesClient/Suspend/main.go new file mode 100644 index 000000000000..20b7edffefab --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/InstancesClient/Suspend/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_Instances_Suspend_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SuspendInstanceRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SuspendInstanceRequest. + } + op, err := c.Suspend(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_Instances_Suspend_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/Delete/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/Delete/main.go new file mode 100644 index 000000000000..69928ceeed0b --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/Delete/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_Delete_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#DeleteMachineImageRequest. + } + op, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_MachineImages_Delete_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/Get/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/Get/main.go new file mode 100644 index 000000000000..6707bdd5e104 --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/Get/main.go @@ -0,0 +1,48 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_Get_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#GetMachineImageRequest. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END compute_v1_generated_MachineImages_Get_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/GetIamPolicy/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/GetIamPolicy/main.go new file mode 100644 index 000000000000..c636110f0952 --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/GetIamPolicy/main.go @@ -0,0 +1,48 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_GetIamPolicy_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#GetIamPolicyMachineImageRequest. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END compute_v1_generated_MachineImages_GetIamPolicy_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/Insert/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/Insert/main.go new file mode 100644 index 000000000000..f4a2aebe147b --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/Insert/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_Insert_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#InsertMachineImageRequest. + } + op, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_MachineImages_Insert_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/List/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/List/main.go new file mode 100644 index 000000000000..b29c23e54654 --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/List/main.go @@ -0,0 +1,55 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_List_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + "google.golang.org/api/iterator" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListMachineImagesRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#ListMachineImagesRequest. + } + it := c.List(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END compute_v1_generated_MachineImages_List_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/SetIamPolicy/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/SetIamPolicy/main.go new file mode 100644 index 000000000000..f8d361216681 --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/SetIamPolicy/main.go @@ -0,0 +1,48 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_SetIamPolicy_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#SetIamPolicyMachineImageRequest. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END compute_v1_generated_MachineImages_SetIamPolicy_sync] diff --git a/internal/generated/snippets/compute/apiv1/MachineImagesClient/TestIamPermissions/main.go b/internal/generated/snippets/compute/apiv1/MachineImagesClient/TestIamPermissions/main.go new file mode 100644 index 000000000000..800cac3436ed --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/MachineImagesClient/TestIamPermissions/main.go @@ -0,0 +1,48 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_MachineImages_TestIamPermissions_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewMachineImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsMachineImageRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#TestIamPermissionsMachineImageRequest. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END compute_v1_generated_MachineImages_TestIamPermissions_sync] diff --git a/internal/generated/snippets/compute/apiv1/RegionCommitmentsClient/Update/main.go b/internal/generated/snippets/compute/apiv1/RegionCommitmentsClient/Update/main.go new file mode 100644 index 000000000000..a14ea49783be --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/RegionCommitmentsClient/Update/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_RegionCommitments_Update_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRegionCommitmentRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#UpdateRegionCommitmentRequest. + } + op, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_RegionCommitments_Update_sync] diff --git a/internal/generated/snippets/compute/apiv1/ReservationsClient/Update/main.go b/internal/generated/snippets/compute/apiv1/ReservationsClient/Update/main.go new file mode 100644 index 000000000000..21c36de5ca5f --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/ReservationsClient/Update/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_Reservations_Update_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateReservationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#UpdateReservationRequest. + } + op, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_Reservations_Update_sync] diff --git a/internal/generated/snippets/compute/apiv1/SnapshotsClient/Insert/main.go b/internal/generated/snippets/compute/apiv1/SnapshotsClient/Insert/main.go new file mode 100644 index 000000000000..bdc04a65df6c --- /dev/null +++ b/internal/generated/snippets/compute/apiv1/SnapshotsClient/Insert/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START compute_v1_generated_Snapshots_Insert_sync] + +package main + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func main() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertSnapshotRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/compute/v1#InsertSnapshotRequest. + } + op, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END compute_v1_generated_Snapshots_Insert_sync] diff --git a/internal/generated/snippets/go.mod b/internal/generated/snippets/go.mod index 726171d134ba..bbddbaaa141d 100644 --- a/internal/generated/snippets/go.mod +++ b/internal/generated/snippets/go.mod @@ -112,7 +112,7 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect google.golang.org/api v0.68.0 - google.golang.org/genproto v0.0.0-20220210181026-6fee9acbd336 + google.golang.org/genproto v0.0.0-20220211171837-173942840c17 ) replace cloud.google.com/go/storagetransfer => ../../../storagetransfer diff --git a/internal/generated/snippets/go.sum b/internal/generated/snippets/go.sum index 6c3376e4d1c7..a3cc3fc44bfb 100644 --- a/internal/generated/snippets/go.sum +++ b/internal/generated/snippets/go.sum @@ -168,8 +168,9 @@ google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ6 google.golang.org/genproto v0.0.0-20220204002441-d6cc3cc0770e/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20220207164111-0872dc986b00/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20220208230804-65c12eb4c068/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= -google.golang.org/genproto v0.0.0-20220210181026-6fee9acbd336 h1:RK2ysGpQApbI6U7xn+ROT2rrm08lE/t8AcGqG8XI1CY= google.golang.org/genproto v0.0.0-20220210181026-6fee9acbd336/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= +google.golang.org/genproto v0.0.0-20220211171837-173942840c17 h1:2X+CNIheCutWRyKRte8szGxrE5ggtV4U+NKAbh/oLhg= +google.golang.org/genproto v0.0.0-20220211171837-173942840c17/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/internal/generated/snippets/osconfig/apiv1alpha/OsConfigZonalClient/GetOSPolicyAssignmentReport/main.go b/internal/generated/snippets/osconfig/apiv1alpha/OsConfigZonalClient/GetOSPolicyAssignmentReport/main.go new file mode 100644 index 000000000000..ef2c673ad2c2 --- /dev/null +++ b/internal/generated/snippets/osconfig/apiv1alpha/OsConfigZonalClient/GetOSPolicyAssignmentReport/main.go @@ -0,0 +1,48 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START osconfig_v1alpha_generated_OsConfigZonalService_GetOSPolicyAssignmentReport_sync] + +package main + +import ( + "context" + + osconfig "cloud.google.com/go/osconfig/apiv1alpha" + osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" +) + +func main() { + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &osconfigpb.GetOSPolicyAssignmentReportRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha#GetOSPolicyAssignmentReportRequest. + } + resp, err := c.GetOSPolicyAssignmentReport(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END osconfig_v1alpha_generated_OsConfigZonalService_GetOSPolicyAssignmentReport_sync] diff --git a/internal/generated/snippets/osconfig/apiv1alpha/OsConfigZonalClient/ListOSPolicyAssignmentReports/main.go b/internal/generated/snippets/osconfig/apiv1alpha/OsConfigZonalClient/ListOSPolicyAssignmentReports/main.go new file mode 100644 index 000000000000..b52397f0252a --- /dev/null +++ b/internal/generated/snippets/osconfig/apiv1alpha/OsConfigZonalClient/ListOSPolicyAssignmentReports/main.go @@ -0,0 +1,55 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START osconfig_v1alpha_generated_OsConfigZonalService_ListOSPolicyAssignmentReports_sync] + +package main + +import ( + "context" + + osconfig "cloud.google.com/go/osconfig/apiv1alpha" + "google.golang.org/api/iterator" + osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" +) + +func main() { + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &osconfigpb.ListOSPolicyAssignmentReportsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha#ListOSPolicyAssignmentReportsRequest. + } + it := c.ListOSPolicyAssignmentReports(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END osconfig_v1alpha_generated_OsConfigZonalService_ListOSPolicyAssignmentReports_sync] diff --git a/osconfig/agentendpoint/apiv1/doc.go b/osconfig/agentendpoint/apiv1/doc.go index d31fea24b920..6c9d604afe75 100644 --- a/osconfig/agentendpoint/apiv1/doc.go +++ b/osconfig/agentendpoint/apiv1/doc.go @@ -67,7 +67,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go b/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go index b98e429deb42..966b0b52d60f 100644 --- a/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go +++ b/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go @@ -130,7 +130,7 @@ func defaultCallOptions() *CallOptions { } } -// internalClient is an interface that defines the methods availaible from Cloud OS Config API. +// internalClient is an interface that defines the methods availaible from OS Config API. type internalClient interface { Close() error setGoogleClientInfo(...string) @@ -143,7 +143,7 @@ type internalClient interface { RegisterAgent(context.Context, *agentendpointpb.RegisterAgentRequest, ...gax.CallOption) (*agentendpointpb.RegisterAgentResponse, error) } -// Client is a client for interacting with Cloud OS Config API. +// Client is a client for interacting with OS Config API. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. // // OS Config agent endpoint API. @@ -209,7 +209,7 @@ func (c *Client) RegisterAgent(ctx context.Context, req *agentendpointpb.Registe return c.internalClient.RegisterAgent(ctx, req, opts...) } -// gRPCClient is a client for interacting with Cloud OS Config API over gRPC transport. +// gRPCClient is a client for interacting with OS Config API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. type gRPCClient struct { diff --git a/osconfig/agentendpoint/apiv1beta/doc.go b/osconfig/agentendpoint/apiv1beta/doc.go index beab2c728cc2..2eebd2236865 100644 --- a/osconfig/agentendpoint/apiv1beta/doc.go +++ b/osconfig/agentendpoint/apiv1beta/doc.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go_gapic. DO NOT EDIT. // Package agentendpoint is an auto-generated package for the -// Cloud OS Config API. +// OS Config API. // // OS management tools that can be used for patch management, patch // compliance, and configuration management on VM instances. @@ -69,7 +69,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/apiv1alpha/doc.go b/osconfig/apiv1alpha/doc.go index 0b49a3342046..399565018ad6 100644 --- a/osconfig/apiv1alpha/doc.go +++ b/osconfig/apiv1alpha/doc.go @@ -92,7 +92,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/apiv1alpha/gapic_metadata.json b/osconfig/apiv1alpha/gapic_metadata.json index 68645256d0c3..8edd40fe520c 100644 --- a/osconfig/apiv1alpha/gapic_metadata.json +++ b/osconfig/apiv1alpha/gapic_metadata.json @@ -35,6 +35,11 @@ "GetOSPolicyAssignment" ] }, + "GetOSPolicyAssignmentReport": { + "methods": [ + "GetOSPolicyAssignmentReport" + ] + }, "GetVulnerabilityReport": { "methods": [ "GetVulnerabilityReport" @@ -50,6 +55,11 @@ "ListInventories" ] }, + "ListOSPolicyAssignmentReports": { + "methods": [ + "ListOSPolicyAssignmentReports" + ] + }, "ListOSPolicyAssignmentRevisions": { "methods": [ "ListOSPolicyAssignmentRevisions" diff --git a/osconfig/apiv1alpha/os_config_zonal_client.go b/osconfig/apiv1alpha/os_config_zonal_client.go index 2cbc8b8c3df1..377aae70714b 100644 --- a/osconfig/apiv1alpha/os_config_zonal_client.go +++ b/osconfig/apiv1alpha/os_config_zonal_client.go @@ -50,6 +50,8 @@ type OsConfigZonalCallOptions struct { DeleteOSPolicyAssignment []gax.CallOption GetInstanceOSPoliciesCompliance []gax.CallOption ListInstanceOSPoliciesCompliances []gax.CallOption + GetOSPolicyAssignmentReport []gax.CallOption + ListOSPolicyAssignmentReports []gax.CallOption GetInventory []gax.CallOption ListInventories []gax.CallOption GetVulnerabilityReport []gax.CallOption @@ -158,6 +160,28 @@ func defaultOsConfigZonalCallOptions() *OsConfigZonalCallOptions { }) }), }, + GetOSPolicyAssignmentReport: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListOSPolicyAssignmentReports: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, GetInventory: []gax.CallOption{ gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ @@ -221,6 +245,8 @@ type internalOsConfigZonalClient interface { DeleteOSPolicyAssignmentOperation(name string) *DeleteOSPolicyAssignmentOperation GetInstanceOSPoliciesCompliance(context.Context, *osconfigpb.GetInstanceOSPoliciesComplianceRequest, ...gax.CallOption) (*osconfigpb.InstanceOSPoliciesCompliance, error) ListInstanceOSPoliciesCompliances(context.Context, *osconfigpb.ListInstanceOSPoliciesCompliancesRequest, ...gax.CallOption) *InstanceOSPoliciesComplianceIterator + GetOSPolicyAssignmentReport(context.Context, *osconfigpb.GetOSPolicyAssignmentReportRequest, ...gax.CallOption) (*osconfigpb.OSPolicyAssignmentReport, error) + ListOSPolicyAssignmentReports(context.Context, *osconfigpb.ListOSPolicyAssignmentReportsRequest, ...gax.CallOption) *OSPolicyAssignmentReportIterator GetInventory(context.Context, *osconfigpb.GetInventoryRequest, ...gax.CallOption) (*osconfigpb.Inventory, error) ListInventories(context.Context, *osconfigpb.ListInventoriesRequest, ...gax.CallOption) *InventoryIterator GetVulnerabilityReport(context.Context, *osconfigpb.GetVulnerabilityReportRequest, ...gax.CallOption) (*osconfigpb.VulnerabilityReport, error) @@ -352,16 +378,32 @@ func (c *OsConfigZonalClient) DeleteOSPolicyAssignmentOperation(name string) *De // GetInstanceOSPoliciesCompliance get OS policies compliance data for the specified Compute Engine VM // instance. +// +// Deprecated: GetInstanceOSPoliciesCompliance may be removed in a future version. func (c *OsConfigZonalClient) GetInstanceOSPoliciesCompliance(ctx context.Context, req *osconfigpb.GetInstanceOSPoliciesComplianceRequest, opts ...gax.CallOption) (*osconfigpb.InstanceOSPoliciesCompliance, error) { return c.internalClient.GetInstanceOSPoliciesCompliance(ctx, req, opts...) } // ListInstanceOSPoliciesCompliances list OS policies compliance data for all Compute Engine VM instances in the // specified zone. +// +// Deprecated: ListInstanceOSPoliciesCompliances may be removed in a future version. func (c *OsConfigZonalClient) ListInstanceOSPoliciesCompliances(ctx context.Context, req *osconfigpb.ListInstanceOSPoliciesCompliancesRequest, opts ...gax.CallOption) *InstanceOSPoliciesComplianceIterator { return c.internalClient.ListInstanceOSPoliciesCompliances(ctx, req, opts...) } +// GetOSPolicyAssignmentReport get the OS policy asssignment report for the specified Compute Engine VM +// instance. +func (c *OsConfigZonalClient) GetOSPolicyAssignmentReport(ctx context.Context, req *osconfigpb.GetOSPolicyAssignmentReportRequest, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignmentReport, error) { + return c.internalClient.GetOSPolicyAssignmentReport(ctx, req, opts...) +} + +// ListOSPolicyAssignmentReports list OS policy asssignment reports for all Compute Engine VM instances in +// the specified zone. +func (c *OsConfigZonalClient) ListOSPolicyAssignmentReports(ctx context.Context, req *osconfigpb.ListOSPolicyAssignmentReportsRequest, opts ...gax.CallOption) *OSPolicyAssignmentReportIterator { + return c.internalClient.ListOSPolicyAssignmentReports(ctx, req, opts...) +} + // GetInventory get inventory data for the specified VM instance. If the VM has no // associated inventory, the message NOT_FOUND is returned. func (c *OsConfigZonalClient) GetInventory(ctx context.Context, req *osconfigpb.GetInventoryRequest, opts ...gax.CallOption) (*osconfigpb.Inventory, error) { @@ -726,6 +768,71 @@ func (c *osConfigZonalGRPCClient) ListInstanceOSPoliciesCompliances(ctx context. return it } +func (c *osConfigZonalGRPCClient) GetOSPolicyAssignmentReport(ctx context.Context, req *osconfigpb.GetOSPolicyAssignmentReportRequest, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignmentReport, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOSPolicyAssignmentReport[0:len((*c.CallOptions).GetOSPolicyAssignmentReport):len((*c.CallOptions).GetOSPolicyAssignmentReport)], opts...) + var resp *osconfigpb.OSPolicyAssignmentReport + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.GetOSPolicyAssignmentReport(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *osConfigZonalGRPCClient) ListOSPolicyAssignmentReports(ctx context.Context, req *osconfigpb.ListOSPolicyAssignmentReportsRequest, opts ...gax.CallOption) *OSPolicyAssignmentReportIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOSPolicyAssignmentReports[0:len((*c.CallOptions).ListOSPolicyAssignmentReports):len((*c.CallOptions).ListOSPolicyAssignmentReports)], opts...) + it := &OSPolicyAssignmentReportIterator{} + req = proto.Clone(req).(*osconfigpb.ListOSPolicyAssignmentReportsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*osconfigpb.OSPolicyAssignmentReport, string, error) { + resp := &osconfigpb.ListOSPolicyAssignmentReportsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.ListOSPolicyAssignmentReports(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOsPolicyAssignmentReports(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + func (c *osConfigZonalGRPCClient) GetInventory(ctx context.Context, req *osconfigpb.GetInventoryRequest, opts ...gax.CallOption) (*osconfigpb.Inventory, error) { if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) @@ -1193,6 +1300,53 @@ func (it *OSPolicyAssignmentIterator) takeBuf() interface{} { return b } +// OSPolicyAssignmentReportIterator manages a stream of *osconfigpb.OSPolicyAssignmentReport. +type OSPolicyAssignmentReportIterator struct { + items []*osconfigpb.OSPolicyAssignmentReport + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*osconfigpb.OSPolicyAssignmentReport, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *OSPolicyAssignmentReportIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *OSPolicyAssignmentReportIterator) Next() (*osconfigpb.OSPolicyAssignmentReport, error) { + var item *osconfigpb.OSPolicyAssignmentReport + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *OSPolicyAssignmentReportIterator) bufLen() int { + return len(it.items) +} + +func (it *OSPolicyAssignmentReportIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + // VulnerabilityReportIterator manages a stream of *osconfigpb.VulnerabilityReport. type VulnerabilityReportIterator struct { items []*osconfigpb.VulnerabilityReport diff --git a/osconfig/apiv1alpha/os_config_zonal_client_example_test.go b/osconfig/apiv1alpha/os_config_zonal_client_example_test.go index 8931e80e158d..f66e58cc4e33 100644 --- a/osconfig/apiv1alpha/os_config_zonal_client_example_test.go +++ b/osconfig/apiv1alpha/os_config_zonal_client_example_test.go @@ -227,6 +227,52 @@ func ExampleOsConfigZonalClient_ListInstanceOSPoliciesCompliances() { } } +func ExampleOsConfigZonalClient_GetOSPolicyAssignmentReport() { + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &osconfigpb.GetOSPolicyAssignmentReportRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha#GetOSPolicyAssignmentReportRequest. + } + resp, err := c.GetOSPolicyAssignmentReport(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_ListOSPolicyAssignmentReports() { + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &osconfigpb.ListOSPolicyAssignmentReportsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha#ListOSPolicyAssignmentReportsRequest. + } + it := c.ListOSPolicyAssignmentReports(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + func ExampleOsConfigZonalClient_GetInventory() { ctx := context.Background() c, err := osconfig.NewOsConfigZonalClient(ctx) diff --git a/pubsub/apiv1/doc.go b/pubsub/apiv1/doc.go index 0a3f2c94d8bc..3af1a33baf76 100644 --- a/pubsub/apiv1/doc.go +++ b/pubsub/apiv1/doc.go @@ -85,7 +85,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/security/privateca/apiv1/doc.go b/security/privateca/apiv1/doc.go index 8e9ce3f14128..f01f757b9805 100644 --- a/security/privateca/apiv1/doc.go +++ b/security/privateca/apiv1/doc.go @@ -87,7 +87,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/servicemanagement/apiv1/doc.go b/servicemanagement/apiv1/doc.go index 1485e952ea5c..a84ab43d22da 100644 --- a/servicemanagement/apiv1/doc.go +++ b/servicemanagement/apiv1/doc.go @@ -92,7 +92,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/servicemanagement/apiv1/gapic_metadata.json b/servicemanagement/apiv1/gapic_metadata.json index 76ab2fcdbc3f..b32e999aae67 100644 --- a/servicemanagement/apiv1/gapic_metadata.json +++ b/servicemanagement/apiv1/gapic_metadata.json @@ -30,16 +30,6 @@ "DeleteService" ] }, - "DisableService": { - "methods": [ - "DisableService" - ] - }, - "EnableService": { - "methods": [ - "EnableService" - ] - }, "GenerateConfigReport": { "methods": [ "GenerateConfigReport" diff --git a/servicemanagement/apiv1/service_manager_client.go b/servicemanagement/apiv1/service_manager_client.go index e1bd78272e30..4168e4dbcf0f 100644 --- a/servicemanagement/apiv1/service_manager_client.go +++ b/servicemanagement/apiv1/service_manager_client.go @@ -55,8 +55,6 @@ type ServiceManagerCallOptions struct { GetServiceRollout []gax.CallOption CreateServiceRollout []gax.CallOption GenerateConfigReport []gax.CallOption - EnableService []gax.CallOption - DisableService []gax.CallOption } func defaultServiceManagerGRPCClientOptions() []option.ClientOption { @@ -86,8 +84,6 @@ func defaultServiceManagerCallOptions() *ServiceManagerCallOptions { GetServiceRollout: []gax.CallOption{}, CreateServiceRollout: []gax.CallOption{}, GenerateConfigReport: []gax.CallOption{}, - EnableService: []gax.CallOption{}, - DisableService: []gax.CallOption{}, } } @@ -114,16 +110,12 @@ type internalServiceManagerClient interface { CreateServiceRollout(context.Context, *servicemanagementpb.CreateServiceRolloutRequest, ...gax.CallOption) (*CreateServiceRolloutOperation, error) CreateServiceRolloutOperation(name string) *CreateServiceRolloutOperation GenerateConfigReport(context.Context, *servicemanagementpb.GenerateConfigReportRequest, ...gax.CallOption) (*servicemanagementpb.GenerateConfigReportResponse, error) - EnableService(context.Context, *servicemanagementpb.EnableServiceRequest, ...gax.CallOption) (*EnableServiceOperation, error) - EnableServiceOperation(name string) *EnableServiceOperation - DisableService(context.Context, *servicemanagementpb.DisableServiceRequest, ...gax.CallOption) (*DisableServiceOperation, error) - DisableServiceOperation(name string) *DisableServiceOperation } // ServiceManagerClient is a client for interacting with Service Management API. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. // -// Google Service Management API (at https://cloud.google.com/service-management/overview) +// Google Service Management API (at /service-management/overview) type ServiceManagerClient struct { // The internal transport-dependent client. internalClient internalServiceManagerClient @@ -164,10 +156,6 @@ func (c *ServiceManagerClient) Connection() *grpc.ClientConn { // Returns all public services. For authenticated users, also returns all // services the calling user has “servicemanagement.services.get” permission // for. -// -// BETA: If the caller specifies the consumer_id, it returns only the -// services enabled on the consumer. The consumer_id must have the format -// of “project:{PROJECT-ID}”. func (c *ServiceManagerClient) ListServices(ctx context.Context, req *servicemanagementpb.ListServicesRequest, opts ...gax.CallOption) *ManagedServiceIterator { return c.internalClient.ListServices(ctx, req, opts...) } @@ -179,7 +167,14 @@ func (c *ServiceManagerClient) GetService(ctx context.Context, req *servicemanag } // CreateService creates a new managed service. -// Please note one producer project can own no more than 20 services. +// +// A managed service is immutable, and is subject to mandatory 30-day +// data retention. You cannot move a service or recreate it within 30 days +// after deletion. +// +// One producer project can own no more than 500 services. For security and +// reliability purposes, a production service should be hosted in a +// dedicated producer project. // // Operation func (c *ServiceManagerClient) CreateService(ctx context.Context, req *servicemanagementpb.CreateServiceRequest, opts ...gax.CallOption) (*CreateServiceOperation, error) { @@ -320,41 +315,6 @@ func (c *ServiceManagerClient) GenerateConfigReport(ctx context.Context, req *se return c.internalClient.GenerateConfigReport(ctx, req, opts...) } -// EnableService enables a service for a project, so it can be used -// for the project. See -// Cloud Auth Guide (at https://cloud.google.com/docs/authentication) for -// more information. -// -// Operation -// -// Deprecated: EnableService may be removed in a future version. -func (c *ServiceManagerClient) EnableService(ctx context.Context, req *servicemanagementpb.EnableServiceRequest, opts ...gax.CallOption) (*EnableServiceOperation, error) { - return c.internalClient.EnableService(ctx, req, opts...) -} - -// EnableServiceOperation returns a new EnableServiceOperation from a given name. -// The name must be that of a previously created EnableServiceOperation, possibly from a different process. -func (c *ServiceManagerClient) EnableServiceOperation(name string) *EnableServiceOperation { - return c.internalClient.EnableServiceOperation(name) -} - -// DisableService disables a service for a project, so it can no longer be -// be used for the project. It prevents accidental usage that may cause -// unexpected billing charges or security leaks. -// -// Operation -// -// Deprecated: DisableService may be removed in a future version. -func (c *ServiceManagerClient) DisableService(ctx context.Context, req *servicemanagementpb.DisableServiceRequest, opts ...gax.CallOption) (*DisableServiceOperation, error) { - return c.internalClient.DisableService(ctx, req, opts...) -} - -// DisableServiceOperation returns a new DisableServiceOperation from a given name. -// The name must be that of a previously created DisableServiceOperation, possibly from a different process. -func (c *ServiceManagerClient) DisableServiceOperation(name string) *DisableServiceOperation { - return c.internalClient.DisableServiceOperation(name) -} - // serviceManagerGRPCClient is a client for interacting with Service Management API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -383,7 +343,7 @@ type serviceManagerGRPCClient struct { // NewServiceManagerClient creates a new service manager client based on gRPC. // The returned client must be Closed when it is done being used to clean up its underlying connections. // -// Google Service Management API (at https://cloud.google.com/service-management/overview) +// Google Service Management API (at /service-management/overview) func NewServiceManagerClient(ctx context.Context, opts ...option.ClientOption) (*ServiceManagerClient, error) { clientOpts := defaultServiceManagerGRPCClientOptions() if newServiceManagerClientHook != nil { @@ -800,52 +760,6 @@ func (c *serviceManagerGRPCClient) GenerateConfigReport(ctx context.Context, req return resp, nil } -func (c *serviceManagerGRPCClient) EnableService(ctx context.Context, req *servicemanagementpb.EnableServiceRequest, opts ...gax.CallOption) (*EnableServiceOperation, error) { - if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { - cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) - defer cancel() - ctx = cctx - } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) - ctx = insertMetadata(ctx, c.xGoogMetadata, md) - opts = append((*c.CallOptions).EnableService[0:len((*c.CallOptions).EnableService):len((*c.CallOptions).EnableService)], opts...) - var resp *longrunningpb.Operation - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.serviceManagerClient.EnableService(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return &EnableServiceOperation{ - lro: longrunning.InternalNewOperation(*c.LROClient, resp), - }, nil -} - -func (c *serviceManagerGRPCClient) DisableService(ctx context.Context, req *servicemanagementpb.DisableServiceRequest, opts ...gax.CallOption) (*DisableServiceOperation, error) { - if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { - cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) - defer cancel() - ctx = cctx - } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) - ctx = insertMetadata(ctx, c.xGoogMetadata, md) - opts = append((*c.CallOptions).DisableService[0:len((*c.CallOptions).DisableService):len((*c.CallOptions).DisableService)], opts...) - var resp *longrunningpb.Operation - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.serviceManagerClient.DisableService(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return &DisableServiceOperation{ - lro: longrunning.InternalNewOperation(*c.LROClient, resp), - }, nil -} - // CreateServiceOperation manages a long-running operation from CreateService. type CreateServiceOperation struct { lro *longrunning.Operation @@ -1042,144 +956,6 @@ func (op *DeleteServiceOperation) Name() string { return op.lro.Name() } -// DisableServiceOperation manages a long-running operation from DisableService. -type DisableServiceOperation struct { - lro *longrunning.Operation -} - -// DisableServiceOperation returns a new DisableServiceOperation from a given name. -// The name must be that of a previously created DisableServiceOperation, possibly from a different process. -func (c *serviceManagerGRPCClient) DisableServiceOperation(name string) *DisableServiceOperation { - return &DisableServiceOperation{ - lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), - } -} - -// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. -// -// See documentation of Poll for error-handling information. -func (op *DisableServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.DisableServiceResponse, error) { - var resp servicemanagementpb.DisableServiceResponse - if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { - return nil, err - } - return &resp, nil -} - -// Poll fetches the latest state of the long-running operation. -// -// Poll also fetches the latest metadata, which can be retrieved by Metadata. -// -// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and -// the operation has completed with failure, the error is returned and op.Done will return true. -// If Poll succeeds and the operation has completed successfully, -// op.Done will return true, and the response of the operation is returned. -// If Poll succeeds and the operation has not completed, the returned response and error are both nil. -func (op *DisableServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.DisableServiceResponse, error) { - var resp servicemanagementpb.DisableServiceResponse - if err := op.lro.Poll(ctx, &resp, opts...); err != nil { - return nil, err - } - if !op.Done() { - return nil, nil - } - return &resp, nil -} - -// Metadata returns metadata associated with the long-running operation. -// Metadata itself does not contact the server, but Poll does. -// To get the latest metadata, call this method after a successful call to Poll. -// If the metadata is not available, the returned metadata and error are both nil. -func (op *DisableServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { - var meta servicemanagementpb.OperationMetadata - if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { - return nil, nil - } else if err != nil { - return nil, err - } - return &meta, nil -} - -// Done reports whether the long-running operation has completed. -func (op *DisableServiceOperation) Done() bool { - return op.lro.Done() -} - -// Name returns the name of the long-running operation. -// The name is assigned by the server and is unique within the service from which the operation is created. -func (op *DisableServiceOperation) Name() string { - return op.lro.Name() -} - -// EnableServiceOperation manages a long-running operation from EnableService. -type EnableServiceOperation struct { - lro *longrunning.Operation -} - -// EnableServiceOperation returns a new EnableServiceOperation from a given name. -// The name must be that of a previously created EnableServiceOperation, possibly from a different process. -func (c *serviceManagerGRPCClient) EnableServiceOperation(name string) *EnableServiceOperation { - return &EnableServiceOperation{ - lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), - } -} - -// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. -// -// See documentation of Poll for error-handling information. -func (op *EnableServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.EnableServiceResponse, error) { - var resp servicemanagementpb.EnableServiceResponse - if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { - return nil, err - } - return &resp, nil -} - -// Poll fetches the latest state of the long-running operation. -// -// Poll also fetches the latest metadata, which can be retrieved by Metadata. -// -// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and -// the operation has completed with failure, the error is returned and op.Done will return true. -// If Poll succeeds and the operation has completed successfully, -// op.Done will return true, and the response of the operation is returned. -// If Poll succeeds and the operation has not completed, the returned response and error are both nil. -func (op *EnableServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.EnableServiceResponse, error) { - var resp servicemanagementpb.EnableServiceResponse - if err := op.lro.Poll(ctx, &resp, opts...); err != nil { - return nil, err - } - if !op.Done() { - return nil, nil - } - return &resp, nil -} - -// Metadata returns metadata associated with the long-running operation. -// Metadata itself does not contact the server, but Poll does. -// To get the latest metadata, call this method after a successful call to Poll. -// If the metadata is not available, the returned metadata and error are both nil. -func (op *EnableServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { - var meta servicemanagementpb.OperationMetadata - if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { - return nil, nil - } else if err != nil { - return nil, err - } - return &meta, nil -} - -// Done reports whether the long-running operation has completed. -func (op *EnableServiceOperation) Done() bool { - return op.lro.Done() -} - -// Name returns the name of the long-running operation. -// The name is assigned by the server and is unique within the service from which the operation is created. -func (op *EnableServiceOperation) Name() string { - return op.lro.Name() -} - // SubmitConfigSourceOperation manages a long-running operation from SubmitConfigSource. type SubmitConfigSourceOperation struct { lro *longrunning.Operation diff --git a/servicemanagement/apiv1/service_manager_client_example_test.go b/servicemanagement/apiv1/service_manager_client_example_test.go index 4c088f4b785a..e05b00df3670 100644 --- a/servicemanagement/apiv1/service_manager_client_example_test.go +++ b/servicemanagement/apiv1/service_manager_client_example_test.go @@ -336,53 +336,3 @@ func ExampleServiceManagerClient_GenerateConfigReport() { // TODO: Use resp. _ = resp } - -func ExampleServiceManagerClient_EnableService() { - ctx := context.Background() - c, err := servicemanagement.NewServiceManagerClient(ctx) - if err != nil { - // TODO: Handle error. - } - defer c.Close() - - req := &servicemanagementpb.EnableServiceRequest{ - // TODO: Fill request struct fields. - // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/servicemanagement/v1#EnableServiceRequest. - } - op, err := c.EnableService(ctx, req) - if err != nil { - // TODO: Handle error. - } - - resp, err := op.Wait(ctx) - if err != nil { - // TODO: Handle error. - } - // TODO: Use resp. - _ = resp -} - -func ExampleServiceManagerClient_DisableService() { - ctx := context.Background() - c, err := servicemanagement.NewServiceManagerClient(ctx) - if err != nil { - // TODO: Handle error. - } - defer c.Close() - - req := &servicemanagementpb.DisableServiceRequest{ - // TODO: Fill request struct fields. - // See https://pkg.go.dev/google.golang.org/genproto/googleapis/api/servicemanagement/v1#DisableServiceRequest. - } - op, err := c.DisableService(ctx, req) - if err != nil { - // TODO: Handle error. - } - - resp, err := op.Wait(ctx) - if err != nil { - // TODO: Handle error. - } - // TODO: Use resp. - _ = resp -} diff --git a/video/livestream/apiv1/doc.go b/video/livestream/apiv1/doc.go index 71d444b9e409..06e1d287ca57 100644 --- a/video/livestream/apiv1/doc.go +++ b/video/livestream/apiv1/doc.go @@ -89,7 +89,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20220207" +const versionClient = "20220215" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx)