diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index fcab2e74d94..db315213164 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -773,6 +773,15 @@ "release_level": "ga", "library_type": "" }, + "cloud.google.com/go/osconfig/apiv1alpha": { + "distribution_name": "cloud.google.com/go/osconfig/apiv1alpha", + "description": "OS Config API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/osconfig/apiv1alpha", + "release_level": "alpha", + "library_type": "" + }, "cloud.google.com/go/osconfig/apiv1beta": { "distribution_name": "cloud.google.com/go/osconfig/apiv1beta", "description": "Cloud OS Config API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index ae9910e1b11..1e064c64391 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -314,6 +314,14 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/cloud/osconfig/v1/osconfig_v1.yaml", releaseLevel: "ga", }, + { + inputDirectoryPath: "google/cloud/osconfig/v1alpha", + pkg: "osconfig", + importPath: "cloud.google.com/go/osconfig/apiv1alpha", + gRPCServiceConfigPath: "google/cloud/osconfig/v1alpha/osconfig_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/osconfig/v1alpha/osconfig_v1alpha.yaml", + releaseLevel: "alpha", + }, { inputDirectoryPath: "google/cloud/osconfig/v1beta", pkg: "osconfig", diff --git a/osconfig/apiv1alpha/doc.go b/osconfig/apiv1alpha/doc.go new file mode 100644 index 00000000000..ed40c29ec4a --- /dev/null +++ b/osconfig/apiv1alpha/doc.go @@ -0,0 +1,117 @@ +// Copyright 2021 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 osconfig is an auto-generated package for the +// OS Config API. +// +// OS management tools that can be used for patch management, patch +// compliance, and configuration management on VM instances. +// +// Use of Context +// +// The ctx passed to NewClient is used for authentication requests and +// for creating the underlying connection, but is not used for subsequent calls. +// Individual methods on the client use the ctx given to them. +// +// To close the open connection, use the Close() method. +// +// For information about setting deadlines, reusing contexts, and more +// please visit pkg.go.dev/cloud.google.com/go. +package osconfig // import "cloud.google.com/go/osconfig/apiv1alpha" + +import ( + "context" + "os" + "runtime" + "strconv" + "strings" + "unicode" + + "google.golang.org/api/option" + "google.golang.org/grpc/metadata" +) + +// For more information on implementing a client constructor hook, see +// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. +type clientHookParams struct{} +type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) + +const versionClient = "20210518" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/osconfig/apiv1alpha/gapic_metadata.json b/osconfig/apiv1alpha/gapic_metadata.json new file mode 100644 index 00000000000..68645256d0c --- /dev/null +++ b/osconfig/apiv1alpha/gapic_metadata.json @@ -0,0 +1,78 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.osconfig.v1alpha", + "libraryPackage": "cloud.google.com/go/osconfig/apiv1alpha", + "services": { + "OsConfigZonalService": { + "clients": { + "grpc": { + "libraryClient": "OsConfigZonalClient", + "rpcs": { + "CreateOSPolicyAssignment": { + "methods": [ + "CreateOSPolicyAssignment" + ] + }, + "DeleteOSPolicyAssignment": { + "methods": [ + "DeleteOSPolicyAssignment" + ] + }, + "GetInstanceOSPoliciesCompliance": { + "methods": [ + "GetInstanceOSPoliciesCompliance" + ] + }, + "GetInventory": { + "methods": [ + "GetInventory" + ] + }, + "GetOSPolicyAssignment": { + "methods": [ + "GetOSPolicyAssignment" + ] + }, + "GetVulnerabilityReport": { + "methods": [ + "GetVulnerabilityReport" + ] + }, + "ListInstanceOSPoliciesCompliances": { + "methods": [ + "ListInstanceOSPoliciesCompliances" + ] + }, + "ListInventories": { + "methods": [ + "ListInventories" + ] + }, + "ListOSPolicyAssignmentRevisions": { + "methods": [ + "ListOSPolicyAssignmentRevisions" + ] + }, + "ListOSPolicyAssignments": { + "methods": [ + "ListOSPolicyAssignments" + ] + }, + "ListVulnerabilityReports": { + "methods": [ + "ListVulnerabilityReports" + ] + }, + "UpdateOSPolicyAssignment": { + "methods": [ + "UpdateOSPolicyAssignment" + ] + } + } + } + } + } + } +} diff --git a/osconfig/apiv1alpha/os_config_zonal_client.go b/osconfig/apiv1alpha/os_config_zonal_client.go new file mode 100644 index 00000000000..8974653f396 --- /dev/null +++ b/osconfig/apiv1alpha/os_config_zonal_client.go @@ -0,0 +1,1087 @@ +// Copyright 2021 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 osconfig + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newOsConfigZonalClientHook clientHook + +// OsConfigZonalCallOptions contains the retry settings for each method of OsConfigZonalClient. +type OsConfigZonalCallOptions struct { + CreateOSPolicyAssignment []gax.CallOption + UpdateOSPolicyAssignment []gax.CallOption + GetOSPolicyAssignment []gax.CallOption + ListOSPolicyAssignments []gax.CallOption + ListOSPolicyAssignmentRevisions []gax.CallOption + DeleteOSPolicyAssignment []gax.CallOption + GetInstanceOSPoliciesCompliance []gax.CallOption + ListInstanceOSPoliciesCompliances []gax.CallOption + GetInventory []gax.CallOption + ListInventories []gax.CallOption + GetVulnerabilityReport []gax.CallOption + ListVulnerabilityReports []gax.CallOption +} + +func defaultOsConfigZonalClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("osconfig.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultOsConfigZonalCallOptions() *OsConfigZonalCallOptions { + return &OsConfigZonalCallOptions{ + CreateOSPolicyAssignment: []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, + }) + }), + }, + UpdateOSPolicyAssignment: []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, + }) + }), + }, + GetOSPolicyAssignment: []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, + }) + }), + }, + ListOSPolicyAssignments: []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, + }) + }), + }, + ListOSPolicyAssignmentRevisions: []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, + }) + }), + }, + DeleteOSPolicyAssignment: []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, + }) + }), + }, + GetInstanceOSPoliciesCompliance: []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, + }) + }), + }, + ListInstanceOSPoliciesCompliances: []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{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListInventories: []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, + }) + }), + }, + GetVulnerabilityReport: []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, + }) + }), + }, + ListVulnerabilityReports: []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, + }) + }), + }, + } +} + +// OsConfigZonalClient 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. +type OsConfigZonalClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + osConfigZonalClient osconfigpb.OsConfigZonalServiceClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *OsConfigZonalCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewOsConfigZonalClient creates a new os config zonal service client. +// +// Zonal OS Config API +// +// The OS Config service is the server-side component that allows users to +// manage package installations and patch jobs for Compute Engine VM instances. +func NewOsConfigZonalClient(ctx context.Context, opts ...option.ClientOption) (*OsConfigZonalClient, error) { + clientOpts := defaultOsConfigZonalClientOptions() + + if newOsConfigZonalClientHook != nil { + hookOpts, err := newOsConfigZonalClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &OsConfigZonalClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultOsConfigZonalCallOptions(), + + osConfigZonalClient: osconfigpb.NewOsConfigZonalServiceClient(connPool), + } + c.setGoogleClientInfo() + + c.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 + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *OsConfigZonalClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *OsConfigZonalClient) Close() error { + return c.connPool.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 *OsConfigZonalClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateOSPolicyAssignment create an OS policy assignment. +// +// This method also creates the first revision of the OS policy assignment. +// +// This method returns a long running operation (LRO) that contains the +// rollout details. The rollout can be cancelled by cancelling the LRO. +// +// For more information, see Method: +// projects.locations.osPolicyAssignments.operations.cancel (at https://cloud.google.com/compute/docs/osconfig/rest/v1alpha/projects.locations.osPolicyAssignments.operations/cancel). +func (c *OsConfigZonalClient) CreateOSPolicyAssignment(ctx context.Context, req *osconfigpb.CreateOSPolicyAssignmentRequest, opts ...gax.CallOption) (*CreateOSPolicyAssignmentOperation, 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", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateOSPolicyAssignment[0:len(c.CallOptions.CreateOSPolicyAssignment):len(c.CallOptions.CreateOSPolicyAssignment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.CreateOSPolicyAssignment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateOSPolicyAssignmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UpdateOSPolicyAssignment update an existing OS policy assignment. +// +// This method creates a new revision of the OS policy assignment. +// +// This method returns a long running operation (LRO) that contains the +// rollout details. The rollout can be cancelled by cancelling the LRO. +// +// For more information, see Method: +// projects.locations.osPolicyAssignments.operations.cancel (at https://cloud.google.com/compute/docs/osconfig/rest/v1alpha/projects.locations.osPolicyAssignments.operations/cancel). +func (c *OsConfigZonalClient) UpdateOSPolicyAssignment(ctx context.Context, req *osconfigpb.UpdateOSPolicyAssignmentRequest, opts ...gax.CallOption) (*UpdateOSPolicyAssignmentOperation, 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", "os_policy_assignment.name", url.QueryEscape(req.GetOsPolicyAssignment().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateOSPolicyAssignment[0:len(c.CallOptions.UpdateOSPolicyAssignment):len(c.CallOptions.UpdateOSPolicyAssignment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.UpdateOSPolicyAssignment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateOSPolicyAssignmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// GetOSPolicyAssignment retrieve an existing OS policy assignment. +// +// This method always returns the latest revision. In order to retrieve a +// previous revision of the assignment, also provide the revision ID in the +// name parameter. +func (c *OsConfigZonalClient) GetOSPolicyAssignment(ctx context.Context, req *osconfigpb.GetOSPolicyAssignmentRequest, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignment, 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.GetOSPolicyAssignment[0:len(c.CallOptions.GetOSPolicyAssignment):len(c.CallOptions.GetOSPolicyAssignment)], opts...) + var resp *osconfigpb.OSPolicyAssignment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.GetOSPolicyAssignment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListOSPolicyAssignments list the OS policy assignments under the parent resource. +// +// For each OS policy assignment, the latest revision is returned. +func (c *OsConfigZonalClient) ListOSPolicyAssignments(ctx context.Context, req *osconfigpb.ListOSPolicyAssignmentsRequest, opts ...gax.CallOption) *OSPolicyAssignmentIterator { + 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.ListOSPolicyAssignments[0:len(c.CallOptions.ListOSPolicyAssignments):len(c.CallOptions.ListOSPolicyAssignments)], opts...) + it := &OSPolicyAssignmentIterator{} + req = proto.Clone(req).(*osconfigpb.ListOSPolicyAssignmentsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*osconfigpb.OSPolicyAssignment, string, error) { + var resp *osconfigpb.ListOSPolicyAssignmentsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.ListOSPolicyAssignments(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOsPolicyAssignments(), 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 +} + +// ListOSPolicyAssignmentRevisions list the OS policy assignment revisions for a given OS policy assignment. +func (c *OsConfigZonalClient) ListOSPolicyAssignmentRevisions(ctx context.Context, req *osconfigpb.ListOSPolicyAssignmentRevisionsRequest, opts ...gax.CallOption) *OSPolicyAssignmentIterator { + 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.ListOSPolicyAssignmentRevisions[0:len(c.CallOptions.ListOSPolicyAssignmentRevisions):len(c.CallOptions.ListOSPolicyAssignmentRevisions)], opts...) + it := &OSPolicyAssignmentIterator{} + req = proto.Clone(req).(*osconfigpb.ListOSPolicyAssignmentRevisionsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*osconfigpb.OSPolicyAssignment, string, error) { + var resp *osconfigpb.ListOSPolicyAssignmentRevisionsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.ListOSPolicyAssignmentRevisions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOsPolicyAssignments(), 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 +} + +// DeleteOSPolicyAssignment delete the OS policy assignment. +// +// This method creates a new revision of the OS policy assignment. +// +// This method returns a long running operation (LRO) that contains the +// rollout details. The rollout can be cancelled by cancelling the LRO. +// +// If the LRO completes and is not cancelled, all revisions associated with +// the OS policy assignment are deleted. +// +// For more information, see Method: +// projects.locations.osPolicyAssignments.operations.cancel (at https://cloud.google.com/compute/docs/osconfig/rest/v1alpha/projects.locations.osPolicyAssignments.operations/cancel). +func (c *OsConfigZonalClient) DeleteOSPolicyAssignment(ctx context.Context, req *osconfigpb.DeleteOSPolicyAssignmentRequest, opts ...gax.CallOption) (*DeleteOSPolicyAssignmentOperation, 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.DeleteOSPolicyAssignment[0:len(c.CallOptions.DeleteOSPolicyAssignment):len(c.CallOptions.DeleteOSPolicyAssignment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.DeleteOSPolicyAssignment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteOSPolicyAssignmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// GetInstanceOSPoliciesCompliance get OS policies compliance data for the specified Compute Engine VM +// instance. +func (c *OsConfigZonalClient) GetInstanceOSPoliciesCompliance(ctx context.Context, req *osconfigpb.GetInstanceOSPoliciesComplianceRequest, opts ...gax.CallOption) (*osconfigpb.InstanceOSPoliciesCompliance, 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.GetInstanceOSPoliciesCompliance[0:len(c.CallOptions.GetInstanceOSPoliciesCompliance):len(c.CallOptions.GetInstanceOSPoliciesCompliance)], opts...) + var resp *osconfigpb.InstanceOSPoliciesCompliance + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.GetInstanceOSPoliciesCompliance(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListInstanceOSPoliciesCompliances list OS policies compliance data for all Compute Engine VM instances in the +// specified zone. +func (c *OsConfigZonalClient) ListInstanceOSPoliciesCompliances(ctx context.Context, req *osconfigpb.ListInstanceOSPoliciesCompliancesRequest, opts ...gax.CallOption) *InstanceOSPoliciesComplianceIterator { + 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.ListInstanceOSPoliciesCompliances[0:len(c.CallOptions.ListInstanceOSPoliciesCompliances):len(c.CallOptions.ListInstanceOSPoliciesCompliances)], opts...) + it := &InstanceOSPoliciesComplianceIterator{} + req = proto.Clone(req).(*osconfigpb.ListInstanceOSPoliciesCompliancesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*osconfigpb.InstanceOSPoliciesCompliance, string, error) { + var resp *osconfigpb.ListInstanceOSPoliciesCompliancesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.ListInstanceOSPoliciesCompliances(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetInstanceOsPoliciesCompliances(), 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 +} + +// 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) { + 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.GetInventory[0:len(c.CallOptions.GetInventory):len(c.CallOptions.GetInventory)], opts...) + var resp *osconfigpb.Inventory + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.GetInventory(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListInventories list inventory data for all VM instances in the specified zone. +func (c *OsConfigZonalClient) ListInventories(ctx context.Context, req *osconfigpb.ListInventoriesRequest, opts ...gax.CallOption) *InventoryIterator { + 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.ListInventories[0:len(c.CallOptions.ListInventories):len(c.CallOptions.ListInventories)], opts...) + it := &InventoryIterator{} + req = proto.Clone(req).(*osconfigpb.ListInventoriesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*osconfigpb.Inventory, string, error) { + var resp *osconfigpb.ListInventoriesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.ListInventories(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetInventories(), 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 +} + +// GetVulnerabilityReport gets the vulnerability report for the specified VM instance. Only VMs with +// inventory data have vulnerability reports associated with them. +func (c *OsConfigZonalClient) GetVulnerabilityReport(ctx context.Context, req *osconfigpb.GetVulnerabilityReportRequest, opts ...gax.CallOption) (*osconfigpb.VulnerabilityReport, 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.GetVulnerabilityReport[0:len(c.CallOptions.GetVulnerabilityReport):len(c.CallOptions.GetVulnerabilityReport)], opts...) + var resp *osconfigpb.VulnerabilityReport + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.GetVulnerabilityReport(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListVulnerabilityReports list vulnerability reports for all VM instances in the specified zone. +func (c *OsConfigZonalClient) ListVulnerabilityReports(ctx context.Context, req *osconfigpb.ListVulnerabilityReportsRequest, opts ...gax.CallOption) *VulnerabilityReportIterator { + 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.ListVulnerabilityReports[0:len(c.CallOptions.ListVulnerabilityReports):len(c.CallOptions.ListVulnerabilityReports)], opts...) + it := &VulnerabilityReportIterator{} + req = proto.Clone(req).(*osconfigpb.ListVulnerabilityReportsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*osconfigpb.VulnerabilityReport, string, error) { + var resp *osconfigpb.ListVulnerabilityReportsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.osConfigZonalClient.ListVulnerabilityReports(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetVulnerabilityReports(), 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 +} + +// CreateOSPolicyAssignmentOperation manages a long-running operation from CreateOSPolicyAssignment. +type CreateOSPolicyAssignmentOperation struct { + lro *longrunning.Operation +} + +// CreateOSPolicyAssignmentOperation returns a new CreateOSPolicyAssignmentOperation from a given name. +// The name must be that of a previously created CreateOSPolicyAssignmentOperation, possibly from a different process. +func (c *OsConfigZonalClient) CreateOSPolicyAssignmentOperation(name string) *CreateOSPolicyAssignmentOperation { + return &CreateOSPolicyAssignmentOperation{ + 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 *CreateOSPolicyAssignmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignment, error) { + var resp osconfigpb.OSPolicyAssignment + 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 *CreateOSPolicyAssignmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignment, error) { + var resp osconfigpb.OSPolicyAssignment + 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 *CreateOSPolicyAssignmentOperation) Metadata() (*osconfigpb.OSPolicyAssignmentOperationMetadata, error) { + var meta osconfigpb.OSPolicyAssignmentOperationMetadata + 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 *CreateOSPolicyAssignmentOperation) 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 *CreateOSPolicyAssignmentOperation) Name() string { + return op.lro.Name() +} + +// DeleteOSPolicyAssignmentOperation manages a long-running operation from DeleteOSPolicyAssignment. +type DeleteOSPolicyAssignmentOperation struct { + lro *longrunning.Operation +} + +// DeleteOSPolicyAssignmentOperation returns a new DeleteOSPolicyAssignmentOperation from a given name. +// The name must be that of a previously created DeleteOSPolicyAssignmentOperation, possibly from a different process. +func (c *OsConfigZonalClient) DeleteOSPolicyAssignmentOperation(name string) *DeleteOSPolicyAssignmentOperation { + return &DeleteOSPolicyAssignmentOperation{ + 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 *DeleteOSPolicyAssignmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) +} + +// 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 *DeleteOSPolicyAssignmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.Poll(ctx, nil, opts...) +} + +// 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 *DeleteOSPolicyAssignmentOperation) Metadata() (*osconfigpb.OSPolicyAssignmentOperationMetadata, error) { + var meta osconfigpb.OSPolicyAssignmentOperationMetadata + 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 *DeleteOSPolicyAssignmentOperation) 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 *DeleteOSPolicyAssignmentOperation) Name() string { + return op.lro.Name() +} + +// UpdateOSPolicyAssignmentOperation manages a long-running operation from UpdateOSPolicyAssignment. +type UpdateOSPolicyAssignmentOperation struct { + lro *longrunning.Operation +} + +// UpdateOSPolicyAssignmentOperation returns a new UpdateOSPolicyAssignmentOperation from a given name. +// The name must be that of a previously created UpdateOSPolicyAssignmentOperation, possibly from a different process. +func (c *OsConfigZonalClient) UpdateOSPolicyAssignmentOperation(name string) *UpdateOSPolicyAssignmentOperation { + return &UpdateOSPolicyAssignmentOperation{ + 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 *UpdateOSPolicyAssignmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignment, error) { + var resp osconfigpb.OSPolicyAssignment + 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 *UpdateOSPolicyAssignmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*osconfigpb.OSPolicyAssignment, error) { + var resp osconfigpb.OSPolicyAssignment + 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 *UpdateOSPolicyAssignmentOperation) Metadata() (*osconfigpb.OSPolicyAssignmentOperationMetadata, error) { + var meta osconfigpb.OSPolicyAssignmentOperationMetadata + 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 *UpdateOSPolicyAssignmentOperation) 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 *UpdateOSPolicyAssignmentOperation) Name() string { + return op.lro.Name() +} + +// InstanceOSPoliciesComplianceIterator manages a stream of *osconfigpb.InstanceOSPoliciesCompliance. +type InstanceOSPoliciesComplianceIterator struct { + items []*osconfigpb.InstanceOSPoliciesCompliance + 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.InstanceOSPoliciesCompliance, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *InstanceOSPoliciesComplianceIterator) 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 *InstanceOSPoliciesComplianceIterator) Next() (*osconfigpb.InstanceOSPoliciesCompliance, error) { + var item *osconfigpb.InstanceOSPoliciesCompliance + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *InstanceOSPoliciesComplianceIterator) bufLen() int { + return len(it.items) +} + +func (it *InstanceOSPoliciesComplianceIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// InventoryIterator manages a stream of *osconfigpb.Inventory. +type InventoryIterator struct { + items []*osconfigpb.Inventory + 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.Inventory, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *InventoryIterator) 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 *InventoryIterator) Next() (*osconfigpb.Inventory, error) { + var item *osconfigpb.Inventory + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *InventoryIterator) bufLen() int { + return len(it.items) +} + +func (it *InventoryIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// OSPolicyAssignmentIterator manages a stream of *osconfigpb.OSPolicyAssignment. +type OSPolicyAssignmentIterator struct { + items []*osconfigpb.OSPolicyAssignment + 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.OSPolicyAssignment, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *OSPolicyAssignmentIterator) 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 *OSPolicyAssignmentIterator) Next() (*osconfigpb.OSPolicyAssignment, error) { + var item *osconfigpb.OSPolicyAssignment + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *OSPolicyAssignmentIterator) bufLen() int { + return len(it.items) +} + +func (it *OSPolicyAssignmentIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// VulnerabilityReportIterator manages a stream of *osconfigpb.VulnerabilityReport. +type VulnerabilityReportIterator struct { + items []*osconfigpb.VulnerabilityReport + 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.VulnerabilityReport, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *VulnerabilityReportIterator) 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 *VulnerabilityReportIterator) Next() (*osconfigpb.VulnerabilityReport, error) { + var item *osconfigpb.VulnerabilityReport + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *VulnerabilityReportIterator) bufLen() int { + return len(it.items) +} + +func (it *VulnerabilityReportIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/osconfig/apiv1alpha/os_config_zonal_client_example_test.go b/osconfig/apiv1alpha/os_config_zonal_client_example_test.go new file mode 100644 index 00000000000..c3b09c16695 --- /dev/null +++ b/osconfig/apiv1alpha/os_config_zonal_client_example_test.go @@ -0,0 +1,323 @@ +// Copyright 2021 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 osconfig_test + +import ( + "context" + + osconfig "cloud.google.com/go/osconfig/apiv1alpha" + "google.golang.org/api/iterator" + osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" +) + +func ExampleNewOsConfigZonalClient() { + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleOsConfigZonalClient_CreateOSPolicyAssignment() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.CreateOSPolicyAssignmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateOSPolicyAssignment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_UpdateOSPolicyAssignment() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.UpdateOSPolicyAssignmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateOSPolicyAssignment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_GetOSPolicyAssignment() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.GetOSPolicyAssignmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetOSPolicyAssignment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_ListOSPolicyAssignments() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.ListOSPolicyAssignmentsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListOSPolicyAssignments(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleOsConfigZonalClient_ListOSPolicyAssignmentRevisions() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.ListOSPolicyAssignmentRevisionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListOSPolicyAssignmentRevisions(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleOsConfigZonalClient_DeleteOSPolicyAssignment() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.DeleteOSPolicyAssignmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteOSPolicyAssignment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleOsConfigZonalClient_GetInstanceOSPoliciesCompliance() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.GetInstanceOSPoliciesComplianceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetInstanceOSPoliciesCompliance(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_ListInstanceOSPoliciesCompliances() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.ListInstanceOSPoliciesCompliancesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListInstanceOSPoliciesCompliances(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() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.GetInventoryRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetInventory(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_ListInventories() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.ListInventoriesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListInventories(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleOsConfigZonalClient_GetVulnerabilityReport() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.GetVulnerabilityReportRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetVulnerabilityReport(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleOsConfigZonalClient_ListVulnerabilityReports() { + // import osconfigpb "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := osconfig.NewOsConfigZonalClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &osconfigpb.ListVulnerabilityReportsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListVulnerabilityReports(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +}