...

Source file src/cloud.google.com/go/pubsub/apiv1/schema_client.go

Documentation: cloud.google.com/go/pubsub/apiv1

     1  // Copyright 2024 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package pubsub
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"io"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  	"time"
    28  
    29  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    30  	pubsubpb "cloud.google.com/go/pubsub/apiv1/pubsubpb"
    31  	gax "github.com/googleapis/gax-go/v2"
    32  	"google.golang.org/api/googleapi"
    33  	"google.golang.org/api/iterator"
    34  	"google.golang.org/api/option"
    35  	"google.golang.org/api/option/internaloption"
    36  	gtransport "google.golang.org/api/transport/grpc"
    37  	httptransport "google.golang.org/api/transport/http"
    38  	"google.golang.org/grpc"
    39  	"google.golang.org/grpc/codes"
    40  	"google.golang.org/protobuf/encoding/protojson"
    41  	"google.golang.org/protobuf/proto"
    42  )
    43  
    44  var newSchemaClientHook clientHook
    45  
    46  // SchemaCallOptions contains the retry settings for each method of SchemaClient.
    47  type SchemaCallOptions struct {
    48  	CreateSchema         []gax.CallOption
    49  	GetSchema            []gax.CallOption
    50  	ListSchemas          []gax.CallOption
    51  	ListSchemaRevisions  []gax.CallOption
    52  	CommitSchema         []gax.CallOption
    53  	RollbackSchema       []gax.CallOption
    54  	DeleteSchemaRevision []gax.CallOption
    55  	DeleteSchema         []gax.CallOption
    56  	ValidateSchema       []gax.CallOption
    57  	ValidateMessage      []gax.CallOption
    58  	GetIamPolicy         []gax.CallOption
    59  	SetIamPolicy         []gax.CallOption
    60  	TestIamPermissions   []gax.CallOption
    61  }
    62  
    63  func defaultSchemaGRPCClientOptions() []option.ClientOption {
    64  	return []option.ClientOption{
    65  		internaloption.WithDefaultEndpoint("pubsub.googleapis.com:443"),
    66  		internaloption.WithDefaultEndpointTemplate("pubsub.UNIVERSE_DOMAIN:443"),
    67  		internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"),
    68  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    69  		internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
    70  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    71  		internaloption.EnableJwtWithScope(),
    72  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    73  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    74  	}
    75  }
    76  
    77  func defaultSchemaCallOptions() *SchemaCallOptions {
    78  	return &SchemaCallOptions{
    79  		CreateSchema: []gax.CallOption{
    80  			gax.WithTimeout(60000 * time.Millisecond),
    81  			gax.WithRetry(func() gax.Retryer {
    82  				return gax.OnCodes([]codes.Code{
    83  					codes.Unavailable,
    84  				}, gax.Backoff{
    85  					Initial:    100 * time.Millisecond,
    86  					Max:        60000 * time.Millisecond,
    87  					Multiplier: 1.30,
    88  				})
    89  			}),
    90  		},
    91  		GetSchema: []gax.CallOption{
    92  			gax.WithTimeout(60000 * time.Millisecond),
    93  			gax.WithRetry(func() gax.Retryer {
    94  				return gax.OnCodes([]codes.Code{
    95  					codes.Unavailable,
    96  				}, gax.Backoff{
    97  					Initial:    100 * time.Millisecond,
    98  					Max:        60000 * time.Millisecond,
    99  					Multiplier: 1.30,
   100  				})
   101  			}),
   102  		},
   103  		ListSchemas: []gax.CallOption{
   104  			gax.WithTimeout(60000 * time.Millisecond),
   105  			gax.WithRetry(func() gax.Retryer {
   106  				return gax.OnCodes([]codes.Code{
   107  					codes.Unavailable,
   108  				}, gax.Backoff{
   109  					Initial:    100 * time.Millisecond,
   110  					Max:        60000 * time.Millisecond,
   111  					Multiplier: 1.30,
   112  				})
   113  			}),
   114  		},
   115  		ListSchemaRevisions: []gax.CallOption{
   116  			gax.WithTimeout(60000 * time.Millisecond),
   117  			gax.WithRetry(func() gax.Retryer {
   118  				return gax.OnCodes([]codes.Code{
   119  					codes.Unavailable,
   120  				}, gax.Backoff{
   121  					Initial:    100 * time.Millisecond,
   122  					Max:        60000 * time.Millisecond,
   123  					Multiplier: 1.30,
   124  				})
   125  			}),
   126  		},
   127  		CommitSchema: []gax.CallOption{
   128  			gax.WithTimeout(60000 * time.Millisecond),
   129  			gax.WithRetry(func() gax.Retryer {
   130  				return gax.OnCodes([]codes.Code{
   131  					codes.Unavailable,
   132  				}, gax.Backoff{
   133  					Initial:    100 * time.Millisecond,
   134  					Max:        60000 * time.Millisecond,
   135  					Multiplier: 1.30,
   136  				})
   137  			}),
   138  		},
   139  		RollbackSchema: []gax.CallOption{
   140  			gax.WithTimeout(60000 * time.Millisecond),
   141  			gax.WithRetry(func() gax.Retryer {
   142  				return gax.OnCodes([]codes.Code{
   143  					codes.Unavailable,
   144  				}, gax.Backoff{
   145  					Initial:    100 * time.Millisecond,
   146  					Max:        60000 * time.Millisecond,
   147  					Multiplier: 1.30,
   148  				})
   149  			}),
   150  		},
   151  		DeleteSchemaRevision: []gax.CallOption{
   152  			gax.WithTimeout(60000 * time.Millisecond),
   153  			gax.WithRetry(func() gax.Retryer {
   154  				return gax.OnCodes([]codes.Code{
   155  					codes.Unavailable,
   156  				}, gax.Backoff{
   157  					Initial:    100 * time.Millisecond,
   158  					Max:        60000 * time.Millisecond,
   159  					Multiplier: 1.30,
   160  				})
   161  			}),
   162  		},
   163  		DeleteSchema: []gax.CallOption{
   164  			gax.WithTimeout(60000 * time.Millisecond),
   165  			gax.WithRetry(func() gax.Retryer {
   166  				return gax.OnCodes([]codes.Code{
   167  					codes.Unavailable,
   168  				}, gax.Backoff{
   169  					Initial:    100 * time.Millisecond,
   170  					Max:        60000 * time.Millisecond,
   171  					Multiplier: 1.30,
   172  				})
   173  			}),
   174  		},
   175  		ValidateSchema: []gax.CallOption{
   176  			gax.WithTimeout(60000 * time.Millisecond),
   177  			gax.WithRetry(func() gax.Retryer {
   178  				return gax.OnCodes([]codes.Code{
   179  					codes.Unavailable,
   180  				}, gax.Backoff{
   181  					Initial:    100 * time.Millisecond,
   182  					Max:        60000 * time.Millisecond,
   183  					Multiplier: 1.30,
   184  				})
   185  			}),
   186  		},
   187  		ValidateMessage: []gax.CallOption{
   188  			gax.WithTimeout(60000 * time.Millisecond),
   189  			gax.WithRetry(func() gax.Retryer {
   190  				return gax.OnCodes([]codes.Code{
   191  					codes.Unavailable,
   192  				}, gax.Backoff{
   193  					Initial:    100 * time.Millisecond,
   194  					Max:        60000 * time.Millisecond,
   195  					Multiplier: 1.30,
   196  				})
   197  			}),
   198  		},
   199  		GetIamPolicy:       []gax.CallOption{},
   200  		SetIamPolicy:       []gax.CallOption{},
   201  		TestIamPermissions: []gax.CallOption{},
   202  	}
   203  }
   204  
   205  func defaultSchemaRESTCallOptions() *SchemaCallOptions {
   206  	return &SchemaCallOptions{
   207  		CreateSchema: []gax.CallOption{
   208  			gax.WithTimeout(60000 * time.Millisecond),
   209  			gax.WithRetry(func() gax.Retryer {
   210  				return gax.OnHTTPCodes(gax.Backoff{
   211  					Initial:    100 * time.Millisecond,
   212  					Max:        60000 * time.Millisecond,
   213  					Multiplier: 1.30,
   214  				},
   215  					http.StatusServiceUnavailable)
   216  			}),
   217  		},
   218  		GetSchema: []gax.CallOption{
   219  			gax.WithTimeout(60000 * time.Millisecond),
   220  			gax.WithRetry(func() gax.Retryer {
   221  				return gax.OnHTTPCodes(gax.Backoff{
   222  					Initial:    100 * time.Millisecond,
   223  					Max:        60000 * time.Millisecond,
   224  					Multiplier: 1.30,
   225  				},
   226  					http.StatusServiceUnavailable)
   227  			}),
   228  		},
   229  		ListSchemas: []gax.CallOption{
   230  			gax.WithTimeout(60000 * time.Millisecond),
   231  			gax.WithRetry(func() gax.Retryer {
   232  				return gax.OnHTTPCodes(gax.Backoff{
   233  					Initial:    100 * time.Millisecond,
   234  					Max:        60000 * time.Millisecond,
   235  					Multiplier: 1.30,
   236  				},
   237  					http.StatusServiceUnavailable)
   238  			}),
   239  		},
   240  		ListSchemaRevisions: []gax.CallOption{
   241  			gax.WithTimeout(60000 * time.Millisecond),
   242  			gax.WithRetry(func() gax.Retryer {
   243  				return gax.OnHTTPCodes(gax.Backoff{
   244  					Initial:    100 * time.Millisecond,
   245  					Max:        60000 * time.Millisecond,
   246  					Multiplier: 1.30,
   247  				},
   248  					http.StatusServiceUnavailable)
   249  			}),
   250  		},
   251  		CommitSchema: []gax.CallOption{
   252  			gax.WithTimeout(60000 * time.Millisecond),
   253  			gax.WithRetry(func() gax.Retryer {
   254  				return gax.OnHTTPCodes(gax.Backoff{
   255  					Initial:    100 * time.Millisecond,
   256  					Max:        60000 * time.Millisecond,
   257  					Multiplier: 1.30,
   258  				},
   259  					http.StatusServiceUnavailable)
   260  			}),
   261  		},
   262  		RollbackSchema: []gax.CallOption{
   263  			gax.WithTimeout(60000 * time.Millisecond),
   264  			gax.WithRetry(func() gax.Retryer {
   265  				return gax.OnHTTPCodes(gax.Backoff{
   266  					Initial:    100 * time.Millisecond,
   267  					Max:        60000 * time.Millisecond,
   268  					Multiplier: 1.30,
   269  				},
   270  					http.StatusServiceUnavailable)
   271  			}),
   272  		},
   273  		DeleteSchemaRevision: []gax.CallOption{
   274  			gax.WithTimeout(60000 * time.Millisecond),
   275  			gax.WithRetry(func() gax.Retryer {
   276  				return gax.OnHTTPCodes(gax.Backoff{
   277  					Initial:    100 * time.Millisecond,
   278  					Max:        60000 * time.Millisecond,
   279  					Multiplier: 1.30,
   280  				},
   281  					http.StatusServiceUnavailable)
   282  			}),
   283  		},
   284  		DeleteSchema: []gax.CallOption{
   285  			gax.WithTimeout(60000 * time.Millisecond),
   286  			gax.WithRetry(func() gax.Retryer {
   287  				return gax.OnHTTPCodes(gax.Backoff{
   288  					Initial:    100 * time.Millisecond,
   289  					Max:        60000 * time.Millisecond,
   290  					Multiplier: 1.30,
   291  				},
   292  					http.StatusServiceUnavailable)
   293  			}),
   294  		},
   295  		ValidateSchema: []gax.CallOption{
   296  			gax.WithTimeout(60000 * time.Millisecond),
   297  			gax.WithRetry(func() gax.Retryer {
   298  				return gax.OnHTTPCodes(gax.Backoff{
   299  					Initial:    100 * time.Millisecond,
   300  					Max:        60000 * time.Millisecond,
   301  					Multiplier: 1.30,
   302  				},
   303  					http.StatusServiceUnavailable)
   304  			}),
   305  		},
   306  		ValidateMessage: []gax.CallOption{
   307  			gax.WithTimeout(60000 * time.Millisecond),
   308  			gax.WithRetry(func() gax.Retryer {
   309  				return gax.OnHTTPCodes(gax.Backoff{
   310  					Initial:    100 * time.Millisecond,
   311  					Max:        60000 * time.Millisecond,
   312  					Multiplier: 1.30,
   313  				},
   314  					http.StatusServiceUnavailable)
   315  			}),
   316  		},
   317  		GetIamPolicy:       []gax.CallOption{},
   318  		SetIamPolicy:       []gax.CallOption{},
   319  		TestIamPermissions: []gax.CallOption{},
   320  	}
   321  }
   322  
   323  // internalSchemaClient is an interface that defines the methods available from Cloud Pub/Sub API.
   324  type internalSchemaClient interface {
   325  	Close() error
   326  	setGoogleClientInfo(...string)
   327  	Connection() *grpc.ClientConn
   328  	CreateSchema(context.Context, *pubsubpb.CreateSchemaRequest, ...gax.CallOption) (*pubsubpb.Schema, error)
   329  	GetSchema(context.Context, *pubsubpb.GetSchemaRequest, ...gax.CallOption) (*pubsubpb.Schema, error)
   330  	ListSchemas(context.Context, *pubsubpb.ListSchemasRequest, ...gax.CallOption) *SchemaIterator
   331  	ListSchemaRevisions(context.Context, *pubsubpb.ListSchemaRevisionsRequest, ...gax.CallOption) *SchemaIterator
   332  	CommitSchema(context.Context, *pubsubpb.CommitSchemaRequest, ...gax.CallOption) (*pubsubpb.Schema, error)
   333  	RollbackSchema(context.Context, *pubsubpb.RollbackSchemaRequest, ...gax.CallOption) (*pubsubpb.Schema, error)
   334  	DeleteSchemaRevision(context.Context, *pubsubpb.DeleteSchemaRevisionRequest, ...gax.CallOption) (*pubsubpb.Schema, error)
   335  	DeleteSchema(context.Context, *pubsubpb.DeleteSchemaRequest, ...gax.CallOption) error
   336  	ValidateSchema(context.Context, *pubsubpb.ValidateSchemaRequest, ...gax.CallOption) (*pubsubpb.ValidateSchemaResponse, error)
   337  	ValidateMessage(context.Context, *pubsubpb.ValidateMessageRequest, ...gax.CallOption) (*pubsubpb.ValidateMessageResponse, error)
   338  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   339  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   340  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   341  }
   342  
   343  // SchemaClient is a client for interacting with Cloud Pub/Sub API.
   344  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   345  //
   346  // Service for doing schema-related operations.
   347  type SchemaClient struct {
   348  	// The internal transport-dependent client.
   349  	internalClient internalSchemaClient
   350  
   351  	// The call options for this service.
   352  	CallOptions *SchemaCallOptions
   353  }
   354  
   355  // Wrapper methods routed to the internal client.
   356  
   357  // Close closes the connection to the API service. The user should invoke this when
   358  // the client is no longer required.
   359  func (c *SchemaClient) Close() error {
   360  	return c.internalClient.Close()
   361  }
   362  
   363  // setGoogleClientInfo sets the name and version of the application in
   364  // the `x-goog-api-client` header passed on each request. Intended for
   365  // use by Google-written clients.
   366  func (c *SchemaClient) setGoogleClientInfo(keyval ...string) {
   367  	c.internalClient.setGoogleClientInfo(keyval...)
   368  }
   369  
   370  // Connection returns a connection to the API service.
   371  //
   372  // Deprecated: Connections are now pooled so this method does not always
   373  // return the same resource.
   374  func (c *SchemaClient) Connection() *grpc.ClientConn {
   375  	return c.internalClient.Connection()
   376  }
   377  
   378  // CreateSchema creates a schema.
   379  func (c *SchemaClient) CreateSchema(ctx context.Context, req *pubsubpb.CreateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   380  	return c.internalClient.CreateSchema(ctx, req, opts...)
   381  }
   382  
   383  // GetSchema gets a schema.
   384  func (c *SchemaClient) GetSchema(ctx context.Context, req *pubsubpb.GetSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   385  	return c.internalClient.GetSchema(ctx, req, opts...)
   386  }
   387  
   388  // ListSchemas lists schemas in a project.
   389  func (c *SchemaClient) ListSchemas(ctx context.Context, req *pubsubpb.ListSchemasRequest, opts ...gax.CallOption) *SchemaIterator {
   390  	return c.internalClient.ListSchemas(ctx, req, opts...)
   391  }
   392  
   393  // ListSchemaRevisions lists all schema revisions for the named schema.
   394  func (c *SchemaClient) ListSchemaRevisions(ctx context.Context, req *pubsubpb.ListSchemaRevisionsRequest, opts ...gax.CallOption) *SchemaIterator {
   395  	return c.internalClient.ListSchemaRevisions(ctx, req, opts...)
   396  }
   397  
   398  // CommitSchema commits a new schema revision to an existing schema.
   399  func (c *SchemaClient) CommitSchema(ctx context.Context, req *pubsubpb.CommitSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   400  	return c.internalClient.CommitSchema(ctx, req, opts...)
   401  }
   402  
   403  // RollbackSchema creates a new schema revision that is a copy of the provided revision_id.
   404  func (c *SchemaClient) RollbackSchema(ctx context.Context, req *pubsubpb.RollbackSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   405  	return c.internalClient.RollbackSchema(ctx, req, opts...)
   406  }
   407  
   408  // DeleteSchemaRevision deletes a specific schema revision.
   409  func (c *SchemaClient) DeleteSchemaRevision(ctx context.Context, req *pubsubpb.DeleteSchemaRevisionRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   410  	return c.internalClient.DeleteSchemaRevision(ctx, req, opts...)
   411  }
   412  
   413  // DeleteSchema deletes a schema.
   414  func (c *SchemaClient) DeleteSchema(ctx context.Context, req *pubsubpb.DeleteSchemaRequest, opts ...gax.CallOption) error {
   415  	return c.internalClient.DeleteSchema(ctx, req, opts...)
   416  }
   417  
   418  // ValidateSchema validates a schema.
   419  func (c *SchemaClient) ValidateSchema(ctx context.Context, req *pubsubpb.ValidateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.ValidateSchemaResponse, error) {
   420  	return c.internalClient.ValidateSchema(ctx, req, opts...)
   421  }
   422  
   423  // ValidateMessage validates a message against a schema.
   424  func (c *SchemaClient) ValidateMessage(ctx context.Context, req *pubsubpb.ValidateMessageRequest, opts ...gax.CallOption) (*pubsubpb.ValidateMessageResponse, error) {
   425  	return c.internalClient.ValidateMessage(ctx, req, opts...)
   426  }
   427  
   428  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   429  // if the resource exists and does not have a policy set.
   430  func (c *SchemaClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   431  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   432  }
   433  
   434  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   435  // any existing policy.
   436  //
   437  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   438  // errors.
   439  func (c *SchemaClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   440  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   441  }
   442  
   443  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   444  // resource does not exist, this will return an empty set of
   445  // permissions, not a NOT_FOUND error.
   446  //
   447  // Note: This operation is designed to be used for building
   448  // permission-aware UIs and command-line tools, not for authorization
   449  // checking. This operation may “fail open” without warning.
   450  func (c *SchemaClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   451  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   452  }
   453  
   454  // schemaGRPCClient is a client for interacting with Cloud Pub/Sub API over gRPC transport.
   455  //
   456  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   457  type schemaGRPCClient struct {
   458  	// Connection pool of gRPC connections to the service.
   459  	connPool gtransport.ConnPool
   460  
   461  	// Points back to the CallOptions field of the containing SchemaClient
   462  	CallOptions **SchemaCallOptions
   463  
   464  	// The gRPC API client.
   465  	schemaClient pubsubpb.SchemaServiceClient
   466  
   467  	iamPolicyClient iampb.IAMPolicyClient
   468  
   469  	// The x-goog-* metadata to be sent with each request.
   470  	xGoogHeaders []string
   471  }
   472  
   473  // NewSchemaClient creates a new schema service client based on gRPC.
   474  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   475  //
   476  // Service for doing schema-related operations.
   477  func NewSchemaClient(ctx context.Context, opts ...option.ClientOption) (*SchemaClient, error) {
   478  	clientOpts := defaultSchemaGRPCClientOptions()
   479  	if newSchemaClientHook != nil {
   480  		hookOpts, err := newSchemaClientHook(ctx, clientHookParams{})
   481  		if err != nil {
   482  			return nil, err
   483  		}
   484  		clientOpts = append(clientOpts, hookOpts...)
   485  	}
   486  
   487  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   488  	if err != nil {
   489  		return nil, err
   490  	}
   491  	client := SchemaClient{CallOptions: defaultSchemaCallOptions()}
   492  
   493  	c := &schemaGRPCClient{
   494  		connPool:        connPool,
   495  		schemaClient:    pubsubpb.NewSchemaServiceClient(connPool),
   496  		CallOptions:     &client.CallOptions,
   497  		iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
   498  	}
   499  	c.setGoogleClientInfo()
   500  
   501  	client.internalClient = c
   502  
   503  	return &client, nil
   504  }
   505  
   506  // Connection returns a connection to the API service.
   507  //
   508  // Deprecated: Connections are now pooled so this method does not always
   509  // return the same resource.
   510  func (c *schemaGRPCClient) Connection() *grpc.ClientConn {
   511  	return c.connPool.Conn()
   512  }
   513  
   514  // setGoogleClientInfo sets the name and version of the application in
   515  // the `x-goog-api-client` header passed on each request. Intended for
   516  // use by Google-written clients.
   517  func (c *schemaGRPCClient) setGoogleClientInfo(keyval ...string) {
   518  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   519  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   520  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   521  }
   522  
   523  // Close closes the connection to the API service. The user should invoke this when
   524  // the client is no longer required.
   525  func (c *schemaGRPCClient) Close() error {
   526  	return c.connPool.Close()
   527  }
   528  
   529  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   530  type schemaRESTClient struct {
   531  	// The http endpoint to connect to.
   532  	endpoint string
   533  
   534  	// The http client.
   535  	httpClient *http.Client
   536  
   537  	// The x-goog-* headers to be sent with each request.
   538  	xGoogHeaders []string
   539  
   540  	// Points back to the CallOptions field of the containing SchemaClient
   541  	CallOptions **SchemaCallOptions
   542  }
   543  
   544  // NewSchemaRESTClient creates a new schema service rest client.
   545  //
   546  // Service for doing schema-related operations.
   547  func NewSchemaRESTClient(ctx context.Context, opts ...option.ClientOption) (*SchemaClient, error) {
   548  	clientOpts := append(defaultSchemaRESTClientOptions(), opts...)
   549  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   550  	if err != nil {
   551  		return nil, err
   552  	}
   553  
   554  	callOpts := defaultSchemaRESTCallOptions()
   555  	c := &schemaRESTClient{
   556  		endpoint:    endpoint,
   557  		httpClient:  httpClient,
   558  		CallOptions: &callOpts,
   559  	}
   560  	c.setGoogleClientInfo()
   561  
   562  	return &SchemaClient{internalClient: c, CallOptions: callOpts}, nil
   563  }
   564  
   565  func defaultSchemaRESTClientOptions() []option.ClientOption {
   566  	return []option.ClientOption{
   567  		internaloption.WithDefaultEndpoint("https://pubsub.googleapis.com"),
   568  		internaloption.WithDefaultEndpointTemplate("https://pubsub.UNIVERSE_DOMAIN"),
   569  		internaloption.WithDefaultMTLSEndpoint("https://pubsub.mtls.googleapis.com"),
   570  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   571  		internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"),
   572  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   573  	}
   574  }
   575  
   576  // setGoogleClientInfo sets the name and version of the application in
   577  // the `x-goog-api-client` header passed on each request. Intended for
   578  // use by Google-written clients.
   579  func (c *schemaRESTClient) setGoogleClientInfo(keyval ...string) {
   580  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   581  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
   582  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   583  }
   584  
   585  // Close closes the connection to the API service. The user should invoke this when
   586  // the client is no longer required.
   587  func (c *schemaRESTClient) Close() error {
   588  	// Replace httpClient with nil to force cleanup.
   589  	c.httpClient = nil
   590  	return nil
   591  }
   592  
   593  // Connection returns a connection to the API service.
   594  //
   595  // Deprecated: This method always returns nil.
   596  func (c *schemaRESTClient) Connection() *grpc.ClientConn {
   597  	return nil
   598  }
   599  func (c *schemaGRPCClient) CreateSchema(ctx context.Context, req *pubsubpb.CreateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   600  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   601  
   602  	hds = append(c.xGoogHeaders, hds...)
   603  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   604  	opts = append((*c.CallOptions).CreateSchema[0:len((*c.CallOptions).CreateSchema):len((*c.CallOptions).CreateSchema)], opts...)
   605  	var resp *pubsubpb.Schema
   606  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   607  		var err error
   608  		resp, err = c.schemaClient.CreateSchema(ctx, req, settings.GRPC...)
   609  		return err
   610  	}, opts...)
   611  	if err != nil {
   612  		return nil, err
   613  	}
   614  	return resp, nil
   615  }
   616  
   617  func (c *schemaGRPCClient) GetSchema(ctx context.Context, req *pubsubpb.GetSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   618  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   619  
   620  	hds = append(c.xGoogHeaders, hds...)
   621  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   622  	opts = append((*c.CallOptions).GetSchema[0:len((*c.CallOptions).GetSchema):len((*c.CallOptions).GetSchema)], opts...)
   623  	var resp *pubsubpb.Schema
   624  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   625  		var err error
   626  		resp, err = c.schemaClient.GetSchema(ctx, req, settings.GRPC...)
   627  		return err
   628  	}, opts...)
   629  	if err != nil {
   630  		return nil, err
   631  	}
   632  	return resp, nil
   633  }
   634  
   635  func (c *schemaGRPCClient) ListSchemas(ctx context.Context, req *pubsubpb.ListSchemasRequest, opts ...gax.CallOption) *SchemaIterator {
   636  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   637  
   638  	hds = append(c.xGoogHeaders, hds...)
   639  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   640  	opts = append((*c.CallOptions).ListSchemas[0:len((*c.CallOptions).ListSchemas):len((*c.CallOptions).ListSchemas)], opts...)
   641  	it := &SchemaIterator{}
   642  	req = proto.Clone(req).(*pubsubpb.ListSchemasRequest)
   643  	it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Schema, string, error) {
   644  		resp := &pubsubpb.ListSchemasResponse{}
   645  		if pageToken != "" {
   646  			req.PageToken = pageToken
   647  		}
   648  		if pageSize > math.MaxInt32 {
   649  			req.PageSize = math.MaxInt32
   650  		} else if pageSize != 0 {
   651  			req.PageSize = int32(pageSize)
   652  		}
   653  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   654  			var err error
   655  			resp, err = c.schemaClient.ListSchemas(ctx, req, settings.GRPC...)
   656  			return err
   657  		}, opts...)
   658  		if err != nil {
   659  			return nil, "", err
   660  		}
   661  
   662  		it.Response = resp
   663  		return resp.GetSchemas(), resp.GetNextPageToken(), nil
   664  	}
   665  	fetch := func(pageSize int, pageToken string) (string, error) {
   666  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   667  		if err != nil {
   668  			return "", err
   669  		}
   670  		it.items = append(it.items, items...)
   671  		return nextPageToken, nil
   672  	}
   673  
   674  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   675  	it.pageInfo.MaxSize = int(req.GetPageSize())
   676  	it.pageInfo.Token = req.GetPageToken()
   677  
   678  	return it
   679  }
   680  
   681  func (c *schemaGRPCClient) ListSchemaRevisions(ctx context.Context, req *pubsubpb.ListSchemaRevisionsRequest, opts ...gax.CallOption) *SchemaIterator {
   682  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   683  
   684  	hds = append(c.xGoogHeaders, hds...)
   685  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   686  	opts = append((*c.CallOptions).ListSchemaRevisions[0:len((*c.CallOptions).ListSchemaRevisions):len((*c.CallOptions).ListSchemaRevisions)], opts...)
   687  	it := &SchemaIterator{}
   688  	req = proto.Clone(req).(*pubsubpb.ListSchemaRevisionsRequest)
   689  	it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Schema, string, error) {
   690  		resp := &pubsubpb.ListSchemaRevisionsResponse{}
   691  		if pageToken != "" {
   692  			req.PageToken = pageToken
   693  		}
   694  		if pageSize > math.MaxInt32 {
   695  			req.PageSize = math.MaxInt32
   696  		} else if pageSize != 0 {
   697  			req.PageSize = int32(pageSize)
   698  		}
   699  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   700  			var err error
   701  			resp, err = c.schemaClient.ListSchemaRevisions(ctx, req, settings.GRPC...)
   702  			return err
   703  		}, opts...)
   704  		if err != nil {
   705  			return nil, "", err
   706  		}
   707  
   708  		it.Response = resp
   709  		return resp.GetSchemas(), resp.GetNextPageToken(), nil
   710  	}
   711  	fetch := func(pageSize int, pageToken string) (string, error) {
   712  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   713  		if err != nil {
   714  			return "", err
   715  		}
   716  		it.items = append(it.items, items...)
   717  		return nextPageToken, nil
   718  	}
   719  
   720  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   721  	it.pageInfo.MaxSize = int(req.GetPageSize())
   722  	it.pageInfo.Token = req.GetPageToken()
   723  
   724  	return it
   725  }
   726  
   727  func (c *schemaGRPCClient) CommitSchema(ctx context.Context, req *pubsubpb.CommitSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   728  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   729  
   730  	hds = append(c.xGoogHeaders, hds...)
   731  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   732  	opts = append((*c.CallOptions).CommitSchema[0:len((*c.CallOptions).CommitSchema):len((*c.CallOptions).CommitSchema)], opts...)
   733  	var resp *pubsubpb.Schema
   734  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   735  		var err error
   736  		resp, err = c.schemaClient.CommitSchema(ctx, req, settings.GRPC...)
   737  		return err
   738  	}, opts...)
   739  	if err != nil {
   740  		return nil, err
   741  	}
   742  	return resp, nil
   743  }
   744  
   745  func (c *schemaGRPCClient) RollbackSchema(ctx context.Context, req *pubsubpb.RollbackSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   746  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   747  
   748  	hds = append(c.xGoogHeaders, hds...)
   749  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   750  	opts = append((*c.CallOptions).RollbackSchema[0:len((*c.CallOptions).RollbackSchema):len((*c.CallOptions).RollbackSchema)], opts...)
   751  	var resp *pubsubpb.Schema
   752  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   753  		var err error
   754  		resp, err = c.schemaClient.RollbackSchema(ctx, req, settings.GRPC...)
   755  		return err
   756  	}, opts...)
   757  	if err != nil {
   758  		return nil, err
   759  	}
   760  	return resp, nil
   761  }
   762  
   763  func (c *schemaGRPCClient) DeleteSchemaRevision(ctx context.Context, req *pubsubpb.DeleteSchemaRevisionRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   764  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   765  
   766  	hds = append(c.xGoogHeaders, hds...)
   767  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   768  	opts = append((*c.CallOptions).DeleteSchemaRevision[0:len((*c.CallOptions).DeleteSchemaRevision):len((*c.CallOptions).DeleteSchemaRevision)], opts...)
   769  	var resp *pubsubpb.Schema
   770  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   771  		var err error
   772  		resp, err = c.schemaClient.DeleteSchemaRevision(ctx, req, settings.GRPC...)
   773  		return err
   774  	}, opts...)
   775  	if err != nil {
   776  		return nil, err
   777  	}
   778  	return resp, nil
   779  }
   780  
   781  func (c *schemaGRPCClient) DeleteSchema(ctx context.Context, req *pubsubpb.DeleteSchemaRequest, opts ...gax.CallOption) error {
   782  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   783  
   784  	hds = append(c.xGoogHeaders, hds...)
   785  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   786  	opts = append((*c.CallOptions).DeleteSchema[0:len((*c.CallOptions).DeleteSchema):len((*c.CallOptions).DeleteSchema)], opts...)
   787  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   788  		var err error
   789  		_, err = c.schemaClient.DeleteSchema(ctx, req, settings.GRPC...)
   790  		return err
   791  	}, opts...)
   792  	return err
   793  }
   794  
   795  func (c *schemaGRPCClient) ValidateSchema(ctx context.Context, req *pubsubpb.ValidateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.ValidateSchemaResponse, error) {
   796  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   797  
   798  	hds = append(c.xGoogHeaders, hds...)
   799  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   800  	opts = append((*c.CallOptions).ValidateSchema[0:len((*c.CallOptions).ValidateSchema):len((*c.CallOptions).ValidateSchema)], opts...)
   801  	var resp *pubsubpb.ValidateSchemaResponse
   802  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   803  		var err error
   804  		resp, err = c.schemaClient.ValidateSchema(ctx, req, settings.GRPC...)
   805  		return err
   806  	}, opts...)
   807  	if err != nil {
   808  		return nil, err
   809  	}
   810  	return resp, nil
   811  }
   812  
   813  func (c *schemaGRPCClient) ValidateMessage(ctx context.Context, req *pubsubpb.ValidateMessageRequest, opts ...gax.CallOption) (*pubsubpb.ValidateMessageResponse, error) {
   814  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   815  
   816  	hds = append(c.xGoogHeaders, hds...)
   817  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   818  	opts = append((*c.CallOptions).ValidateMessage[0:len((*c.CallOptions).ValidateMessage):len((*c.CallOptions).ValidateMessage)], opts...)
   819  	var resp *pubsubpb.ValidateMessageResponse
   820  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   821  		var err error
   822  		resp, err = c.schemaClient.ValidateMessage(ctx, req, settings.GRPC...)
   823  		return err
   824  	}, opts...)
   825  	if err != nil {
   826  		return nil, err
   827  	}
   828  	return resp, nil
   829  }
   830  
   831  func (c *schemaGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   832  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   833  
   834  	hds = append(c.xGoogHeaders, hds...)
   835  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   836  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   837  	var resp *iampb.Policy
   838  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   839  		var err error
   840  		resp, err = c.iamPolicyClient.GetIamPolicy(ctx, req, settings.GRPC...)
   841  		return err
   842  	}, opts...)
   843  	if err != nil {
   844  		return nil, err
   845  	}
   846  	return resp, nil
   847  }
   848  
   849  func (c *schemaGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   850  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   851  
   852  	hds = append(c.xGoogHeaders, hds...)
   853  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   854  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   855  	var resp *iampb.Policy
   856  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   857  		var err error
   858  		resp, err = c.iamPolicyClient.SetIamPolicy(ctx, req, settings.GRPC...)
   859  		return err
   860  	}, opts...)
   861  	if err != nil {
   862  		return nil, err
   863  	}
   864  	return resp, nil
   865  }
   866  
   867  func (c *schemaGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   868  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   869  
   870  	hds = append(c.xGoogHeaders, hds...)
   871  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   872  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   873  	var resp *iampb.TestIamPermissionsResponse
   874  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   875  		var err error
   876  		resp, err = c.iamPolicyClient.TestIamPermissions(ctx, req, settings.GRPC...)
   877  		return err
   878  	}, opts...)
   879  	if err != nil {
   880  		return nil, err
   881  	}
   882  	return resp, nil
   883  }
   884  
   885  // CreateSchema creates a schema.
   886  func (c *schemaRESTClient) CreateSchema(ctx context.Context, req *pubsubpb.CreateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   887  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   888  	body := req.GetSchema()
   889  	jsonReq, err := m.Marshal(body)
   890  	if err != nil {
   891  		return nil, err
   892  	}
   893  
   894  	baseUrl, err := url.Parse(c.endpoint)
   895  	if err != nil {
   896  		return nil, err
   897  	}
   898  	baseUrl.Path += fmt.Sprintf("/v1/%v/schemas", req.GetParent())
   899  
   900  	params := url.Values{}
   901  	params.Add("$alt", "json;enum-encoding=int")
   902  	if req.GetSchemaId() != "" {
   903  		params.Add("schemaId", fmt.Sprintf("%v", req.GetSchemaId()))
   904  	}
   905  
   906  	baseUrl.RawQuery = params.Encode()
   907  
   908  	// Build HTTP headers from client and context metadata.
   909  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   910  
   911  	hds = append(c.xGoogHeaders, hds...)
   912  	hds = append(hds, "Content-Type", "application/json")
   913  	headers := gax.BuildHeaders(ctx, hds...)
   914  	opts = append((*c.CallOptions).CreateSchema[0:len((*c.CallOptions).CreateSchema):len((*c.CallOptions).CreateSchema)], opts...)
   915  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   916  	resp := &pubsubpb.Schema{}
   917  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   918  		if settings.Path != "" {
   919  			baseUrl.Path = settings.Path
   920  		}
   921  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   922  		if err != nil {
   923  			return err
   924  		}
   925  		httpReq = httpReq.WithContext(ctx)
   926  		httpReq.Header = headers
   927  
   928  		httpRsp, err := c.httpClient.Do(httpReq)
   929  		if err != nil {
   930  			return err
   931  		}
   932  		defer httpRsp.Body.Close()
   933  
   934  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   935  			return err
   936  		}
   937  
   938  		buf, err := io.ReadAll(httpRsp.Body)
   939  		if err != nil {
   940  			return err
   941  		}
   942  
   943  		if err := unm.Unmarshal(buf, resp); err != nil {
   944  			return err
   945  		}
   946  
   947  		return nil
   948  	}, opts...)
   949  	if e != nil {
   950  		return nil, e
   951  	}
   952  	return resp, nil
   953  }
   954  
   955  // GetSchema gets a schema.
   956  func (c *schemaRESTClient) GetSchema(ctx context.Context, req *pubsubpb.GetSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
   957  	baseUrl, err := url.Parse(c.endpoint)
   958  	if err != nil {
   959  		return nil, err
   960  	}
   961  	baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
   962  
   963  	params := url.Values{}
   964  	params.Add("$alt", "json;enum-encoding=int")
   965  	if req.GetView() != 0 {
   966  		params.Add("view", fmt.Sprintf("%v", req.GetView()))
   967  	}
   968  
   969  	baseUrl.RawQuery = params.Encode()
   970  
   971  	// Build HTTP headers from client and context metadata.
   972  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   973  
   974  	hds = append(c.xGoogHeaders, hds...)
   975  	hds = append(hds, "Content-Type", "application/json")
   976  	headers := gax.BuildHeaders(ctx, hds...)
   977  	opts = append((*c.CallOptions).GetSchema[0:len((*c.CallOptions).GetSchema):len((*c.CallOptions).GetSchema)], opts...)
   978  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   979  	resp := &pubsubpb.Schema{}
   980  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   981  		if settings.Path != "" {
   982  			baseUrl.Path = settings.Path
   983  		}
   984  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   985  		if err != nil {
   986  			return err
   987  		}
   988  		httpReq = httpReq.WithContext(ctx)
   989  		httpReq.Header = headers
   990  
   991  		httpRsp, err := c.httpClient.Do(httpReq)
   992  		if err != nil {
   993  			return err
   994  		}
   995  		defer httpRsp.Body.Close()
   996  
   997  		if err = googleapi.CheckResponse(httpRsp); err != nil {
   998  			return err
   999  		}
  1000  
  1001  		buf, err := io.ReadAll(httpRsp.Body)
  1002  		if err != nil {
  1003  			return err
  1004  		}
  1005  
  1006  		if err := unm.Unmarshal(buf, resp); err != nil {
  1007  			return err
  1008  		}
  1009  
  1010  		return nil
  1011  	}, opts...)
  1012  	if e != nil {
  1013  		return nil, e
  1014  	}
  1015  	return resp, nil
  1016  }
  1017  
  1018  // ListSchemas lists schemas in a project.
  1019  func (c *schemaRESTClient) ListSchemas(ctx context.Context, req *pubsubpb.ListSchemasRequest, opts ...gax.CallOption) *SchemaIterator {
  1020  	it := &SchemaIterator{}
  1021  	req = proto.Clone(req).(*pubsubpb.ListSchemasRequest)
  1022  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1023  	it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Schema, string, error) {
  1024  		resp := &pubsubpb.ListSchemasResponse{}
  1025  		if pageToken != "" {
  1026  			req.PageToken = pageToken
  1027  		}
  1028  		if pageSize > math.MaxInt32 {
  1029  			req.PageSize = math.MaxInt32
  1030  		} else if pageSize != 0 {
  1031  			req.PageSize = int32(pageSize)
  1032  		}
  1033  		baseUrl, err := url.Parse(c.endpoint)
  1034  		if err != nil {
  1035  			return nil, "", err
  1036  		}
  1037  		baseUrl.Path += fmt.Sprintf("/v1/%v/schemas", req.GetParent())
  1038  
  1039  		params := url.Values{}
  1040  		params.Add("$alt", "json;enum-encoding=int")
  1041  		if req.GetPageSize() != 0 {
  1042  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1043  		}
  1044  		if req.GetPageToken() != "" {
  1045  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1046  		}
  1047  		if req.GetView() != 0 {
  1048  			params.Add("view", fmt.Sprintf("%v", req.GetView()))
  1049  		}
  1050  
  1051  		baseUrl.RawQuery = params.Encode()
  1052  
  1053  		// Build HTTP headers from client and context metadata.
  1054  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1055  		headers := gax.BuildHeaders(ctx, hds...)
  1056  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1057  			if settings.Path != "" {
  1058  				baseUrl.Path = settings.Path
  1059  			}
  1060  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1061  			if err != nil {
  1062  				return err
  1063  			}
  1064  			httpReq.Header = headers
  1065  
  1066  			httpRsp, err := c.httpClient.Do(httpReq)
  1067  			if err != nil {
  1068  				return err
  1069  			}
  1070  			defer httpRsp.Body.Close()
  1071  
  1072  			if err = googleapi.CheckResponse(httpRsp); err != nil {
  1073  				return err
  1074  			}
  1075  
  1076  			buf, err := io.ReadAll(httpRsp.Body)
  1077  			if err != nil {
  1078  				return err
  1079  			}
  1080  
  1081  			if err := unm.Unmarshal(buf, resp); err != nil {
  1082  				return err
  1083  			}
  1084  
  1085  			return nil
  1086  		}, opts...)
  1087  		if e != nil {
  1088  			return nil, "", e
  1089  		}
  1090  		it.Response = resp
  1091  		return resp.GetSchemas(), resp.GetNextPageToken(), nil
  1092  	}
  1093  
  1094  	fetch := func(pageSize int, pageToken string) (string, error) {
  1095  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1096  		if err != nil {
  1097  			return "", err
  1098  		}
  1099  		it.items = append(it.items, items...)
  1100  		return nextPageToken, nil
  1101  	}
  1102  
  1103  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1104  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1105  	it.pageInfo.Token = req.GetPageToken()
  1106  
  1107  	return it
  1108  }
  1109  
  1110  // ListSchemaRevisions lists all schema revisions for the named schema.
  1111  func (c *schemaRESTClient) ListSchemaRevisions(ctx context.Context, req *pubsubpb.ListSchemaRevisionsRequest, opts ...gax.CallOption) *SchemaIterator {
  1112  	it := &SchemaIterator{}
  1113  	req = proto.Clone(req).(*pubsubpb.ListSchemaRevisionsRequest)
  1114  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1115  	it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Schema, string, error) {
  1116  		resp := &pubsubpb.ListSchemaRevisionsResponse{}
  1117  		if pageToken != "" {
  1118  			req.PageToken = pageToken
  1119  		}
  1120  		if pageSize > math.MaxInt32 {
  1121  			req.PageSize = math.MaxInt32
  1122  		} else if pageSize != 0 {
  1123  			req.PageSize = int32(pageSize)
  1124  		}
  1125  		baseUrl, err := url.Parse(c.endpoint)
  1126  		if err != nil {
  1127  			return nil, "", err
  1128  		}
  1129  		baseUrl.Path += fmt.Sprintf("/v1/%v:listRevisions", req.GetName())
  1130  
  1131  		params := url.Values{}
  1132  		params.Add("$alt", "json;enum-encoding=int")
  1133  		if req.GetPageSize() != 0 {
  1134  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1135  		}
  1136  		if req.GetPageToken() != "" {
  1137  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1138  		}
  1139  		if req.GetView() != 0 {
  1140  			params.Add("view", fmt.Sprintf("%v", req.GetView()))
  1141  		}
  1142  
  1143  		baseUrl.RawQuery = params.Encode()
  1144  
  1145  		// Build HTTP headers from client and context metadata.
  1146  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1147  		headers := gax.BuildHeaders(ctx, hds...)
  1148  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1149  			if settings.Path != "" {
  1150  				baseUrl.Path = settings.Path
  1151  			}
  1152  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1153  			if err != nil {
  1154  				return err
  1155  			}
  1156  			httpReq.Header = headers
  1157  
  1158  			httpRsp, err := c.httpClient.Do(httpReq)
  1159  			if err != nil {
  1160  				return err
  1161  			}
  1162  			defer httpRsp.Body.Close()
  1163  
  1164  			if err = googleapi.CheckResponse(httpRsp); err != nil {
  1165  				return err
  1166  			}
  1167  
  1168  			buf, err := io.ReadAll(httpRsp.Body)
  1169  			if err != nil {
  1170  				return err
  1171  			}
  1172  
  1173  			if err := unm.Unmarshal(buf, resp); err != nil {
  1174  				return err
  1175  			}
  1176  
  1177  			return nil
  1178  		}, opts...)
  1179  		if e != nil {
  1180  			return nil, "", e
  1181  		}
  1182  		it.Response = resp
  1183  		return resp.GetSchemas(), resp.GetNextPageToken(), nil
  1184  	}
  1185  
  1186  	fetch := func(pageSize int, pageToken string) (string, error) {
  1187  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1188  		if err != nil {
  1189  			return "", err
  1190  		}
  1191  		it.items = append(it.items, items...)
  1192  		return nextPageToken, nil
  1193  	}
  1194  
  1195  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1196  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1197  	it.pageInfo.Token = req.GetPageToken()
  1198  
  1199  	return it
  1200  }
  1201  
  1202  // CommitSchema commits a new schema revision to an existing schema.
  1203  func (c *schemaRESTClient) CommitSchema(ctx context.Context, req *pubsubpb.CommitSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
  1204  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1205  	jsonReq, err := m.Marshal(req)
  1206  	if err != nil {
  1207  		return nil, err
  1208  	}
  1209  
  1210  	baseUrl, err := url.Parse(c.endpoint)
  1211  	if err != nil {
  1212  		return nil, err
  1213  	}
  1214  	baseUrl.Path += fmt.Sprintf("/v1/%v:commit", req.GetName())
  1215  
  1216  	params := url.Values{}
  1217  	params.Add("$alt", "json;enum-encoding=int")
  1218  
  1219  	baseUrl.RawQuery = params.Encode()
  1220  
  1221  	// Build HTTP headers from client and context metadata.
  1222  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1223  
  1224  	hds = append(c.xGoogHeaders, hds...)
  1225  	hds = append(hds, "Content-Type", "application/json")
  1226  	headers := gax.BuildHeaders(ctx, hds...)
  1227  	opts = append((*c.CallOptions).CommitSchema[0:len((*c.CallOptions).CommitSchema):len((*c.CallOptions).CommitSchema)], opts...)
  1228  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1229  	resp := &pubsubpb.Schema{}
  1230  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1231  		if settings.Path != "" {
  1232  			baseUrl.Path = settings.Path
  1233  		}
  1234  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1235  		if err != nil {
  1236  			return err
  1237  		}
  1238  		httpReq = httpReq.WithContext(ctx)
  1239  		httpReq.Header = headers
  1240  
  1241  		httpRsp, err := c.httpClient.Do(httpReq)
  1242  		if err != nil {
  1243  			return err
  1244  		}
  1245  		defer httpRsp.Body.Close()
  1246  
  1247  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1248  			return err
  1249  		}
  1250  
  1251  		buf, err := io.ReadAll(httpRsp.Body)
  1252  		if err != nil {
  1253  			return err
  1254  		}
  1255  
  1256  		if err := unm.Unmarshal(buf, resp); err != nil {
  1257  			return err
  1258  		}
  1259  
  1260  		return nil
  1261  	}, opts...)
  1262  	if e != nil {
  1263  		return nil, e
  1264  	}
  1265  	return resp, nil
  1266  }
  1267  
  1268  // RollbackSchema creates a new schema revision that is a copy of the provided revision_id.
  1269  func (c *schemaRESTClient) RollbackSchema(ctx context.Context, req *pubsubpb.RollbackSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
  1270  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1271  	jsonReq, err := m.Marshal(req)
  1272  	if err != nil {
  1273  		return nil, err
  1274  	}
  1275  
  1276  	baseUrl, err := url.Parse(c.endpoint)
  1277  	if err != nil {
  1278  		return nil, err
  1279  	}
  1280  	baseUrl.Path += fmt.Sprintf("/v1/%v:rollback", req.GetName())
  1281  
  1282  	params := url.Values{}
  1283  	params.Add("$alt", "json;enum-encoding=int")
  1284  
  1285  	baseUrl.RawQuery = params.Encode()
  1286  
  1287  	// Build HTTP headers from client and context metadata.
  1288  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1289  
  1290  	hds = append(c.xGoogHeaders, hds...)
  1291  	hds = append(hds, "Content-Type", "application/json")
  1292  	headers := gax.BuildHeaders(ctx, hds...)
  1293  	opts = append((*c.CallOptions).RollbackSchema[0:len((*c.CallOptions).RollbackSchema):len((*c.CallOptions).RollbackSchema)], opts...)
  1294  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1295  	resp := &pubsubpb.Schema{}
  1296  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1297  		if settings.Path != "" {
  1298  			baseUrl.Path = settings.Path
  1299  		}
  1300  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1301  		if err != nil {
  1302  			return err
  1303  		}
  1304  		httpReq = httpReq.WithContext(ctx)
  1305  		httpReq.Header = headers
  1306  
  1307  		httpRsp, err := c.httpClient.Do(httpReq)
  1308  		if err != nil {
  1309  			return err
  1310  		}
  1311  		defer httpRsp.Body.Close()
  1312  
  1313  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1314  			return err
  1315  		}
  1316  
  1317  		buf, err := io.ReadAll(httpRsp.Body)
  1318  		if err != nil {
  1319  			return err
  1320  		}
  1321  
  1322  		if err := unm.Unmarshal(buf, resp); err != nil {
  1323  			return err
  1324  		}
  1325  
  1326  		return nil
  1327  	}, opts...)
  1328  	if e != nil {
  1329  		return nil, e
  1330  	}
  1331  	return resp, nil
  1332  }
  1333  
  1334  // DeleteSchemaRevision deletes a specific schema revision.
  1335  func (c *schemaRESTClient) DeleteSchemaRevision(ctx context.Context, req *pubsubpb.DeleteSchemaRevisionRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error) {
  1336  	baseUrl, err := url.Parse(c.endpoint)
  1337  	if err != nil {
  1338  		return nil, err
  1339  	}
  1340  	baseUrl.Path += fmt.Sprintf("/v1/%v:deleteRevision", req.GetName())
  1341  
  1342  	params := url.Values{}
  1343  	params.Add("$alt", "json;enum-encoding=int")
  1344  	if req.GetRevisionId() != "" {
  1345  		params.Add("revisionId", fmt.Sprintf("%v", req.GetRevisionId()))
  1346  	}
  1347  
  1348  	baseUrl.RawQuery = params.Encode()
  1349  
  1350  	// Build HTTP headers from client and context metadata.
  1351  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1352  
  1353  	hds = append(c.xGoogHeaders, hds...)
  1354  	hds = append(hds, "Content-Type", "application/json")
  1355  	headers := gax.BuildHeaders(ctx, hds...)
  1356  	opts = append((*c.CallOptions).DeleteSchemaRevision[0:len((*c.CallOptions).DeleteSchemaRevision):len((*c.CallOptions).DeleteSchemaRevision)], opts...)
  1357  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1358  	resp := &pubsubpb.Schema{}
  1359  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1360  		if settings.Path != "" {
  1361  			baseUrl.Path = settings.Path
  1362  		}
  1363  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1364  		if err != nil {
  1365  			return err
  1366  		}
  1367  		httpReq = httpReq.WithContext(ctx)
  1368  		httpReq.Header = headers
  1369  
  1370  		httpRsp, err := c.httpClient.Do(httpReq)
  1371  		if err != nil {
  1372  			return err
  1373  		}
  1374  		defer httpRsp.Body.Close()
  1375  
  1376  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1377  			return err
  1378  		}
  1379  
  1380  		buf, err := io.ReadAll(httpRsp.Body)
  1381  		if err != nil {
  1382  			return err
  1383  		}
  1384  
  1385  		if err := unm.Unmarshal(buf, resp); err != nil {
  1386  			return err
  1387  		}
  1388  
  1389  		return nil
  1390  	}, opts...)
  1391  	if e != nil {
  1392  		return nil, e
  1393  	}
  1394  	return resp, nil
  1395  }
  1396  
  1397  // DeleteSchema deletes a schema.
  1398  func (c *schemaRESTClient) DeleteSchema(ctx context.Context, req *pubsubpb.DeleteSchemaRequest, opts ...gax.CallOption) error {
  1399  	baseUrl, err := url.Parse(c.endpoint)
  1400  	if err != nil {
  1401  		return err
  1402  	}
  1403  	baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
  1404  
  1405  	params := url.Values{}
  1406  	params.Add("$alt", "json;enum-encoding=int")
  1407  
  1408  	baseUrl.RawQuery = params.Encode()
  1409  
  1410  	// Build HTTP headers from client and context metadata.
  1411  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1412  
  1413  	hds = append(c.xGoogHeaders, hds...)
  1414  	hds = append(hds, "Content-Type", "application/json")
  1415  	headers := gax.BuildHeaders(ctx, hds...)
  1416  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1417  		if settings.Path != "" {
  1418  			baseUrl.Path = settings.Path
  1419  		}
  1420  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1421  		if err != nil {
  1422  			return err
  1423  		}
  1424  		httpReq = httpReq.WithContext(ctx)
  1425  		httpReq.Header = headers
  1426  
  1427  		httpRsp, err := c.httpClient.Do(httpReq)
  1428  		if err != nil {
  1429  			return err
  1430  		}
  1431  		defer httpRsp.Body.Close()
  1432  
  1433  		// Returns nil if there is no error, otherwise wraps
  1434  		// the response code and body into a non-nil error
  1435  		return googleapi.CheckResponse(httpRsp)
  1436  	}, opts...)
  1437  }
  1438  
  1439  // ValidateSchema validates a schema.
  1440  func (c *schemaRESTClient) ValidateSchema(ctx context.Context, req *pubsubpb.ValidateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.ValidateSchemaResponse, error) {
  1441  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1442  	jsonReq, err := m.Marshal(req)
  1443  	if err != nil {
  1444  		return nil, err
  1445  	}
  1446  
  1447  	baseUrl, err := url.Parse(c.endpoint)
  1448  	if err != nil {
  1449  		return nil, err
  1450  	}
  1451  	baseUrl.Path += fmt.Sprintf("/v1/%v/schemas:validate", req.GetParent())
  1452  
  1453  	params := url.Values{}
  1454  	params.Add("$alt", "json;enum-encoding=int")
  1455  
  1456  	baseUrl.RawQuery = params.Encode()
  1457  
  1458  	// Build HTTP headers from client and context metadata.
  1459  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  1460  
  1461  	hds = append(c.xGoogHeaders, hds...)
  1462  	hds = append(hds, "Content-Type", "application/json")
  1463  	headers := gax.BuildHeaders(ctx, hds...)
  1464  	opts = append((*c.CallOptions).ValidateSchema[0:len((*c.CallOptions).ValidateSchema):len((*c.CallOptions).ValidateSchema)], opts...)
  1465  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1466  	resp := &pubsubpb.ValidateSchemaResponse{}
  1467  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1468  		if settings.Path != "" {
  1469  			baseUrl.Path = settings.Path
  1470  		}
  1471  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1472  		if err != nil {
  1473  			return err
  1474  		}
  1475  		httpReq = httpReq.WithContext(ctx)
  1476  		httpReq.Header = headers
  1477  
  1478  		httpRsp, err := c.httpClient.Do(httpReq)
  1479  		if err != nil {
  1480  			return err
  1481  		}
  1482  		defer httpRsp.Body.Close()
  1483  
  1484  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1485  			return err
  1486  		}
  1487  
  1488  		buf, err := io.ReadAll(httpRsp.Body)
  1489  		if err != nil {
  1490  			return err
  1491  		}
  1492  
  1493  		if err := unm.Unmarshal(buf, resp); err != nil {
  1494  			return err
  1495  		}
  1496  
  1497  		return nil
  1498  	}, opts...)
  1499  	if e != nil {
  1500  		return nil, e
  1501  	}
  1502  	return resp, nil
  1503  }
  1504  
  1505  // ValidateMessage validates a message against a schema.
  1506  func (c *schemaRESTClient) ValidateMessage(ctx context.Context, req *pubsubpb.ValidateMessageRequest, opts ...gax.CallOption) (*pubsubpb.ValidateMessageResponse, error) {
  1507  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1508  	jsonReq, err := m.Marshal(req)
  1509  	if err != nil {
  1510  		return nil, err
  1511  	}
  1512  
  1513  	baseUrl, err := url.Parse(c.endpoint)
  1514  	if err != nil {
  1515  		return nil, err
  1516  	}
  1517  	baseUrl.Path += fmt.Sprintf("/v1/%v/schemas:validateMessage", req.GetParent())
  1518  
  1519  	params := url.Values{}
  1520  	params.Add("$alt", "json;enum-encoding=int")
  1521  
  1522  	baseUrl.RawQuery = params.Encode()
  1523  
  1524  	// Build HTTP headers from client and context metadata.
  1525  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  1526  
  1527  	hds = append(c.xGoogHeaders, hds...)
  1528  	hds = append(hds, "Content-Type", "application/json")
  1529  	headers := gax.BuildHeaders(ctx, hds...)
  1530  	opts = append((*c.CallOptions).ValidateMessage[0:len((*c.CallOptions).ValidateMessage):len((*c.CallOptions).ValidateMessage)], opts...)
  1531  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1532  	resp := &pubsubpb.ValidateMessageResponse{}
  1533  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1534  		if settings.Path != "" {
  1535  			baseUrl.Path = settings.Path
  1536  		}
  1537  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1538  		if err != nil {
  1539  			return err
  1540  		}
  1541  		httpReq = httpReq.WithContext(ctx)
  1542  		httpReq.Header = headers
  1543  
  1544  		httpRsp, err := c.httpClient.Do(httpReq)
  1545  		if err != nil {
  1546  			return err
  1547  		}
  1548  		defer httpRsp.Body.Close()
  1549  
  1550  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1551  			return err
  1552  		}
  1553  
  1554  		buf, err := io.ReadAll(httpRsp.Body)
  1555  		if err != nil {
  1556  			return err
  1557  		}
  1558  
  1559  		if err := unm.Unmarshal(buf, resp); err != nil {
  1560  			return err
  1561  		}
  1562  
  1563  		return nil
  1564  	}, opts...)
  1565  	if e != nil {
  1566  		return nil, e
  1567  	}
  1568  	return resp, nil
  1569  }
  1570  
  1571  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
  1572  // if the resource exists and does not have a policy set.
  1573  func (c *schemaRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1574  	baseUrl, err := url.Parse(c.endpoint)
  1575  	if err != nil {
  1576  		return nil, err
  1577  	}
  1578  	baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
  1579  
  1580  	params := url.Values{}
  1581  	params.Add("$alt", "json;enum-encoding=int")
  1582  	if req.GetOptions().GetRequestedPolicyVersion() != 0 {
  1583  		params.Add("options.requestedPolicyVersion", fmt.Sprintf("%v", req.GetOptions().GetRequestedPolicyVersion()))
  1584  	}
  1585  
  1586  	baseUrl.RawQuery = params.Encode()
  1587  
  1588  	// Build HTTP headers from client and context metadata.
  1589  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1590  
  1591  	hds = append(c.xGoogHeaders, hds...)
  1592  	hds = append(hds, "Content-Type", "application/json")
  1593  	headers := gax.BuildHeaders(ctx, hds...)
  1594  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1595  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1596  	resp := &iampb.Policy{}
  1597  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1598  		if settings.Path != "" {
  1599  			baseUrl.Path = settings.Path
  1600  		}
  1601  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1602  		if err != nil {
  1603  			return err
  1604  		}
  1605  		httpReq = httpReq.WithContext(ctx)
  1606  		httpReq.Header = headers
  1607  
  1608  		httpRsp, err := c.httpClient.Do(httpReq)
  1609  		if err != nil {
  1610  			return err
  1611  		}
  1612  		defer httpRsp.Body.Close()
  1613  
  1614  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1615  			return err
  1616  		}
  1617  
  1618  		buf, err := io.ReadAll(httpRsp.Body)
  1619  		if err != nil {
  1620  			return err
  1621  		}
  1622  
  1623  		if err := unm.Unmarshal(buf, resp); err != nil {
  1624  			return err
  1625  		}
  1626  
  1627  		return nil
  1628  	}, opts...)
  1629  	if e != nil {
  1630  		return nil, e
  1631  	}
  1632  	return resp, nil
  1633  }
  1634  
  1635  // SetIamPolicy sets the access control policy on the specified resource. Replaces
  1636  // any existing policy.
  1637  //
  1638  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
  1639  // errors.
  1640  func (c *schemaRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1641  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1642  	jsonReq, err := m.Marshal(req)
  1643  	if err != nil {
  1644  		return nil, err
  1645  	}
  1646  
  1647  	baseUrl, err := url.Parse(c.endpoint)
  1648  	if err != nil {
  1649  		return nil, err
  1650  	}
  1651  	baseUrl.Path += fmt.Sprintf("/v1/%v:setIamPolicy", req.GetResource())
  1652  
  1653  	params := url.Values{}
  1654  	params.Add("$alt", "json;enum-encoding=int")
  1655  
  1656  	baseUrl.RawQuery = params.Encode()
  1657  
  1658  	// Build HTTP headers from client and context metadata.
  1659  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1660  
  1661  	hds = append(c.xGoogHeaders, hds...)
  1662  	hds = append(hds, "Content-Type", "application/json")
  1663  	headers := gax.BuildHeaders(ctx, hds...)
  1664  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1665  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1666  	resp := &iampb.Policy{}
  1667  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1668  		if settings.Path != "" {
  1669  			baseUrl.Path = settings.Path
  1670  		}
  1671  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1672  		if err != nil {
  1673  			return err
  1674  		}
  1675  		httpReq = httpReq.WithContext(ctx)
  1676  		httpReq.Header = headers
  1677  
  1678  		httpRsp, err := c.httpClient.Do(httpReq)
  1679  		if err != nil {
  1680  			return err
  1681  		}
  1682  		defer httpRsp.Body.Close()
  1683  
  1684  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1685  			return err
  1686  		}
  1687  
  1688  		buf, err := io.ReadAll(httpRsp.Body)
  1689  		if err != nil {
  1690  			return err
  1691  		}
  1692  
  1693  		if err := unm.Unmarshal(buf, resp); err != nil {
  1694  			return err
  1695  		}
  1696  
  1697  		return nil
  1698  	}, opts...)
  1699  	if e != nil {
  1700  		return nil, e
  1701  	}
  1702  	return resp, nil
  1703  }
  1704  
  1705  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
  1706  // resource does not exist, this will return an empty set of
  1707  // permissions, not a NOT_FOUND error.
  1708  //
  1709  // Note: This operation is designed to be used for building
  1710  // permission-aware UIs and command-line tools, not for authorization
  1711  // checking. This operation may “fail open” without warning.
  1712  func (c *schemaRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1713  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1714  	jsonReq, err := m.Marshal(req)
  1715  	if err != nil {
  1716  		return nil, err
  1717  	}
  1718  
  1719  	baseUrl, err := url.Parse(c.endpoint)
  1720  	if err != nil {
  1721  		return nil, err
  1722  	}
  1723  	baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
  1724  
  1725  	params := url.Values{}
  1726  	params.Add("$alt", "json;enum-encoding=int")
  1727  
  1728  	baseUrl.RawQuery = params.Encode()
  1729  
  1730  	// Build HTTP headers from client and context metadata.
  1731  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1732  
  1733  	hds = append(c.xGoogHeaders, hds...)
  1734  	hds = append(hds, "Content-Type", "application/json")
  1735  	headers := gax.BuildHeaders(ctx, hds...)
  1736  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1737  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1738  	resp := &iampb.TestIamPermissionsResponse{}
  1739  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1740  		if settings.Path != "" {
  1741  			baseUrl.Path = settings.Path
  1742  		}
  1743  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1744  		if err != nil {
  1745  			return err
  1746  		}
  1747  		httpReq = httpReq.WithContext(ctx)
  1748  		httpReq.Header = headers
  1749  
  1750  		httpRsp, err := c.httpClient.Do(httpReq)
  1751  		if err != nil {
  1752  			return err
  1753  		}
  1754  		defer httpRsp.Body.Close()
  1755  
  1756  		if err = googleapi.CheckResponse(httpRsp); err != nil {
  1757  			return err
  1758  		}
  1759  
  1760  		buf, err := io.ReadAll(httpRsp.Body)
  1761  		if err != nil {
  1762  			return err
  1763  		}
  1764  
  1765  		if err := unm.Unmarshal(buf, resp); err != nil {
  1766  			return err
  1767  		}
  1768  
  1769  		return nil
  1770  	}, opts...)
  1771  	if e != nil {
  1772  		return nil, e
  1773  	}
  1774  	return resp, nil
  1775  }
  1776  

View as plain text