diff --git a/appengine/apiv1/applications_client.go b/appengine/apiv1/applications_client.go new file mode 100644 index 00000000000..1c4812afa02 --- /dev/null +++ b/appengine/apiv1/applications_client.go @@ -0,0 +1,460 @@ +// 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 appengine + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newApplicationsClientHook clientHook + +// ApplicationsCallOptions contains the retry settings for each method of ApplicationsClient. +type ApplicationsCallOptions struct { + GetApplication []gax.CallOption + CreateApplication []gax.CallOption + UpdateApplication []gax.CallOption + RepairApplication []gax.CallOption +} + +func defaultApplicationsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultApplicationsCallOptions() *ApplicationsCallOptions { + return &ApplicationsCallOptions{ + GetApplication: []gax.CallOption{}, + CreateApplication: []gax.CallOption{}, + UpdateApplication: []gax.CallOption{}, + RepairApplication: []gax.CallOption{}, + } +} + +// ApplicationsClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type ApplicationsClient 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. + applicationsClient appenginepb.ApplicationsClient + + // 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 *ApplicationsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewApplicationsClient creates a new applications client. +// +// Manages App Engine applications. +func NewApplicationsClient(ctx context.Context, opts ...option.ClientOption) (*ApplicationsClient, error) { + clientOpts := defaultApplicationsClientOptions() + + if newApplicationsClientHook != nil { + hookOpts, err := newApplicationsClientHook(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 := &ApplicationsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultApplicationsCallOptions(), + + applicationsClient: appenginepb.NewApplicationsClient(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 *ApplicationsClient) 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 *ApplicationsClient) 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 *ApplicationsClient) 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...)) +} + +// GetApplication gets information about an application. +func (c *ApplicationsClient) GetApplication(ctx context.Context, req *appenginepb.GetApplicationRequest, opts ...gax.CallOption) (*appenginepb.Application, error) { + 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.GetApplication[0:len(c.CallOptions.GetApplication):len(c.CallOptions.GetApplication)], opts...) + var resp *appenginepb.Application + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.applicationsClient.GetApplication(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateApplication creates an App Engine application for a Google Cloud Platform project. +// Required fields: +// +// id - The ID of the target Cloud Platform project. +// +// location - The region (at https://cloud.google.com/appengine/docs/locations) where you want the App Engine application located. +// +// For more information about App Engine applications, see Managing Projects, Applications, and Billing (at https://cloud.google.com/appengine/docs/standard/python/console/). +func (c *ApplicationsClient) CreateApplication(ctx context.Context, req *appenginepb.CreateApplicationRequest, opts ...gax.CallOption) (*CreateApplicationOperation, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.CreateApplication[0:len(c.CallOptions.CreateApplication):len(c.CallOptions.CreateApplication)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.applicationsClient.CreateApplication(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateApplicationOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UpdateApplication updates the specified Application resource. +// You can update the following fields: +// +// auth_domain - Google authentication domain for controlling user access to the application. +// +// default_cookie_expiration - Cookie expiration policy for the application. +func (c *ApplicationsClient) UpdateApplication(ctx context.Context, req *appenginepb.UpdateApplicationRequest, opts ...gax.CallOption) (*UpdateApplicationOperation, error) { + 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.UpdateApplication[0:len(c.CallOptions.UpdateApplication):len(c.CallOptions.UpdateApplication)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.applicationsClient.UpdateApplication(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateApplicationOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// RepairApplication recreates the required App Engine features for the specified App Engine +// application, for example a Cloud Storage bucket or App Engine service +// account. +// Use this method if you receive an error message about a missing feature, +// for example, Error retrieving the App Engine service account. +// If you have deleted your App Engine service account, this will +// not be able to recreate it. Instead, you should attempt to use the +// IAM undelete API if possible at https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/undelete?apix_params={ (at https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/undelete?apix_params=%7B)“name”%3A"projects%2F-%2FserviceAccounts%2Funique_id"%2C"resource"%3A%7B%7D%7D . +// If the deletion was recent, the numeric ID can be found in the Cloud +// Console Activity Log. +func (c *ApplicationsClient) RepairApplication(ctx context.Context, req *appenginepb.RepairApplicationRequest, opts ...gax.CallOption) (*RepairApplicationOperation, error) { + 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.RepairApplication[0:len(c.CallOptions.RepairApplication):len(c.CallOptions.RepairApplication)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.applicationsClient.RepairApplication(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &RepairApplicationOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// CreateApplicationOperation manages a long-running operation from CreateApplication. +type CreateApplicationOperation struct { + lro *longrunning.Operation +} + +// CreateApplicationOperation returns a new CreateApplicationOperation from a given name. +// The name must be that of a previously created CreateApplicationOperation, possibly from a different process. +func (c *ApplicationsClient) CreateApplicationOperation(name string) *CreateApplicationOperation { + return &CreateApplicationOperation{ + 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 *CreateApplicationOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) { + var resp appenginepb.Application + 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 *CreateApplicationOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) { + var resp appenginepb.Application + 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 *CreateApplicationOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *CreateApplicationOperation) 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 *CreateApplicationOperation) Name() string { + return op.lro.Name() +} + +// RepairApplicationOperation manages a long-running operation from RepairApplication. +type RepairApplicationOperation struct { + lro *longrunning.Operation +} + +// RepairApplicationOperation returns a new RepairApplicationOperation from a given name. +// The name must be that of a previously created RepairApplicationOperation, possibly from a different process. +func (c *ApplicationsClient) RepairApplicationOperation(name string) *RepairApplicationOperation { + return &RepairApplicationOperation{ + 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 *RepairApplicationOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) { + var resp appenginepb.Application + 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 *RepairApplicationOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) { + var resp appenginepb.Application + 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 *RepairApplicationOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *RepairApplicationOperation) 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 *RepairApplicationOperation) Name() string { + return op.lro.Name() +} + +// UpdateApplicationOperation manages a long-running operation from UpdateApplication. +type UpdateApplicationOperation struct { + lro *longrunning.Operation +} + +// UpdateApplicationOperation returns a new UpdateApplicationOperation from a given name. +// The name must be that of a previously created UpdateApplicationOperation, possibly from a different process. +func (c *ApplicationsClient) UpdateApplicationOperation(name string) *UpdateApplicationOperation { + return &UpdateApplicationOperation{ + 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 *UpdateApplicationOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) { + var resp appenginepb.Application + 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 *UpdateApplicationOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Application, error) { + var resp appenginepb.Application + 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 *UpdateApplicationOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *UpdateApplicationOperation) 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 *UpdateApplicationOperation) Name() string { + return op.lro.Name() +} diff --git a/appengine/apiv1/applications_client_example_test.go b/appengine/apiv1/applications_client_example_test.go new file mode 100644 index 00000000000..59566c9c2d7 --- /dev/null +++ b/appengine/apiv1/applications_client_example_test.go @@ -0,0 +1,129 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewApplicationsClient() { + ctx := context.Background() + c, err := appengine.NewApplicationsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleApplicationsClient_GetApplication() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewApplicationsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetApplicationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetApplication(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleApplicationsClient_CreateApplication() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewApplicationsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.CreateApplicationRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateApplication(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleApplicationsClient_UpdateApplication() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewApplicationsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.UpdateApplicationRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateApplication(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleApplicationsClient_RepairApplication() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewApplicationsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.RepairApplicationRequest{ + // TODO: Fill request struct fields. + } + op, err := c.RepairApplication(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/appengine/apiv1/authorized_certificates_client.go b/appengine/apiv1/authorized_certificates_client.go new file mode 100644 index 00000000000..2b366517dbf --- /dev/null +++ b/appengine/apiv1/authorized_certificates_client.go @@ -0,0 +1,301 @@ +// 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 appengine + +import ( + "context" + "fmt" + "math" + "net/url" + + "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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newAuthorizedCertificatesClientHook clientHook + +// AuthorizedCertificatesCallOptions contains the retry settings for each method of AuthorizedCertificatesClient. +type AuthorizedCertificatesCallOptions struct { + ListAuthorizedCertificates []gax.CallOption + GetAuthorizedCertificate []gax.CallOption + CreateAuthorizedCertificate []gax.CallOption + UpdateAuthorizedCertificate []gax.CallOption + DeleteAuthorizedCertificate []gax.CallOption +} + +func defaultAuthorizedCertificatesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultAuthorizedCertificatesCallOptions() *AuthorizedCertificatesCallOptions { + return &AuthorizedCertificatesCallOptions{ + ListAuthorizedCertificates: []gax.CallOption{}, + GetAuthorizedCertificate: []gax.CallOption{}, + CreateAuthorizedCertificate: []gax.CallOption{}, + UpdateAuthorizedCertificate: []gax.CallOption{}, + DeleteAuthorizedCertificate: []gax.CallOption{}, + } +} + +// AuthorizedCertificatesClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type AuthorizedCertificatesClient 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. + authorizedCertificatesClient appenginepb.AuthorizedCertificatesClient + + // The call options for this service. + CallOptions *AuthorizedCertificatesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAuthorizedCertificatesClient creates a new authorized certificates client. +// +// Manages SSL certificates a user is authorized to administer. A user can +// administer any SSL certificates applicable to their authorized domains. +func NewAuthorizedCertificatesClient(ctx context.Context, opts ...option.ClientOption) (*AuthorizedCertificatesClient, error) { + clientOpts := defaultAuthorizedCertificatesClientOptions() + + if newAuthorizedCertificatesClientHook != nil { + hookOpts, err := newAuthorizedCertificatesClientHook(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 := &AuthorizedCertificatesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultAuthorizedCertificatesCallOptions(), + + authorizedCertificatesClient: appenginepb.NewAuthorizedCertificatesClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AuthorizedCertificatesClient) 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 *AuthorizedCertificatesClient) 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 *AuthorizedCertificatesClient) 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...)) +} + +// ListAuthorizedCertificates lists all SSL certificates the user is authorized to administer. +func (c *AuthorizedCertificatesClient) ListAuthorizedCertificates(ctx context.Context, req *appenginepb.ListAuthorizedCertificatesRequest, opts ...gax.CallOption) *AuthorizedCertificateIterator { + 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.ListAuthorizedCertificates[0:len(c.CallOptions.ListAuthorizedCertificates):len(c.CallOptions.ListAuthorizedCertificates)], opts...) + it := &AuthorizedCertificateIterator{} + req = proto.Clone(req).(*appenginepb.ListAuthorizedCertificatesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.AuthorizedCertificate, string, error) { + var resp *appenginepb.ListAuthorizedCertificatesResponse + 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.authorizedCertificatesClient.ListAuthorizedCertificates(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetCertificates(), 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 +} + +// GetAuthorizedCertificate gets the specified SSL certificate. +func (c *AuthorizedCertificatesClient) GetAuthorizedCertificate(ctx context.Context, req *appenginepb.GetAuthorizedCertificateRequest, opts ...gax.CallOption) (*appenginepb.AuthorizedCertificate, error) { + 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.GetAuthorizedCertificate[0:len(c.CallOptions.GetAuthorizedCertificate):len(c.CallOptions.GetAuthorizedCertificate)], opts...) + var resp *appenginepb.AuthorizedCertificate + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.authorizedCertificatesClient.GetAuthorizedCertificate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateAuthorizedCertificate uploads the specified SSL certificate. +func (c *AuthorizedCertificatesClient) CreateAuthorizedCertificate(ctx context.Context, req *appenginepb.CreateAuthorizedCertificateRequest, opts ...gax.CallOption) (*appenginepb.AuthorizedCertificate, error) { + 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.CreateAuthorizedCertificate[0:len(c.CallOptions.CreateAuthorizedCertificate):len(c.CallOptions.CreateAuthorizedCertificate)], opts...) + var resp *appenginepb.AuthorizedCertificate + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.authorizedCertificatesClient.CreateAuthorizedCertificate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateAuthorizedCertificate updates the specified SSL certificate. To renew a certificate and maintain +// its existing domain mappings, update certificate_data with a new +// certificate. The new certificate must be applicable to the same domains as +// the original certificate. The certificate display_name may also be +// updated. +func (c *AuthorizedCertificatesClient) UpdateAuthorizedCertificate(ctx context.Context, req *appenginepb.UpdateAuthorizedCertificateRequest, opts ...gax.CallOption) (*appenginepb.AuthorizedCertificate, error) { + 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.UpdateAuthorizedCertificate[0:len(c.CallOptions.UpdateAuthorizedCertificate):len(c.CallOptions.UpdateAuthorizedCertificate)], opts...) + var resp *appenginepb.AuthorizedCertificate + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.authorizedCertificatesClient.UpdateAuthorizedCertificate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteAuthorizedCertificate deletes the specified SSL certificate. +func (c *AuthorizedCertificatesClient) DeleteAuthorizedCertificate(ctx context.Context, req *appenginepb.DeleteAuthorizedCertificateRequest, opts ...gax.CallOption) error { + 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.DeleteAuthorizedCertificate[0:len(c.CallOptions.DeleteAuthorizedCertificate):len(c.CallOptions.DeleteAuthorizedCertificate)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.authorizedCertificatesClient.DeleteAuthorizedCertificate(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// AuthorizedCertificateIterator manages a stream of *appenginepb.AuthorizedCertificate. +type AuthorizedCertificateIterator struct { + items []*appenginepb.AuthorizedCertificate + 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 []*appenginepb.AuthorizedCertificate, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *AuthorizedCertificateIterator) 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 *AuthorizedCertificateIterator) Next() (*appenginepb.AuthorizedCertificate, error) { + var item *appenginepb.AuthorizedCertificate + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *AuthorizedCertificateIterator) bufLen() int { + return len(it.items) +} + +func (it *AuthorizedCertificateIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/authorized_certificates_client_example_test.go b/appengine/apiv1/authorized_certificates_client_example_test.go new file mode 100644 index 00000000000..901b771c71f --- /dev/null +++ b/appengine/apiv1/authorized_certificates_client_example_test.go @@ -0,0 +1,138 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewAuthorizedCertificatesClient() { + ctx := context.Background() + c, err := appengine.NewAuthorizedCertificatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleAuthorizedCertificatesClient_ListAuthorizedCertificates() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewAuthorizedCertificatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListAuthorizedCertificatesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListAuthorizedCertificates(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleAuthorizedCertificatesClient_GetAuthorizedCertificate() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewAuthorizedCertificatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetAuthorizedCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetAuthorizedCertificate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAuthorizedCertificatesClient_CreateAuthorizedCertificate() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewAuthorizedCertificatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.CreateAuthorizedCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateAuthorizedCertificate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAuthorizedCertificatesClient_UpdateAuthorizedCertificate() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewAuthorizedCertificatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.UpdateAuthorizedCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateAuthorizedCertificate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAuthorizedCertificatesClient_DeleteAuthorizedCertificate() { + ctx := context.Background() + c, err := appengine.NewAuthorizedCertificatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DeleteAuthorizedCertificateRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteAuthorizedCertificate(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/appengine/apiv1/authorized_domains_client.go b/appengine/apiv1/authorized_domains_client.go new file mode 100644 index 00000000000..cf95e5f5b4b --- /dev/null +++ b/appengine/apiv1/authorized_domains_client.go @@ -0,0 +1,226 @@ +// 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 appengine + +import ( + "context" + "fmt" + "math" + "net/url" + + "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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newAuthorizedDomainsClientHook clientHook + +// AuthorizedDomainsCallOptions contains the retry settings for each method of AuthorizedDomainsClient. +type AuthorizedDomainsCallOptions struct { + ListAuthorizedDomains []gax.CallOption +} + +func defaultAuthorizedDomainsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultAuthorizedDomainsCallOptions() *AuthorizedDomainsCallOptions { + return &AuthorizedDomainsCallOptions{ + ListAuthorizedDomains: []gax.CallOption{}, + } +} + +// AuthorizedDomainsClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type AuthorizedDomainsClient 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. + authorizedDomainsClient appenginepb.AuthorizedDomainsClient + + // The call options for this service. + CallOptions *AuthorizedDomainsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAuthorizedDomainsClient creates a new authorized domains client. +// +// Manages domains a user is authorized to administer. To authorize use of a +// domain, verify ownership via +// Webmaster Central (at https://www.google.com/webmasters/verification/home). +func NewAuthorizedDomainsClient(ctx context.Context, opts ...option.ClientOption) (*AuthorizedDomainsClient, error) { + clientOpts := defaultAuthorizedDomainsClientOptions() + + if newAuthorizedDomainsClientHook != nil { + hookOpts, err := newAuthorizedDomainsClientHook(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 := &AuthorizedDomainsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultAuthorizedDomainsCallOptions(), + + authorizedDomainsClient: appenginepb.NewAuthorizedDomainsClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AuthorizedDomainsClient) 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 *AuthorizedDomainsClient) 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 *AuthorizedDomainsClient) 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...)) +} + +// ListAuthorizedDomains lists all domains the user is authorized to administer. +func (c *AuthorizedDomainsClient) ListAuthorizedDomains(ctx context.Context, req *appenginepb.ListAuthorizedDomainsRequest, opts ...gax.CallOption) *AuthorizedDomainIterator { + 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.ListAuthorizedDomains[0:len(c.CallOptions.ListAuthorizedDomains):len(c.CallOptions.ListAuthorizedDomains)], opts...) + it := &AuthorizedDomainIterator{} + req = proto.Clone(req).(*appenginepb.ListAuthorizedDomainsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.AuthorizedDomain, string, error) { + var resp *appenginepb.ListAuthorizedDomainsResponse + 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.authorizedDomainsClient.ListAuthorizedDomains(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetDomains(), 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 +} + +// AuthorizedDomainIterator manages a stream of *appenginepb.AuthorizedDomain. +type AuthorizedDomainIterator struct { + items []*appenginepb.AuthorizedDomain + 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 []*appenginepb.AuthorizedDomain, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *AuthorizedDomainIterator) 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 *AuthorizedDomainIterator) Next() (*appenginepb.AuthorizedDomain, error) { + var item *appenginepb.AuthorizedDomain + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *AuthorizedDomainIterator) bufLen() int { + return len(it.items) +} + +func (it *AuthorizedDomainIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/authorized_domains_client_example_test.go b/appengine/apiv1/authorized_domains_client_example_test.go new file mode 100644 index 00000000000..88d1b6028e2 --- /dev/null +++ b/appengine/apiv1/authorized_domains_client_example_test.go @@ -0,0 +1,62 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewAuthorizedDomainsClient() { + ctx := context.Background() + c, err := appengine.NewAuthorizedDomainsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleAuthorizedDomainsClient_ListAuthorizedDomains() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewAuthorizedDomainsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListAuthorizedDomainsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListAuthorizedDomains(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/appengine/apiv1/doc.go b/appengine/apiv1/doc.go new file mode 100644 index 00000000000..41d2d86c826 --- /dev/null +++ b/appengine/apiv1/doc.go @@ -0,0 +1,118 @@ +// 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 appengine is an auto-generated package for the +// App Engine Audit Data. +// +// Provisions and manages developers' App Engine applications. +// +// 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 appengine // import "cloud.google.com/go/appengine/apiv1" + +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 = "20210114" + +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/appengine.admin", + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + } +} + +// 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/appengine/apiv1/domain_mappings_client.go b/appengine/apiv1/domain_mappings_client.go new file mode 100644 index 00000000000..71db9a3593e --- /dev/null +++ b/appengine/apiv1/domain_mappings_client.go @@ -0,0 +1,528 @@ +// 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 appengine + +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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newDomainMappingsClientHook clientHook + +// DomainMappingsCallOptions contains the retry settings for each method of DomainMappingsClient. +type DomainMappingsCallOptions struct { + ListDomainMappings []gax.CallOption + GetDomainMapping []gax.CallOption + CreateDomainMapping []gax.CallOption + UpdateDomainMapping []gax.CallOption + DeleteDomainMapping []gax.CallOption +} + +func defaultDomainMappingsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultDomainMappingsCallOptions() *DomainMappingsCallOptions { + return &DomainMappingsCallOptions{ + ListDomainMappings: []gax.CallOption{}, + GetDomainMapping: []gax.CallOption{}, + CreateDomainMapping: []gax.CallOption{}, + UpdateDomainMapping: []gax.CallOption{}, + DeleteDomainMapping: []gax.CallOption{}, + } +} + +// DomainMappingsClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type DomainMappingsClient 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. + domainMappingsClient appenginepb.DomainMappingsClient + + // 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 *DomainMappingsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewDomainMappingsClient creates a new domain mappings client. +// +// Manages domains serving an application. +func NewDomainMappingsClient(ctx context.Context, opts ...option.ClientOption) (*DomainMappingsClient, error) { + clientOpts := defaultDomainMappingsClientOptions() + + if newDomainMappingsClientHook != nil { + hookOpts, err := newDomainMappingsClientHook(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 := &DomainMappingsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultDomainMappingsCallOptions(), + + domainMappingsClient: appenginepb.NewDomainMappingsClient(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 *DomainMappingsClient) 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 *DomainMappingsClient) 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 *DomainMappingsClient) 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...)) +} + +// ListDomainMappings lists the domain mappings on an application. +func (c *DomainMappingsClient) ListDomainMappings(ctx context.Context, req *appenginepb.ListDomainMappingsRequest, opts ...gax.CallOption) *DomainMappingIterator { + 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.ListDomainMappings[0:len(c.CallOptions.ListDomainMappings):len(c.CallOptions.ListDomainMappings)], opts...) + it := &DomainMappingIterator{} + req = proto.Clone(req).(*appenginepb.ListDomainMappingsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.DomainMapping, string, error) { + var resp *appenginepb.ListDomainMappingsResponse + 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.domainMappingsClient.ListDomainMappings(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetDomainMappings(), 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 +} + +// GetDomainMapping gets the specified domain mapping. +func (c *DomainMappingsClient) GetDomainMapping(ctx context.Context, req *appenginepb.GetDomainMappingRequest, opts ...gax.CallOption) (*appenginepb.DomainMapping, error) { + 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.GetDomainMapping[0:len(c.CallOptions.GetDomainMapping):len(c.CallOptions.GetDomainMapping)], opts...) + var resp *appenginepb.DomainMapping + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.domainMappingsClient.GetDomainMapping(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateDomainMapping maps a domain to an application. A user must be authorized to administer a +// domain in order to map it to an application. For a list of available +// authorized domains, see AuthorizedDomains.ListAuthorizedDomains (at ). +func (c *DomainMappingsClient) CreateDomainMapping(ctx context.Context, req *appenginepb.CreateDomainMappingRequest, opts ...gax.CallOption) (*CreateDomainMappingOperation, error) { + 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.CreateDomainMapping[0:len(c.CallOptions.CreateDomainMapping):len(c.CallOptions.CreateDomainMapping)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.domainMappingsClient.CreateDomainMapping(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateDomainMappingOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UpdateDomainMapping updates the specified domain mapping. To map an SSL certificate to a +// domain mapping, update certificate_id to point to an AuthorizedCertificate +// resource. A user must be authorized to administer the associated domain +// in order to update a DomainMapping resource. +func (c *DomainMappingsClient) UpdateDomainMapping(ctx context.Context, req *appenginepb.UpdateDomainMappingRequest, opts ...gax.CallOption) (*UpdateDomainMappingOperation, error) { + 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.UpdateDomainMapping[0:len(c.CallOptions.UpdateDomainMapping):len(c.CallOptions.UpdateDomainMapping)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.domainMappingsClient.UpdateDomainMapping(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateDomainMappingOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteDomainMapping deletes the specified domain mapping. A user must be authorized to +// administer the associated domain in order to delete a DomainMapping +// resource. +func (c *DomainMappingsClient) DeleteDomainMapping(ctx context.Context, req *appenginepb.DeleteDomainMappingRequest, opts ...gax.CallOption) (*DeleteDomainMappingOperation, error) { + 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.DeleteDomainMapping[0:len(c.CallOptions.DeleteDomainMapping):len(c.CallOptions.DeleteDomainMapping)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.domainMappingsClient.DeleteDomainMapping(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteDomainMappingOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// CreateDomainMappingOperation manages a long-running operation from CreateDomainMapping. +type CreateDomainMappingOperation struct { + lro *longrunning.Operation +} + +// CreateDomainMappingOperation returns a new CreateDomainMappingOperation from a given name. +// The name must be that of a previously created CreateDomainMappingOperation, possibly from a different process. +func (c *DomainMappingsClient) CreateDomainMappingOperation(name string) *CreateDomainMappingOperation { + return &CreateDomainMappingOperation{ + 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 *CreateDomainMappingOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.DomainMapping, error) { + var resp appenginepb.DomainMapping + 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 *CreateDomainMappingOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.DomainMapping, error) { + var resp appenginepb.DomainMapping + 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 *CreateDomainMappingOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *CreateDomainMappingOperation) 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 *CreateDomainMappingOperation) Name() string { + return op.lro.Name() +} + +// DeleteDomainMappingOperation manages a long-running operation from DeleteDomainMapping. +type DeleteDomainMappingOperation struct { + lro *longrunning.Operation +} + +// DeleteDomainMappingOperation returns a new DeleteDomainMappingOperation from a given name. +// The name must be that of a previously created DeleteDomainMappingOperation, possibly from a different process. +func (c *DomainMappingsClient) DeleteDomainMappingOperation(name string) *DeleteDomainMappingOperation { + return &DeleteDomainMappingOperation{ + 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 *DeleteDomainMappingOperation) 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 *DeleteDomainMappingOperation) 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 *DeleteDomainMappingOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *DeleteDomainMappingOperation) 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 *DeleteDomainMappingOperation) Name() string { + return op.lro.Name() +} + +// UpdateDomainMappingOperation manages a long-running operation from UpdateDomainMapping. +type UpdateDomainMappingOperation struct { + lro *longrunning.Operation +} + +// UpdateDomainMappingOperation returns a new UpdateDomainMappingOperation from a given name. +// The name must be that of a previously created UpdateDomainMappingOperation, possibly from a different process. +func (c *DomainMappingsClient) UpdateDomainMappingOperation(name string) *UpdateDomainMappingOperation { + return &UpdateDomainMappingOperation{ + 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 *UpdateDomainMappingOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.DomainMapping, error) { + var resp appenginepb.DomainMapping + 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 *UpdateDomainMappingOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.DomainMapping, error) { + var resp appenginepb.DomainMapping + 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 *UpdateDomainMappingOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *UpdateDomainMappingOperation) 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 *UpdateDomainMappingOperation) Name() string { + return op.lro.Name() +} + +// DomainMappingIterator manages a stream of *appenginepb.DomainMapping. +type DomainMappingIterator struct { + items []*appenginepb.DomainMapping + 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 []*appenginepb.DomainMapping, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *DomainMappingIterator) 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 *DomainMappingIterator) Next() (*appenginepb.DomainMapping, error) { + var item *appenginepb.DomainMapping + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *DomainMappingIterator) bufLen() int { + return len(it.items) +} + +func (it *DomainMappingIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/domain_mappings_client_example_test.go b/appengine/apiv1/domain_mappings_client_example_test.go new file mode 100644 index 00000000000..f3aed511314 --- /dev/null +++ b/appengine/apiv1/domain_mappings_client_example_test.go @@ -0,0 +1,155 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewDomainMappingsClient() { + ctx := context.Background() + c, err := appengine.NewDomainMappingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleDomainMappingsClient_ListDomainMappings() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewDomainMappingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListDomainMappingsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListDomainMappings(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleDomainMappingsClient_GetDomainMapping() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewDomainMappingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetDomainMappingRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetDomainMapping(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDomainMappingsClient_CreateDomainMapping() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewDomainMappingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.CreateDomainMappingRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateDomainMapping(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDomainMappingsClient_UpdateDomainMapping() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewDomainMappingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.UpdateDomainMappingRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateDomainMapping(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDomainMappingsClient_DeleteDomainMapping() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewDomainMappingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DeleteDomainMappingRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteDomainMapping(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/appengine/apiv1/firewall_client.go b/appengine/apiv1/firewall_client.go new file mode 100644 index 00000000000..196ef3e83e5 --- /dev/null +++ b/appengine/apiv1/firewall_client.go @@ -0,0 +1,328 @@ +// 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 appengine + +import ( + "context" + "fmt" + "math" + "net/url" + + "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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newFirewallClientHook clientHook + +// FirewallCallOptions contains the retry settings for each method of FirewallClient. +type FirewallCallOptions struct { + ListIngressRules []gax.CallOption + BatchUpdateIngressRules []gax.CallOption + CreateIngressRule []gax.CallOption + GetIngressRule []gax.CallOption + UpdateIngressRule []gax.CallOption + DeleteIngressRule []gax.CallOption +} + +func defaultFirewallClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultFirewallCallOptions() *FirewallCallOptions { + return &FirewallCallOptions{ + ListIngressRules: []gax.CallOption{}, + BatchUpdateIngressRules: []gax.CallOption{}, + CreateIngressRule: []gax.CallOption{}, + GetIngressRule: []gax.CallOption{}, + UpdateIngressRule: []gax.CallOption{}, + DeleteIngressRule: []gax.CallOption{}, + } +} + +// FirewallClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type FirewallClient 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. + firewallClient appenginepb.FirewallClient + + // The call options for this service. + CallOptions *FirewallCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewFirewallClient creates a new firewall client. +// +// Firewall resources are used to define a collection of access control rules +// for an Application. Each rule is defined with a position which specifies +// the rule’s order in the sequence of rules, an IP range to be matched against +// requests, and an action to take upon matching requests. +// +// Every request is evaluated against the Firewall rules in priority order. +// Processesing stops at the first rule which matches the request’s IP address. +// A final rule always specifies an action that applies to all remaining +// IP addresses. The default final rule for a newly-created application will be +// set to “allow” if not otherwise specified by the user. +func NewFirewallClient(ctx context.Context, opts ...option.ClientOption) (*FirewallClient, error) { + clientOpts := defaultFirewallClientOptions() + + if newFirewallClientHook != nil { + hookOpts, err := newFirewallClientHook(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 := &FirewallClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultFirewallCallOptions(), + + firewallClient: appenginepb.NewFirewallClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *FirewallClient) 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 *FirewallClient) 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 *FirewallClient) 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...)) +} + +// ListIngressRules lists the firewall rules of an application. +func (c *FirewallClient) ListIngressRules(ctx context.Context, req *appenginepb.ListIngressRulesRequest, opts ...gax.CallOption) *FirewallRuleIterator { + 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.ListIngressRules[0:len(c.CallOptions.ListIngressRules):len(c.CallOptions.ListIngressRules)], opts...) + it := &FirewallRuleIterator{} + req = proto.Clone(req).(*appenginepb.ListIngressRulesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.FirewallRule, string, error) { + var resp *appenginepb.ListIngressRulesResponse + 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.firewallClient.ListIngressRules(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetIngressRules(), 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 +} + +// BatchUpdateIngressRules replaces the entire firewall ruleset in one bulk operation. This overrides +// and replaces the rules of an existing firewall with the new rules. +// +// If the final rule does not match traffic with the ‘*’ wildcard IP range, +// then an “allow all” rule is explicitly added to the end of the list. +func (c *FirewallClient) BatchUpdateIngressRules(ctx context.Context, req *appenginepb.BatchUpdateIngressRulesRequest, opts ...gax.CallOption) (*appenginepb.BatchUpdateIngressRulesResponse, error) { + 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.BatchUpdateIngressRules[0:len(c.CallOptions.BatchUpdateIngressRules):len(c.CallOptions.BatchUpdateIngressRules)], opts...) + var resp *appenginepb.BatchUpdateIngressRulesResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.firewallClient.BatchUpdateIngressRules(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateIngressRule creates a firewall rule for the application. +func (c *FirewallClient) CreateIngressRule(ctx context.Context, req *appenginepb.CreateIngressRuleRequest, opts ...gax.CallOption) (*appenginepb.FirewallRule, error) { + 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.CreateIngressRule[0:len(c.CallOptions.CreateIngressRule):len(c.CallOptions.CreateIngressRule)], opts...) + var resp *appenginepb.FirewallRule + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.firewallClient.CreateIngressRule(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetIngressRule gets the specified firewall rule. +func (c *FirewallClient) GetIngressRule(ctx context.Context, req *appenginepb.GetIngressRuleRequest, opts ...gax.CallOption) (*appenginepb.FirewallRule, error) { + 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.GetIngressRule[0:len(c.CallOptions.GetIngressRule):len(c.CallOptions.GetIngressRule)], opts...) + var resp *appenginepb.FirewallRule + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.firewallClient.GetIngressRule(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateIngressRule updates the specified firewall rule. +func (c *FirewallClient) UpdateIngressRule(ctx context.Context, req *appenginepb.UpdateIngressRuleRequest, opts ...gax.CallOption) (*appenginepb.FirewallRule, error) { + 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.UpdateIngressRule[0:len(c.CallOptions.UpdateIngressRule):len(c.CallOptions.UpdateIngressRule)], opts...) + var resp *appenginepb.FirewallRule + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.firewallClient.UpdateIngressRule(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteIngressRule deletes the specified firewall rule. +func (c *FirewallClient) DeleteIngressRule(ctx context.Context, req *appenginepb.DeleteIngressRuleRequest, opts ...gax.CallOption) error { + 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.DeleteIngressRule[0:len(c.CallOptions.DeleteIngressRule):len(c.CallOptions.DeleteIngressRule)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.firewallClient.DeleteIngressRule(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// FirewallRuleIterator manages a stream of *appenginepb.FirewallRule. +type FirewallRuleIterator struct { + items []*appenginepb.FirewallRule + 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 []*appenginepb.FirewallRule, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *FirewallRuleIterator) 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 *FirewallRuleIterator) Next() (*appenginepb.FirewallRule, error) { + var item *appenginepb.FirewallRule + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *FirewallRuleIterator) bufLen() int { + return len(it.items) +} + +func (it *FirewallRuleIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/firewall_client_example_test.go b/appengine/apiv1/firewall_client_example_test.go new file mode 100644 index 00000000000..1076b407e20 --- /dev/null +++ b/appengine/apiv1/firewall_client_example_test.go @@ -0,0 +1,158 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewFirewallClient() { + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleFirewallClient_ListIngressRules() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListIngressRulesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListIngressRules(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleFirewallClient_BatchUpdateIngressRules() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.BatchUpdateIngressRulesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.BatchUpdateIngressRules(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallClient_CreateIngressRule() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.CreateIngressRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateIngressRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallClient_GetIngressRule() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetIngressRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIngressRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallClient_UpdateIngressRule() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.UpdateIngressRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateIngressRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallClient_DeleteIngressRule() { + ctx := context.Background() + c, err := appengine.NewFirewallClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DeleteIngressRuleRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteIngressRule(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/appengine/apiv1/instances_client.go b/appengine/apiv1/instances_client.go new file mode 100644 index 00000000000..8ac56dd8acf --- /dev/null +++ b/appengine/apiv1/instances_client.go @@ -0,0 +1,452 @@ +// 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 appengine + +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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newInstancesClientHook clientHook + +// InstancesCallOptions contains the retry settings for each method of InstancesClient. +type InstancesCallOptions struct { + ListInstances []gax.CallOption + GetInstance []gax.CallOption + DeleteInstance []gax.CallOption + DebugInstance []gax.CallOption +} + +func defaultInstancesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultInstancesCallOptions() *InstancesCallOptions { + return &InstancesCallOptions{ + ListInstances: []gax.CallOption{}, + GetInstance: []gax.CallOption{}, + DeleteInstance: []gax.CallOption{}, + DebugInstance: []gax.CallOption{}, + } +} + +// InstancesClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type InstancesClient 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. + instancesClient appenginepb.InstancesClient + + // 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 *InstancesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInstancesClient creates a new instances client. +// +// Manages instances of a version. +func NewInstancesClient(ctx context.Context, opts ...option.ClientOption) (*InstancesClient, error) { + clientOpts := defaultInstancesClientOptions() + + if newInstancesClientHook != nil { + hookOpts, err := newInstancesClientHook(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 := &InstancesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultInstancesCallOptions(), + + instancesClient: appenginepb.NewInstancesClient(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 *InstancesClient) 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 *InstancesClient) 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 *InstancesClient) 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...)) +} + +// ListInstances lists the instances of a version. +// +// Tip: To aggregate details about instances over time, see the +// Stackdriver Monitoring API (at https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list). +func (c *InstancesClient) ListInstances(ctx context.Context, req *appenginepb.ListInstancesRequest, opts ...gax.CallOption) *InstanceIterator { + 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.ListInstances[0:len(c.CallOptions.ListInstances):len(c.CallOptions.ListInstances)], opts...) + it := &InstanceIterator{} + req = proto.Clone(req).(*appenginepb.ListInstancesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.Instance, string, error) { + var resp *appenginepb.ListInstancesResponse + 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.instancesClient.ListInstances(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetInstances(), 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 +} + +// GetInstance gets instance information. +func (c *InstancesClient) GetInstance(ctx context.Context, req *appenginepb.GetInstanceRequest, opts ...gax.CallOption) (*appenginepb.Instance, error) { + 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.GetInstance[0:len(c.CallOptions.GetInstance):len(c.CallOptions.GetInstance)], opts...) + var resp *appenginepb.Instance + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.instancesClient.GetInstance(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteInstance stops a running instance. +// +// The instance might be automatically recreated based on the scaling settings +// of the version. For more information, see “How Instances are Managed” +// (standard environment (at https://cloud.google.com/appengine/docs/standard/python/how-instances-are-managed) | +// flexible environment (at https://cloud.google.com/appengine/docs/flexible/python/how-instances-are-managed)). +// +// To ensure that instances are not re-created and avoid getting billed, you +// can stop all instances within the target version by changing the serving +// status of the version to STOPPED with the +// apps.services.versions.patch (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions/patch) +// method. +func (c *InstancesClient) DeleteInstance(ctx context.Context, req *appenginepb.DeleteInstanceRequest, opts ...gax.CallOption) (*DeleteInstanceOperation, error) { + 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.DeleteInstance[0:len(c.CallOptions.DeleteInstance):len(c.CallOptions.DeleteInstance)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.instancesClient.DeleteInstance(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteInstanceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DebugInstance enables debugging on a VM instance. This allows you to use the SSH +// command to connect to the virtual machine where the instance lives. +// While in “debug mode”, the instance continues to serve live traffic. +// You should delete the instance when you are done debugging and then +// allow the system to take over and determine if another instance +// should be started. +// +// Only applicable for instances in App Engine flexible environment. +func (c *InstancesClient) DebugInstance(ctx context.Context, req *appenginepb.DebugInstanceRequest, opts ...gax.CallOption) (*DebugInstanceOperation, error) { + 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.DebugInstance[0:len(c.CallOptions.DebugInstance):len(c.CallOptions.DebugInstance)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.instancesClient.DebugInstance(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DebugInstanceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DebugInstanceOperation manages a long-running operation from DebugInstance. +type DebugInstanceOperation struct { + lro *longrunning.Operation +} + +// DebugInstanceOperation returns a new DebugInstanceOperation from a given name. +// The name must be that of a previously created DebugInstanceOperation, possibly from a different process. +func (c *InstancesClient) DebugInstanceOperation(name string) *DebugInstanceOperation { + return &DebugInstanceOperation{ + 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 *DebugInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Instance, error) { + var resp appenginepb.Instance + 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 *DebugInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Instance, error) { + var resp appenginepb.Instance + 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 *DebugInstanceOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *DebugInstanceOperation) 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 *DebugInstanceOperation) Name() string { + return op.lro.Name() +} + +// DeleteInstanceOperation manages a long-running operation from DeleteInstance. +type DeleteInstanceOperation struct { + lro *longrunning.Operation +} + +// DeleteInstanceOperation returns a new DeleteInstanceOperation from a given name. +// The name must be that of a previously created DeleteInstanceOperation, possibly from a different process. +func (c *InstancesClient) DeleteInstanceOperation(name string) *DeleteInstanceOperation { + return &DeleteInstanceOperation{ + 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 *DeleteInstanceOperation) 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 *DeleteInstanceOperation) 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 *DeleteInstanceOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *DeleteInstanceOperation) 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 *DeleteInstanceOperation) Name() string { + return op.lro.Name() +} + +// InstanceIterator manages a stream of *appenginepb.Instance. +type InstanceIterator struct { + items []*appenginepb.Instance + 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 []*appenginepb.Instance, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *InstanceIterator) 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 *InstanceIterator) Next() (*appenginepb.Instance, error) { + var item *appenginepb.Instance + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *InstanceIterator) bufLen() int { + return len(it.items) +} + +func (it *InstanceIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/instances_client_example_test.go b/appengine/apiv1/instances_client_example_test.go new file mode 100644 index 00000000000..39f6279fbd9 --- /dev/null +++ b/appengine/apiv1/instances_client_example_test.go @@ -0,0 +1,130 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewInstancesClient() { + ctx := context.Background() + c, err := appengine.NewInstancesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleInstancesClient_ListInstances() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewInstancesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListInstancesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListInstances(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleInstancesClient_GetInstance() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewInstancesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetInstance(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_DeleteInstance() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewInstancesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DeleteInstanceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteInstance(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleInstancesClient_DebugInstance() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewInstancesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DebugInstanceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DebugInstance(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/appengine/apiv1/services_client.go b/appengine/apiv1/services_client.go new file mode 100644 index 00000000000..6deadc25be4 --- /dev/null +++ b/appengine/apiv1/services_client.go @@ -0,0 +1,431 @@ +// 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 appengine + +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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newServicesClientHook clientHook + +// ServicesCallOptions contains the retry settings for each method of ServicesClient. +type ServicesCallOptions struct { + ListServices []gax.CallOption + GetService []gax.CallOption + UpdateService []gax.CallOption + DeleteService []gax.CallOption +} + +func defaultServicesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultServicesCallOptions() *ServicesCallOptions { + return &ServicesCallOptions{ + ListServices: []gax.CallOption{}, + GetService: []gax.CallOption{}, + UpdateService: []gax.CallOption{}, + DeleteService: []gax.CallOption{}, + } +} + +// ServicesClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type ServicesClient 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. + servicesClient appenginepb.ServicesClient + + // 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 *ServicesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewServicesClient creates a new services client. +// +// Manages services of an application. +func NewServicesClient(ctx context.Context, opts ...option.ClientOption) (*ServicesClient, error) { + clientOpts := defaultServicesClientOptions() + + if newServicesClientHook != nil { + hookOpts, err := newServicesClientHook(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 := &ServicesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultServicesCallOptions(), + + servicesClient: appenginepb.NewServicesClient(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 *ServicesClient) 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 *ServicesClient) 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 *ServicesClient) 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...)) +} + +// ListServices lists all the services in the application. +func (c *ServicesClient) ListServices(ctx context.Context, req *appenginepb.ListServicesRequest, opts ...gax.CallOption) *ServiceIterator { + 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.ListServices[0:len(c.CallOptions.ListServices):len(c.CallOptions.ListServices)], opts...) + it := &ServiceIterator{} + req = proto.Clone(req).(*appenginepb.ListServicesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.Service, string, error) { + var resp *appenginepb.ListServicesResponse + 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.servicesClient.ListServices(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetServices(), 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 +} + +// GetService gets the current configuration of the specified service. +func (c *ServicesClient) GetService(ctx context.Context, req *appenginepb.GetServiceRequest, opts ...gax.CallOption) (*appenginepb.Service, error) { + 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.GetService[0:len(c.CallOptions.GetService):len(c.CallOptions.GetService)], opts...) + var resp *appenginepb.Service + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.servicesClient.GetService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateService updates the configuration of the specified service. +func (c *ServicesClient) UpdateService(ctx context.Context, req *appenginepb.UpdateServiceRequest, opts ...gax.CallOption) (*UpdateServiceOperation, error) { + 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.UpdateService[0:len(c.CallOptions.UpdateService):len(c.CallOptions.UpdateService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.servicesClient.UpdateService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteService deletes the specified service and all enclosed versions. +func (c *ServicesClient) DeleteService(ctx context.Context, req *appenginepb.DeleteServiceRequest, opts ...gax.CallOption) (*DeleteServiceOperation, error) { + 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.DeleteService[0:len(c.CallOptions.DeleteService):len(c.CallOptions.DeleteService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.servicesClient.DeleteService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteServiceOperation manages a long-running operation from DeleteService. +type DeleteServiceOperation struct { + lro *longrunning.Operation +} + +// DeleteServiceOperation returns a new DeleteServiceOperation from a given name. +// The name must be that of a previously created DeleteServiceOperation, possibly from a different process. +func (c *ServicesClient) DeleteServiceOperation(name string) *DeleteServiceOperation { + return &DeleteServiceOperation{ + 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 *DeleteServiceOperation) 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 *DeleteServiceOperation) 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 *DeleteServiceOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *DeleteServiceOperation) 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 *DeleteServiceOperation) Name() string { + return op.lro.Name() +} + +// UpdateServiceOperation manages a long-running operation from UpdateService. +type UpdateServiceOperation struct { + lro *longrunning.Operation +} + +// UpdateServiceOperation returns a new UpdateServiceOperation from a given name. +// The name must be that of a previously created UpdateServiceOperation, possibly from a different process. +func (c *ServicesClient) UpdateServiceOperation(name string) *UpdateServiceOperation { + return &UpdateServiceOperation{ + 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 *UpdateServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Service, error) { + var resp appenginepb.Service + 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 *UpdateServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Service, error) { + var resp appenginepb.Service + 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 *UpdateServiceOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *UpdateServiceOperation) 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 *UpdateServiceOperation) Name() string { + return op.lro.Name() +} + +// ServiceIterator manages a stream of *appenginepb.Service. +type ServiceIterator struct { + items []*appenginepb.Service + 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 []*appenginepb.Service, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ServiceIterator) 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 *ServiceIterator) Next() (*appenginepb.Service, error) { + var item *appenginepb.Service + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ServiceIterator) bufLen() int { + return len(it.items) +} + +func (it *ServiceIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/services_client_example_test.go b/appengine/apiv1/services_client_example_test.go new file mode 100644 index 00000000000..0b8019b35fc --- /dev/null +++ b/appengine/apiv1/services_client_example_test.go @@ -0,0 +1,130 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewServicesClient() { + ctx := context.Background() + c, err := appengine.NewServicesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleServicesClient_ListServices() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewServicesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListServicesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListServices(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleServicesClient_GetService() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewServicesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetService(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServicesClient_UpdateService() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewServicesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.UpdateServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServicesClient_DeleteService() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewServicesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DeleteServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/appengine/apiv1/versions_client.go b/appengine/apiv1/versions_client.go new file mode 100644 index 00000000000..a1c3146bee7 --- /dev/null +++ b/appengine/apiv1/versions_client.go @@ -0,0 +1,567 @@ +// 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 appengine + +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" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newVersionsClientHook clientHook + +// VersionsCallOptions contains the retry settings for each method of VersionsClient. +type VersionsCallOptions struct { + ListVersions []gax.CallOption + GetVersion []gax.CallOption + CreateVersion []gax.CallOption + UpdateVersion []gax.CallOption + DeleteVersion []gax.CallOption +} + +func defaultVersionsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("appengine.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultVersionsCallOptions() *VersionsCallOptions { + return &VersionsCallOptions{ + ListVersions: []gax.CallOption{}, + GetVersion: []gax.CallOption{}, + CreateVersion: []gax.CallOption{}, + UpdateVersion: []gax.CallOption{}, + DeleteVersion: []gax.CallOption{}, + } +} + +// VersionsClient is a client for interacting with App Engine Audit Data. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type VersionsClient 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. + versionsClient appenginepb.VersionsClient + + // 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 *VersionsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewVersionsClient creates a new versions client. +// +// Manages versions of a service. +func NewVersionsClient(ctx context.Context, opts ...option.ClientOption) (*VersionsClient, error) { + clientOpts := defaultVersionsClientOptions() + + if newVersionsClientHook != nil { + hookOpts, err := newVersionsClientHook(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 := &VersionsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultVersionsCallOptions(), + + versionsClient: appenginepb.NewVersionsClient(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 *VersionsClient) 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 *VersionsClient) 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 *VersionsClient) 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...)) +} + +// ListVersions lists the versions of a service. +func (c *VersionsClient) ListVersions(ctx context.Context, req *appenginepb.ListVersionsRequest, opts ...gax.CallOption) *VersionIterator { + 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.ListVersions[0:len(c.CallOptions.ListVersions):len(c.CallOptions.ListVersions)], opts...) + it := &VersionIterator{} + req = proto.Clone(req).(*appenginepb.ListVersionsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*appenginepb.Version, string, error) { + var resp *appenginepb.ListVersionsResponse + 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.versionsClient.ListVersions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetVersions(), 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 +} + +// GetVersion gets the specified Version resource. +// By default, only a BASIC_VIEW will be returned. +// Specify the FULL_VIEW parameter to get the full resource. +func (c *VersionsClient) GetVersion(ctx context.Context, req *appenginepb.GetVersionRequest, opts ...gax.CallOption) (*appenginepb.Version, error) { + 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.GetVersion[0:len(c.CallOptions.GetVersion):len(c.CallOptions.GetVersion)], opts...) + var resp *appenginepb.Version + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.GetVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateVersion deploys code and resource files to a new version. +func (c *VersionsClient) CreateVersion(ctx context.Context, req *appenginepb.CreateVersionRequest, opts ...gax.CallOption) (*CreateVersionOperation, error) { + 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.CreateVersion[0:len(c.CallOptions.CreateVersion):len(c.CallOptions.CreateVersion)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.CreateVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UpdateVersion updates the specified Version resource. +// You can specify the following fields depending on the App Engine +// environment and type of scaling that the version resource uses: +// +// Standard environment +// +// instance_class (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.instance_class) +// +// automatic scaling in the standard environment: +// +// automatic_scaling.min_idle_instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.automatic_scaling) +// +// automatic_scaling.max_idle_instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.automatic_scaling) +// +// automaticScaling.standard_scheduler_settings.max_instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#StandardSchedulerSettings) +// +// automaticScaling.standard_scheduler_settings.min_instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#StandardSchedulerSettings) +// +// automaticScaling.standard_scheduler_settings.target_cpu_utilization (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#StandardSchedulerSettings) +// +// automaticScaling.standard_scheduler_settings.target_throughput_utilization (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#StandardSchedulerSettings) +// +// basic scaling or manual scaling in the standard environment: +// +// serving_status (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.serving_status) +// +// manual_scaling.instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#manualscaling) +// +// Flexible environment +// +// serving_status (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.serving_status) +// +// automatic scaling in the flexible environment: +// +// automatic_scaling.min_total_instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.automatic_scaling) +// +// automatic_scaling.max_total_instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.automatic_scaling) +// +// automatic_scaling.cool_down_period_sec (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.automatic_scaling) +// +// automatic_scaling.cpu_utilization.target_utilization (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#Version.FIELDS.automatic_scaling) +// +// manual scaling in the flexible environment: +// +// manual_scaling.instances (at https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#manualscaling) +func (c *VersionsClient) UpdateVersion(ctx context.Context, req *appenginepb.UpdateVersionRequest, opts ...gax.CallOption) (*UpdateVersionOperation, error) { + 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.UpdateVersion[0:len(c.CallOptions.UpdateVersion):len(c.CallOptions.UpdateVersion)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.UpdateVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteVersion deletes an existing Version resource. +func (c *VersionsClient) DeleteVersion(ctx context.Context, req *appenginepb.DeleteVersionRequest, opts ...gax.CallOption) (*DeleteVersionOperation, error) { + 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.DeleteVersion[0:len(c.CallOptions.DeleteVersion):len(c.CallOptions.DeleteVersion)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.DeleteVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// CreateVersionOperation manages a long-running operation from CreateVersion. +type CreateVersionOperation struct { + lro *longrunning.Operation +} + +// CreateVersionOperation returns a new CreateVersionOperation from a given name. +// The name must be that of a previously created CreateVersionOperation, possibly from a different process. +func (c *VersionsClient) CreateVersionOperation(name string) *CreateVersionOperation { + return &CreateVersionOperation{ + 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 *CreateVersionOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Version, error) { + var resp appenginepb.Version + 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 *CreateVersionOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Version, error) { + var resp appenginepb.Version + 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 *CreateVersionOperation) Metadata() (*appenginepb.CreateVersionMetadataV1, error) { + var meta appenginepb.CreateVersionMetadataV1 + 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 *CreateVersionOperation) 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 *CreateVersionOperation) Name() string { + return op.lro.Name() +} + +// DeleteVersionOperation manages a long-running operation from DeleteVersion. +type DeleteVersionOperation struct { + lro *longrunning.Operation +} + +// DeleteVersionOperation returns a new DeleteVersionOperation from a given name. +// The name must be that of a previously created DeleteVersionOperation, possibly from a different process. +func (c *VersionsClient) DeleteVersionOperation(name string) *DeleteVersionOperation { + return &DeleteVersionOperation{ + 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 *DeleteVersionOperation) 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 *DeleteVersionOperation) 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 *DeleteVersionOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *DeleteVersionOperation) 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 *DeleteVersionOperation) Name() string { + return op.lro.Name() +} + +// UpdateVersionOperation manages a long-running operation from UpdateVersion. +type UpdateVersionOperation struct { + lro *longrunning.Operation +} + +// UpdateVersionOperation returns a new UpdateVersionOperation from a given name. +// The name must be that of a previously created UpdateVersionOperation, possibly from a different process. +func (c *VersionsClient) UpdateVersionOperation(name string) *UpdateVersionOperation { + return &UpdateVersionOperation{ + 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 *UpdateVersionOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Version, error) { + var resp appenginepb.Version + 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 *UpdateVersionOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*appenginepb.Version, error) { + var resp appenginepb.Version + 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 *UpdateVersionOperation) Metadata() (*appenginepb.OperationMetadataV1, error) { + var meta appenginepb.OperationMetadataV1 + 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 *UpdateVersionOperation) 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 *UpdateVersionOperation) Name() string { + return op.lro.Name() +} + +// VersionIterator manages a stream of *appenginepb.Version. +type VersionIterator struct { + items []*appenginepb.Version + 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 []*appenginepb.Version, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *VersionIterator) 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 *VersionIterator) Next() (*appenginepb.Version, error) { + var item *appenginepb.Version + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *VersionIterator) bufLen() int { + return len(it.items) +} + +func (it *VersionIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/appengine/apiv1/versions_client_example_test.go b/appengine/apiv1/versions_client_example_test.go new file mode 100644 index 00000000000..ede257f1381 --- /dev/null +++ b/appengine/apiv1/versions_client_example_test.go @@ -0,0 +1,155 @@ +// 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 appengine_test + +import ( + "context" + + appengine "cloud.google.com/go/appengine/apiv1" + "google.golang.org/api/iterator" + appenginepb "google.golang.org/genproto/googleapis/appengine/v1" +) + +func ExampleNewVersionsClient() { + ctx := context.Background() + c, err := appengine.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleVersionsClient_ListVersions() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := appengine.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.ListVersionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListVersions(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleVersionsClient_GetVersion() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.GetVersionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVersionsClient_CreateVersion() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.CreateVersionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVersionsClient_UpdateVersion() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.UpdateVersionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVersionsClient_DeleteVersion() { + // import appenginepb "google.golang.org/genproto/googleapis/appengine/v1" + + ctx := context.Background() + c, err := appengine.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &appenginepb.DeleteVersionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index d59d3da1a92..e4df692741a 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -23,6 +23,14 @@ "docs_url": "https://pkg.go.dev/cloud.google.com/go/analytics/data/apiv1alpha", "release_level": "alpha" }, + "cloud.google.com/go/appengine/apiv1": { + "distribution_name": "cloud.google.com/go/appengine/apiv1", + "description": "App Engine Audit Data", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://pkg.go.dev/cloud.google.com/go/appengine/apiv1", + "release_level": "beta" + }, "cloud.google.com/go/area120/tables/apiv1alpha1": { "distribution_name": "cloud.google.com/go/area120/tables/apiv1alpha1", "description": "", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 671ed03ebec..030371efb5e 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -874,6 +874,13 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/cloud/retail/v2/retail_v2.yaml", releaseLevel: "ga", }, + { + inputDirectoryPath: "google/appengine/v1", + pkg: "appengine", + importPath: "cloud.google.com/go/appengine/apiv1", + apiServiceConfigPath: "google/appengine/v1/appengine.yaml", + releaseLevel: "beta", + }, { inputDirectoryPath: "google/cloud/channel/v1", pkg: "channel", diff --git a/internal/gapicgen/generator/config_test.go b/internal/gapicgen/generator/config_test.go index 006d4533beb..7a36d43f406 100644 --- a/internal/gapicgen/generator/config_test.go +++ b/internal/gapicgen/generator/config_test.go @@ -55,12 +55,6 @@ func TestMicrogenConfigs(t *testing.T) { if entry.pkg == "" { t.Errorf("config %q (#%d) expected non-empty pkg field", entry.importPath, k) } - // TODO: Consider if we want to allow this at a later point in time. If this - // isn't supplied the config is technically valid, but the generated library - // won't include features such as retry policies. - if entry.gRPCServiceConfigPath == "" { - t.Errorf("config %q (#%d) expected non-empty gRPCServiceConfigPath", entry.importPath, k) - } if entry.apiServiceConfigPath == "" { t.Errorf("config %q (#%d) expected non-empty apiServiceConfigPath", entry.importPath, k) } diff --git a/internal/gapicgen/generator/gapics.go b/internal/gapicgen/generator/gapics.go index f2b42ae55e5..e058c71d107 100644 --- a/internal/gapicgen/generator/gapics.go +++ b/internal/gapicgen/generator/gapics.go @@ -172,9 +172,12 @@ func (g *GapicGenerator) microgen(conf *microgenConfig) error { "-I", g.protoDir, "--go_gapic_out", g.googleCloudDir, "--go_gapic_opt", fmt.Sprintf("go-gapic-package=%s;%s", conf.importPath, conf.pkg), - "--go_gapic_opt", fmt.Sprintf("grpc-service-config=%s", conf.gRPCServiceConfigPath), "--go_gapic_opt", fmt.Sprintf("gapic-service-config=%s", conf.apiServiceConfigPath), "--go_gapic_opt", fmt.Sprintf("release-level=%s", conf.releaseLevel)} + + if conf.gRPCServiceConfigPath != "" { + args = append(args, "--go_gapic_opt", fmt.Sprintf("grpc-service-config=%s", conf.gRPCServiceConfigPath)) + } args = append(args, protoFiles...) c := command("protoc", args...) c.Dir = g.googleapisDir