blob: 24fa615dc1dee886b9170787df3eae9ea0759f05 [file] [log] [blame]
// Copyright 2024 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 assuredworkloads
import (
"bytes"
"context"
"fmt"
"io"
"math"
"net/http"
"net/url"
"time"
assuredworkloadspb "cloud.google.com/go/assuredworkloads/apiv1/assuredworkloadspb"
"cloud.google.com/go/longrunning"
lroauto "cloud.google.com/go/longrunning/autogen"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
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"
gtransport "google.golang.org/api/transport/grpc"
httptransport "google.golang.org/api/transport/http"
"google.golang.org/grpc"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
var newClientHook clientHook
// CallOptions contains the retry settings for each method of Client.
type CallOptions struct {
CreateWorkload []gax.CallOption
UpdateWorkload []gax.CallOption
RestrictAllowedResources []gax.CallOption
DeleteWorkload []gax.CallOption
GetWorkload []gax.CallOption
ListWorkloads []gax.CallOption
ListViolations []gax.CallOption
GetViolation []gax.CallOption
AcknowledgeViolation []gax.CallOption
GetOperation []gax.CallOption
ListOperations []gax.CallOption
}
func defaultGRPCClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("assuredworkloads.googleapis.com:443"),
internaloption.WithDefaultEndpointTemplate("assuredworkloads.UNIVERSE_DOMAIN:443"),
internaloption.WithDefaultMTLSEndpoint("assuredworkloads.mtls.googleapis.com:443"),
internaloption.WithDefaultUniverseDomain("googleapis.com"),
internaloption.WithDefaultAudience("https://assuredworkloads.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
}
func defaultCallOptions() *CallOptions {
return &CallOptions{
CreateWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
UpdateWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
RestrictAllowedResources: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
DeleteWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
GetWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
ListWorkloads: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
ListViolations: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
GetViolation: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
AcknowledgeViolation: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
GetOperation: []gax.CallOption{},
ListOperations: []gax.CallOption{},
}
}
func defaultRESTCallOptions() *CallOptions {
return &CallOptions{
CreateWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
UpdateWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
RestrictAllowedResources: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
DeleteWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
GetWorkload: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
ListWorkloads: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
ListViolations: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
GetViolation: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
AcknowledgeViolation: []gax.CallOption{
gax.WithTimeout(60000 * time.Millisecond),
},
GetOperation: []gax.CallOption{},
ListOperations: []gax.CallOption{},
}
}
// internalClient is an interface that defines the methods available from Assured Workloads API.
type internalClient interface {
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
CreateWorkload(context.Context, *assuredworkloadspb.CreateWorkloadRequest, ...gax.CallOption) (*CreateWorkloadOperation, error)
CreateWorkloadOperation(name string) *CreateWorkloadOperation
UpdateWorkload(context.Context, *assuredworkloadspb.UpdateWorkloadRequest, ...gax.CallOption) (*assuredworkloadspb.Workload, error)
RestrictAllowedResources(context.Context, *assuredworkloadspb.RestrictAllowedResourcesRequest, ...gax.CallOption) (*assuredworkloadspb.RestrictAllowedResourcesResponse, error)
DeleteWorkload(context.Context, *assuredworkloadspb.DeleteWorkloadRequest, ...gax.CallOption) error
GetWorkload(context.Context, *assuredworkloadspb.GetWorkloadRequest, ...gax.CallOption) (*assuredworkloadspb.Workload, error)
ListWorkloads(context.Context, *assuredworkloadspb.ListWorkloadsRequest, ...gax.CallOption) *WorkloadIterator
ListViolations(context.Context, *assuredworkloadspb.ListViolationsRequest, ...gax.CallOption) *ViolationIterator
GetViolation(context.Context, *assuredworkloadspb.GetViolationRequest, ...gax.CallOption) (*assuredworkloadspb.Violation, error)
AcknowledgeViolation(context.Context, *assuredworkloadspb.AcknowledgeViolationRequest, ...gax.CallOption) (*assuredworkloadspb.AcknowledgeViolationResponse, error)
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
}
// Client is a client for interacting with Assured Workloads API.
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
//
// Service to manage AssuredWorkloads.
type Client struct {
// The internal transport-dependent client.
internalClient internalClient
// The call options for this service.
CallOptions *CallOptions
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient *lroauto.OperationsClient
}
// 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 *Client) 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 *Client) setGoogleClientInfo(keyval ...string) {
c.internalClient.setGoogleClientInfo(keyval...)
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (c *Client) Connection() *grpc.ClientConn {
return c.internalClient.Connection()
}
// CreateWorkload creates Assured Workload.
func (c *Client) CreateWorkload(ctx context.Context, req *assuredworkloadspb.CreateWorkloadRequest, opts ...gax.CallOption) (*CreateWorkloadOperation, error) {
return c.internalClient.CreateWorkload(ctx, req, opts...)
}
// CreateWorkloadOperation returns a new CreateWorkloadOperation from a given name.
// The name must be that of a previously created CreateWorkloadOperation, possibly from a different process.
func (c *Client) CreateWorkloadOperation(name string) *CreateWorkloadOperation {
return c.internalClient.CreateWorkloadOperation(name)
}
// UpdateWorkload updates an existing workload.
// Currently allows updating of workload display_name and labels.
// For force updates don’t set etag field in the Workload.
// Only one update operation per workload can be in progress.
func (c *Client) UpdateWorkload(ctx context.Context, req *assuredworkloadspb.UpdateWorkloadRequest, opts ...gax.CallOption) (*assuredworkloadspb.Workload, error) {
return c.internalClient.UpdateWorkload(ctx, req, opts...)
}
// RestrictAllowedResources restrict the list of resources allowed in the Workload environment.
// The current list of allowed products can be found at
// https://cloud.google.com/assured-workloads/docs/supported-products (at https://cloud.google.com/assured-workloads/docs/supported-products)
// In addition to assuredworkloads.workload.update permission, the user should
// also have orgpolicy.policy.set permission on the folder resource
// to use this functionality.
func (c *Client) RestrictAllowedResources(ctx context.Context, req *assuredworkloadspb.RestrictAllowedResourcesRequest, opts ...gax.CallOption) (*assuredworkloadspb.RestrictAllowedResourcesResponse, error) {
return c.internalClient.RestrictAllowedResources(ctx, req, opts...)
}
// DeleteWorkload deletes the workload. Make sure that workload’s direct children are already
// in a deleted state, otherwise the request will fail with a
// FAILED_PRECONDITION error.
func (c *Client) DeleteWorkload(ctx context.Context, req *assuredworkloadspb.DeleteWorkloadRequest, opts ...gax.CallOption) error {
return c.internalClient.DeleteWorkload(ctx, req, opts...)
}
// GetWorkload gets Assured Workload associated with a CRM Node
func (c *Client) GetWorkload(ctx context.Context, req *assuredworkloadspb.GetWorkloadRequest, opts ...gax.CallOption) (*assuredworkloadspb.Workload, error) {
return c.internalClient.GetWorkload(ctx, req, opts...)
}
// ListWorkloads lists Assured Workloads under a CRM Node.
func (c *Client) ListWorkloads(ctx context.Context, req *assuredworkloadspb.ListWorkloadsRequest, opts ...gax.CallOption) *WorkloadIterator {
return c.internalClient.ListWorkloads(ctx, req, opts...)
}
// ListViolations lists the Violations in the AssuredWorkload Environment.
// Callers may also choose to read across multiple Workloads as per
// AIP-159 (at https://google.aip.dev/159) by using ‘-’ (the hyphen or dash
// character) as a wildcard character instead of workload-id in the parent.
// Format organizations/{org_id}/locations/{location}/workloads/-
func (c *Client) ListViolations(ctx context.Context, req *assuredworkloadspb.ListViolationsRequest, opts ...gax.CallOption) *ViolationIterator {
return c.internalClient.ListViolations(ctx, req, opts...)
}
// GetViolation retrieves Assured Workload Violation based on ID.
func (c *Client) GetViolation(ctx context.Context, req *assuredworkloadspb.GetViolationRequest, opts ...gax.CallOption) (*assuredworkloadspb.Violation, error) {
return c.internalClient.GetViolation(ctx, req, opts...)
}
// AcknowledgeViolation acknowledges an existing violation. By acknowledging a violation, users
// acknowledge the existence of a compliance violation in their workload and
// decide to ignore it due to a valid business justification. Acknowledgement
// is a permanent operation and it cannot be reverted.
func (c *Client) AcknowledgeViolation(ctx context.Context, req *assuredworkloadspb.AcknowledgeViolationRequest, opts ...gax.CallOption) (*assuredworkloadspb.AcknowledgeViolationResponse, error) {
return c.internalClient.AcknowledgeViolation(ctx, req, opts...)
}
// GetOperation is a utility method from google.longrunning.Operations.
func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
return c.internalClient.GetOperation(ctx, req, opts...)
}
// ListOperations is a utility method from google.longrunning.Operations.
func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
return c.internalClient.ListOperations(ctx, req, opts...)
}
// gRPCClient is a client for interacting with Assured Workloads API over gRPC transport.
//
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type gRPCClient struct {
// Connection pool of gRPC connections to the service.
connPool gtransport.ConnPool
// Points back to the CallOptions field of the containing Client
CallOptions **CallOptions
// The gRPC API client.
client assuredworkloadspb.AssuredWorkloadsServiceClient
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient **lroauto.OperationsClient
operationsClient longrunningpb.OperationsClient
// The x-goog-* metadata to be sent with each request.
xGoogHeaders []string
}
// NewClient creates a new assured workloads service client based on gRPC.
// The returned client must be Closed when it is done being used to clean up its underlying connections.
//
// Service to manage AssuredWorkloads.
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
clientOpts := defaultGRPCClientOptions()
if newClientHook != nil {
hookOpts, err := newClientHook(ctx, clientHookParams{})
if err != nil {
return nil, err
}
clientOpts = append(clientOpts, hookOpts...)
}
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
if err != nil {
return nil, err
}
client := Client{CallOptions: defaultCallOptions()}
c := &gRPCClient{
connPool: connPool,
client: assuredworkloadspb.NewAssuredWorkloadsServiceClient(connPool),
CallOptions: &client.CallOptions,
operationsClient: longrunningpb.NewOperationsClient(connPool),
}
c.setGoogleClientInfo()
client.internalClient = c
client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
if err != nil {
// This error "should not happen", since we are just reusing old connection pool
// and never actually need to dial.
// If this does happen, we could leak connp. However, we cannot close conn:
// If the user invoked the constructor with option.WithGRPCConn,
// we would close a connection that's still in use.
// TODO: investigate error conditions.
return nil, err
}
c.LROClient = &client.LROClient
return &client, nil
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (c *gRPCClient) Connection() *grpc.ClientConn {
return c.connPool.Conn()
}
// 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 *gRPCClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
c.xGoogHeaders = []string{"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 *gRPCClient) Close() error {
return c.connPool.Close()
}
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type restClient struct {
// The http endpoint to connect to.
endpoint string
// The http client.
httpClient *http.Client
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient **lroauto.OperationsClient
// The x-goog-* headers to be sent with each request.
xGoogHeaders []string
// Points back to the CallOptions field of the containing Client
CallOptions **CallOptions
}
// NewRESTClient creates a new assured workloads service rest client.
//
// Service to manage AssuredWorkloads.
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
clientOpts := append(defaultRESTClientOptions(), opts...)
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
if err != nil {
return nil, err
}
callOpts := defaultRESTCallOptions()
c := &restClient{
endpoint: endpoint,
httpClient: httpClient,
CallOptions: &callOpts,
}
c.setGoogleClientInfo()
lroOpts := []option.ClientOption{
option.WithHTTPClient(httpClient),
option.WithEndpoint(endpoint),
}
opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
if err != nil {
return nil, err
}
c.LROClient = &opClient
return &Client{internalClient: c, CallOptions: callOpts}, nil
}
func defaultRESTClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("https://assuredworkloads.googleapis.com"),
internaloption.WithDefaultEndpointTemplate("https://assuredworkloads.UNIVERSE_DOMAIN"),
internaloption.WithDefaultMTLSEndpoint("https://assuredworkloads.mtls.googleapis.com"),
internaloption.WithDefaultUniverseDomain("googleapis.com"),
internaloption.WithDefaultAudience("https://assuredworkloads.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 *restClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
c.xGoogHeaders = []string{"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 *restClient) Close() error {
// Replace httpClient with nil to force cleanup.
c.httpClient = nil
return nil
}
// Connection returns a connection to the API service.
//
// Deprecated: This method always returns nil.
func (c *restClient) Connection() *grpc.ClientConn {
return nil
}
func (c *gRPCClient) CreateWorkload(ctx context.Context, req *assuredworkloadspb.CreateWorkloadRequest, opts ...gax.CallOption) (*CreateWorkloadOperation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).CreateWorkload[0:len((*c.CallOptions).CreateWorkload):len((*c.CallOptions).CreateWorkload)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.CreateWorkload(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return &CreateWorkloadOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
}, nil
}
func (c *gRPCClient) UpdateWorkload(ctx context.Context, req *assuredworkloadspb.UpdateWorkloadRequest, opts ...gax.CallOption) (*assuredworkloadspb.Workload, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "workload.name", url.QueryEscape(req.GetWorkload().GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).UpdateWorkload[0:len((*c.CallOptions).UpdateWorkload):len((*c.CallOptions).UpdateWorkload)], opts...)
var resp *assuredworkloadspb.Workload
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.UpdateWorkload(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) RestrictAllowedResources(ctx context.Context, req *assuredworkloadspb.RestrictAllowedResourcesRequest, opts ...gax.CallOption) (*assuredworkloadspb.RestrictAllowedResourcesResponse, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).RestrictAllowedResources[0:len((*c.CallOptions).RestrictAllowedResources):len((*c.CallOptions).RestrictAllowedResources)], opts...)
var resp *assuredworkloadspb.RestrictAllowedResourcesResponse
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.RestrictAllowedResources(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) DeleteWorkload(ctx context.Context, req *assuredworkloadspb.DeleteWorkloadRequest, opts ...gax.CallOption) error {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).DeleteWorkload[0:len((*c.CallOptions).DeleteWorkload):len((*c.CallOptions).DeleteWorkload)], opts...)
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
_, err = c.client.DeleteWorkload(ctx, req, settings.GRPC...)
return err
}, opts...)
return err
}
func (c *gRPCClient) GetWorkload(ctx context.Context, req *assuredworkloadspb.GetWorkloadRequest, opts ...gax.CallOption) (*assuredworkloadspb.Workload, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).GetWorkload[0:len((*c.CallOptions).GetWorkload):len((*c.CallOptions).GetWorkload)], opts...)
var resp *assuredworkloadspb.Workload
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.GetWorkload(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) ListWorkloads(ctx context.Context, req *assuredworkloadspb.ListWorkloadsRequest, opts ...gax.CallOption) *WorkloadIterator {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).ListWorkloads[0:len((*c.CallOptions).ListWorkloads):len((*c.CallOptions).ListWorkloads)], opts...)
it := &WorkloadIterator{}
req = proto.Clone(req).(*assuredworkloadspb.ListWorkloadsRequest)
it.InternalFetch = func(pageSize int, pageToken string) ([]*assuredworkloadspb.Workload, string, error) {
resp := &assuredworkloadspb.ListWorkloadsResponse{}
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.client.ListWorkloads(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetWorkloads(), 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 *gRPCClient) ListViolations(ctx context.Context, req *assuredworkloadspb.ListViolationsRequest, opts ...gax.CallOption) *ViolationIterator {
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
opts = append((*c.CallOptions).ListViolations[0:len((*c.CallOptions).ListViolations):len((*c.CallOptions).ListViolations)], opts...)
it := &ViolationIterator{}
req = proto.Clone(req).(*assuredworkloadspb.ListViolationsRequest)
it.InternalFetch = func(pageSize int, pageToken string) ([]*assuredworkloadspb.Violation, string, error) {
resp := &assuredworkloadspb.ListViolationsResponse{}
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.client.ListViolations(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetViolations(), 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 *gRPCClient) GetViolation(ctx context.Context, req *assuredworkloadspb.GetViolationRequest, opts ...gax.CallOption) (*assuredworkloadspb.Violation, error) {
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
opts = append((*c.CallOptions).GetViolation[0:len((*c.CallOptions).GetViolation):len((*c.CallOptions).GetViolation)], opts...)
var resp *assuredworkloadspb.Violation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.GetViolation(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) AcknowledgeViolation(ctx context.Context, req *assuredworkloadspb.AcknowledgeViolationRequest, opts ...gax.CallOption) (*assuredworkloadspb.AcknowledgeViolationResponse, error) {
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
opts = append((*c.CallOptions).AcknowledgeViolation[0:len((*c.CallOptions).AcknowledgeViolation):len((*c.CallOptions).AcknowledgeViolation)], opts...)
var resp *assuredworkloadspb.AcknowledgeViolationResponse
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.client.AcknowledgeViolation(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *gRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
it := &OperationIterator{}
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
resp := &longrunningpb.ListOperationsResponse{}
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.operationsClient.ListOperations(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetOperations(), 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
}
// CreateWorkload creates Assured Workload.
func (c *restClient) CreateWorkload(ctx context.Context, req *assuredworkloadspb.CreateWorkloadRequest, opts ...gax.CallOption) (*CreateWorkloadOperation, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
body := req.GetWorkload()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1/%v/workloads", req.GetParent())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetExternalId() != "" {
params.Add("externalId", fmt.Sprintf("%v", req.GetExternalId()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &longrunningpb.Operation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
override := fmt.Sprintf("/v1/%s", resp.GetName())
return &CreateWorkloadOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, resp),
pollPath: override,
}, nil
}
// UpdateWorkload updates an existing workload.
// Currently allows updating of workload display_name and labels.
// For force updates don’t set etag field in the Workload.
// Only one update operation per workload can be in progress.
func (c *restClient) UpdateWorkload(ctx context.Context, req *assuredworkloadspb.UpdateWorkloadRequest, opts ...gax.CallOption) (*assuredworkloadspb.Workload, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
body := req.GetWorkload()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetWorkload().GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetUpdateMask() != nil {
updateMask, err := protojson.Marshal(req.GetUpdateMask())
if err != nil {
return nil, err
}
params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "workload.name", url.QueryEscape(req.GetWorkload().GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
opts = append((*c.CallOptions).UpdateWorkload[0:len((*c.CallOptions).UpdateWorkload):len((*c.CallOptions).UpdateWorkload)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &assuredworkloadspb.Workload{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// RestrictAllowedResources restrict the list of resources allowed in the Workload environment.
// The current list of allowed products can be found at
// https://cloud.google.com/assured-workloads/docs/supported-products (at https://cloud.google.com/assured-workloads/docs/supported-products)
// In addition to assuredworkloads.workload.update permission, the user should
// also have orgpolicy.policy.set permission on the folder resource
// to use this functionality.
func (c *restClient) RestrictAllowedResources(ctx context.Context, req *assuredworkloadspb.RestrictAllowedResourcesRequest, opts ...gax.CallOption) (*assuredworkloadspb.RestrictAllowedResourcesResponse, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1/%v:restrictAllowedResources", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
opts = append((*c.CallOptions).RestrictAllowedResources[0:len((*c.CallOptions).RestrictAllowedResources):len((*c.CallOptions).RestrictAllowedResources)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &assuredworkloadspb.RestrictAllowedResourcesResponse{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// DeleteWorkload deletes the workload. Make sure that workload’s direct children are already
// in a deleted state, otherwise the request will fail with a
// FAILED_PRECONDITION error.
func (c *restClient) DeleteWorkload(ctx context.Context, req *assuredworkloadspb.DeleteWorkloadRequest, opts ...gax.CallOption) error {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return err
}
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetEtag() != "" {
params.Add("etag", fmt.Sprintf("%v", req.GetEtag()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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()
// Returns nil if there is no error, otherwise wraps
// the response code and body into a non-nil error
return googleapi.CheckResponse(httpRsp)
}, opts...)
}
// GetWorkload gets Assured Workload associated with a CRM Node
func (c *restClient) GetWorkload(ctx context.Context, req *assuredworkloadspb.GetWorkloadRequest, opts ...gax.CallOption) (*assuredworkloadspb.Workload, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
opts = append((*c.CallOptions).GetWorkload[0:len((*c.CallOptions).GetWorkload):len((*c.CallOptions).GetWorkload)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &assuredworkloadspb.Workload{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// ListWorkloads lists Assured Workloads under a CRM Node.
func (c *restClient) ListWorkloads(ctx context.Context, req *assuredworkloadspb.ListWorkloadsRequest, opts ...gax.CallOption) *WorkloadIterator {
it := &WorkloadIterator{}
req = proto.Clone(req).(*assuredworkloadspb.ListWorkloadsRequest)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
it.InternalFetch = func(pageSize int, pageToken string) ([]*assuredworkloadspb.Workload, string, error) {
resp := &assuredworkloadspb.ListWorkloadsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, "", err
}
baseUrl.Path += fmt.Sprintf("/v1/%v/workloads", req.GetParent())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetFilter() != "" {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req.GetPageSize() != 0 {
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
}
if req.GetPageToken() != "" {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, "", e
}
it.Response = resp
return resp.GetWorkloads(), 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
}
// ListViolations lists the Violations in the AssuredWorkload Environment.
// Callers may also choose to read across multiple Workloads as per
// AIP-159 (at https://google.aip.dev/159) by using ‘-’ (the hyphen or dash
// character) as a wildcard character instead of workload-id in the parent.
// Format organizations/{org_id}/locations/{location}/workloads/-
func (c *restClient) ListViolations(ctx context.Context, req *assuredworkloadspb.ListViolationsRequest, opts ...gax.CallOption) *ViolationIterator {
it := &ViolationIterator{}
req = proto.Clone(req).(*assuredworkloadspb.ListViolationsRequest)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
it.InternalFetch = func(pageSize int, pageToken string) ([]*assuredworkloadspb.Violation, string, error) {
resp := &assuredworkloadspb.ListViolationsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, "", err
}
baseUrl.Path += fmt.Sprintf("")
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetFilter() != "" {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req.GetInterval().GetEndTime() != nil {
endTime, err := protojson.Marshal(req.GetInterval().GetEndTime())
if err != nil {
return nil, "", err
}
params.Add("interval.endTime", string(endTime[1:len(endTime)-1]))
}
if req.GetInterval().GetStartTime() != nil {
startTime, err := protojson.Marshal(req.GetInterval().GetStartTime())
if err != nil {
return nil, "", err
}
params.Add("interval.startTime", string(startTime[1:len(startTime)-1]))
}
if req.GetPageSize() != 0 {
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
}
if req.GetPageToken() != "" {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
params.Add("parent", fmt.Sprintf("%v", req.GetParent()))
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("", 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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, "", e
}
it.Response = resp
return resp.GetViolations(), 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
}
// GetViolation retrieves Assured Workload Violation based on ID.
func (c *restClient) GetViolation(ctx context.Context, req *assuredworkloadspb.GetViolationRequest, opts ...gax.CallOption) (*assuredworkloadspb.Violation, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("")
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
params.Add("name", fmt.Sprintf("%v", req.GetName()))
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
opts = append((*c.CallOptions).GetViolation[0:len((*c.CallOptions).GetViolation):len((*c.CallOptions).GetViolation)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &assuredworkloadspb.Violation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("", 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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// AcknowledgeViolation acknowledges an existing violation. By acknowledging a violation, users
// acknowledge the existence of a compliance violation in their workload and
// decide to ignore it due to a valid business justification. Acknowledgement
// is a permanent operation and it cannot be reverted.
func (c *restClient) AcknowledgeViolation(ctx context.Context, req *assuredworkloadspb.AcknowledgeViolationRequest, opts ...gax.CallOption) (*assuredworkloadspb.AcknowledgeViolationResponse, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("")
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
params.Add("comment", fmt.Sprintf("%v", req.GetComment()))
params.Add("name", fmt.Sprintf("%v", req.GetName()))
if req.GetNonCompliantOrgPolicy() != "" {
params.Add("nonCompliantOrgPolicy", fmt.Sprintf("%v", req.GetNonCompliantOrgPolicy()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
opts = append((*c.CallOptions).AcknowledgeViolation[0:len((*c.CallOptions).AcknowledgeViolation):len((*c.CallOptions).AcknowledgeViolation)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &assuredworkloadspb.AcknowledgeViolationResponse{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("", 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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// GetOperation is a utility method from google.longrunning.Operations.
func (c *restClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &longrunningpb.Operation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// ListOperations is a utility method from google.longrunning.Operations.
func (c *restClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
it := &OperationIterator{}
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
resp := &longrunningpb.ListOperationsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, "", err
}
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetFilter() != "" {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req.GetPageSize() != 0 {
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
}
if req.GetPageToken() != "" {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
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 := io.ReadAll(httpRsp.Body)
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, "", e
}
it.Response = resp
return resp.GetOperations(), 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
}
// CreateWorkloadOperation returns a new CreateWorkloadOperation from a given name.
// The name must be that of a previously created CreateWorkloadOperation, possibly from a different process.
func (c *gRPCClient) CreateWorkloadOperation(name string) *CreateWorkloadOperation {
return &CreateWorkloadOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
}
}
// CreateWorkloadOperation returns a new CreateWorkloadOperation from a given name.
// The name must be that of a previously created CreateWorkloadOperation, possibly from a different process.
func (c *restClient) CreateWorkloadOperation(name string) *CreateWorkloadOperation {
override := fmt.Sprintf("/v1/%s", name)
return &CreateWorkloadOperation{
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
pollPath: override,
}
}