From 0da1a9d4e2d3dd0fab07c3ed09eaeeb3f9711900 Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Wed, 12 Jan 2022 16:12:09 -0700 Subject: [PATCH] feat(eventarc/publishing): start generating apiv1 (#5358) --- eventarc/publishing/apiv1/doc.go | 152 +++++++++++ eventarc/publishing/apiv1/gapic_metadata.json | 23 ++ eventarc/publishing/apiv1/publisher_client.go | 252 ++++++++++++++++++ .../apiv1/publisher_client_example_test.go | 56 ++++ internal/.repo-metadata-full.json | 9 + internal/gapicgen/generator/config.go | 9 + 6 files changed, 501 insertions(+) create mode 100644 eventarc/publishing/apiv1/doc.go create mode 100644 eventarc/publishing/apiv1/gapic_metadata.json create mode 100644 eventarc/publishing/apiv1/publisher_client.go create mode 100644 eventarc/publishing/apiv1/publisher_client_example_test.go diff --git a/eventarc/publishing/apiv1/doc.go b/eventarc/publishing/apiv1/doc.go new file mode 100644 index 00000000000..5e89bccb4e9 --- /dev/null +++ b/eventarc/publishing/apiv1/doc.go @@ -0,0 +1,152 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +// Package publishing is an auto-generated package for the +// Eventarc Publishing API. +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// Example usage +// +// To get started with this package, create a client. +// ctx := context.Background() +// c, err := publishing.NewPublisherClient(ctx) +// if err != nil { +// // TODO: Handle error. +// } +// defer c.Close() +// +// The client will use your default application credentials. Clients should be reused instead of created as needed. +// The methods of Client are safe for concurrent use by multiple goroutines. +// The returned client must be Closed when it is done being used. +// +// Using the Client +// +// The following is an example of making an API call with the newly created client. +// +// ctx := context.Background() +// c, err := publishing.NewPublisherClient(ctx) +// if err != nil { +// // TODO: Handle error. +// } +// defer c.Close() +// +// req := &publisherpb.PublishChannelConnectionEventsRequest{ +// // TODO: Fill request struct fields. +// // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/eventarc/publishing/v1#PublishChannelConnectionEventsRequest. +// } +// resp, err := c.PublishChannelConnectionEvents(ctx, req) +// if err != nil { +// // TODO: Handle error. +// } +// // TODO: Use resp. +// _ = resp +// +// 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 https://pkg.go.dev/cloud.google.com/go. +package publishing // import "cloud.google.com/go/eventarc/publishing/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 = "20220112" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/eventarc/publishing/apiv1/gapic_metadata.json b/eventarc/publishing/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..48310187e75 --- /dev/null +++ b/eventarc/publishing/apiv1/gapic_metadata.json @@ -0,0 +1,23 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.eventarc.publishing.v1", + "libraryPackage": "cloud.google.com/go/eventarc/publishing/apiv1", + "services": { + "Publisher": { + "clients": { + "grpc": { + "libraryClient": "PublisherClient", + "rpcs": { + "PublishChannelConnectionEvents": { + "methods": [ + "PublishChannelConnectionEvents" + ] + } + } + } + } + } + } +} diff --git a/eventarc/publishing/apiv1/publisher_client.go b/eventarc/publishing/apiv1/publisher_client.go new file mode 100644 index 00000000000..d38dc8d42b6 --- /dev/null +++ b/eventarc/publishing/apiv1/publisher_client.go @@ -0,0 +1,252 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package publishing + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + 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" + publisherpb "google.golang.org/genproto/googleapis/cloud/eventarc/publishing/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newPublisherClientHook clientHook + +// PublisherCallOptions contains the retry settings for each method of PublisherClient. +type PublisherCallOptions struct { + PublishChannelConnectionEvents []gax.CallOption +} + +func defaultPublisherGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("eventarcpublishing.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("eventarcpublishing.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://eventarcpublishing.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultPublisherCallOptions() *PublisherCallOptions { + return &PublisherCallOptions{ + PublishChannelConnectionEvents: []gax.CallOption{}, + } +} + +// internalPublisherClient is an interface that defines the methods availaible from Eventarc Publishing API. +type internalPublisherClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + PublishChannelConnectionEvents(context.Context, *publisherpb.PublishChannelConnectionEventsRequest, ...gax.CallOption) (*publisherpb.PublishChannelConnectionEventsResponse, error) +} + +// PublisherClient is a client for interacting with Eventarc Publishing API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Eventarc processes events generated by an event provider and delivers them to +// a subscriber. +// +// An event provider is a software-as-a-service (SaaS) system or +// product that can generate and deliver events through Eventarc. +// +// A third-party event provider is an event provider from outside of Google. +// +// A partner is a third-party event provider that is integrated with Eventarc. +// +// A subscriber is a GCP customer interested in receiving events. +// +// Channel is a first-class Eventarc resource that is created and managed +// by the subscriber in their GCP project. A Channel represents a subscriber’s +// intent to receive events from an event provider. A Channel is associated with +// exactly one event provider. +// +// ChannelConnection is a first-class Eventarc resource that +// is created and managed by the partner in their GCP project. A +// ChannelConnection represents a connection between a partner and a +// subscriber’s Channel. A ChannelConnection has a one-to-one mapping with a +// Channel. +// +// Publisher allows an event provider to publish events to Eventarc. +type PublisherClient struct { + // The internal transport-dependent client. + internalClient internalPublisherClient + + // The call options for this service. + CallOptions *PublisherCallOptions +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *PublisherClient) Close() error { + return c.internalClient.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *PublisherClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *PublisherClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// PublishChannelConnectionEvents publish events to a ChannelConnection in a partner’s project. +func (c *PublisherClient) PublishChannelConnectionEvents(ctx context.Context, req *publisherpb.PublishChannelConnectionEventsRequest, opts ...gax.CallOption) (*publisherpb.PublishChannelConnectionEventsResponse, error) { + return c.internalClient.PublishChannelConnectionEvents(ctx, req, opts...) +} + +// publisherGRPCClient is a client for interacting with Eventarc Publishing API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type publisherGRPCClient 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 + + // Points back to the CallOptions field of the containing PublisherClient + CallOptions **PublisherCallOptions + + // The gRPC API client. + publisherClient publisherpb.PublisherClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewPublisherClient creates a new publisher client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Eventarc processes events generated by an event provider and delivers them to +// a subscriber. +// +// An event provider is a software-as-a-service (SaaS) system or +// product that can generate and deliver events through Eventarc. +// +// A third-party event provider is an event provider from outside of Google. +// +// A partner is a third-party event provider that is integrated with Eventarc. +// +// A subscriber is a GCP customer interested in receiving events. +// +// Channel is a first-class Eventarc resource that is created and managed +// by the subscriber in their GCP project. A Channel represents a subscriber’s +// intent to receive events from an event provider. A Channel is associated with +// exactly one event provider. +// +// ChannelConnection is a first-class Eventarc resource that +// is created and managed by the partner in their GCP project. A +// ChannelConnection represents a connection between a partner and a +// subscriber’s Channel. A ChannelConnection has a one-to-one mapping with a +// Channel. +// +// Publisher allows an event provider to publish events to Eventarc. +func NewPublisherClient(ctx context.Context, opts ...option.ClientOption) (*PublisherClient, error) { + clientOpts := defaultPublisherGRPCClientOptions() + if newPublisherClientHook != nil { + hookOpts, err := newPublisherClientHook(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 + } + client := PublisherClient{CallOptions: defaultPublisherCallOptions()} + + c := &publisherGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + publisherClient: publisherpb.NewPublisherClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *publisherGRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *publisherGRPCClient) 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...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *publisherGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *publisherGRPCClient) PublishChannelConnectionEvents(ctx context.Context, req *publisherpb.PublishChannelConnectionEventsRequest, opts ...gax.CallOption) (*publisherpb.PublishChannelConnectionEventsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "channel_connection", url.QueryEscape(req.GetChannelConnection()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).PublishChannelConnectionEvents[0:len((*c.CallOptions).PublishChannelConnectionEvents):len((*c.CallOptions).PublishChannelConnectionEvents)], opts...) + var resp *publisherpb.PublishChannelConnectionEventsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.publisherClient.PublishChannelConnectionEvents(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/eventarc/publishing/apiv1/publisher_client_example_test.go b/eventarc/publishing/apiv1/publisher_client_example_test.go new file mode 100644 index 00000000000..5abc3dd2c1f --- /dev/null +++ b/eventarc/publishing/apiv1/publisher_client_example_test.go @@ -0,0 +1,56 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package publishing_test + +import ( + "context" + + publishing "cloud.google.com/go/eventarc/publishing/apiv1" + publisherpb "google.golang.org/genproto/googleapis/cloud/eventarc/publishing/v1" +) + +func ExampleNewPublisherClient() { + ctx := context.Background() + c, err := publishing.NewPublisherClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExamplePublisherClient_PublishChannelConnectionEvents() { + ctx := context.Background() + c, err := publishing.NewPublisherClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &publisherpb.PublishChannelConnectionEventsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/eventarc/publishing/v1#PublishChannelConnectionEventsRequest. + } + resp, err := c.PublishChannelConnectionEvents(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 8cb72408514..42b5ea76f86 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -575,6 +575,15 @@ "release_level": "ga", "library_type": "" }, + "cloud.google.com/go/eventarc/publishing/apiv1": { + "distribution_name": "cloud.google.com/go/eventarc/publishing/apiv1", + "description": "Eventarc Publishing API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/eventarc/latest/publishing/apiv1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/filestore/apiv1": { "distribution_name": "cloud.google.com/go/filestore/apiv1", "description": "Cloud Filestore API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 7d365712032..d250d5dd826 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -1335,6 +1335,15 @@ var microgenGapicConfigs = []*microgenConfig{ // GA after 2021/12/15 releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/eventarc/publishing/v1", + pkg: "publishing", + importPath: "cloud.google.com/go/eventarc/publishing/apiv1", + gRPCServiceConfigPath: "eventarcpublishing_grpc_service_config.json", + apiServiceConfigPath: "eventarcpublishing_v1.yaml", + // GA after 2022/02/13 + releaseLevel: "beta", + }, // Non-Cloud APIs {