| 1 |
// Copyright 2025 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 apihub |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
|
| 28 |
apihubpb "cloud.google.com/go/apihub/apiv1/apihubpb" |
| 29 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 30 |
gax "github.com/googleapis/gax-go/v2" |
| 31 |
"google.golang.org/api/iterator" |
| 32 |
"google.golang.org/api/option" |
| 33 |
"google.golang.org/api/option/internaloption" |
| 34 |
httptransport "google.golang.org/api/transport/http" |
| 35 |
locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| 36 |
"google.golang.org/grpc" |
| 37 |
"google.golang.org/protobuf/encoding/protojson" |
| 38 |
"google.golang.org/protobuf/proto" |
| 39 |
) |
| 40 |
|
| 41 |
var newApiHubCurateClientHook clientHook |
| 42 |
|
| 43 |
// ApiHubCurateCallOptions contains the retry settings for each method of ApiHubCurateClient. |
| 44 |
type ApiHubCurateCallOptions struct { |
| 45 |
CreateCuration []gax.CallOption |
| 46 |
GetCuration []gax.CallOption |
| 47 |
ListCurations []gax.CallOption |
| 48 |
UpdateCuration []gax.CallOption |
| 49 |
DeleteCuration []gax.CallOption |
| 50 |
GetLocation []gax.CallOption |
| 51 |
ListLocations []gax.CallOption |
| 52 |
CancelOperation []gax.CallOption |
| 53 |
DeleteOperation []gax.CallOption |
| 54 |
GetOperation []gax.CallOption |
| 55 |
ListOperations []gax.CallOption |
| 56 |
} |
| 57 |
|
| 58 |
func defaultApiHubCurateRESTCallOptions() *ApiHubCurateCallOptions { |
| 59 |
return &ApiHubCurateCallOptions{ |
| 60 |
CreateCuration: []gax.CallOption{}, |
| 61 |
GetCuration: []gax.CallOption{}, |
| 62 |
ListCurations: []gax.CallOption{}, |
| 63 |
UpdateCuration: []gax.CallOption{}, |
| 64 |
DeleteCuration: []gax.CallOption{}, |
| 65 |
GetLocation: []gax.CallOption{}, |
| 66 |
ListLocations: []gax.CallOption{}, |
| 67 |
CancelOperation: []gax.CallOption{}, |
| 68 |
DeleteOperation: []gax.CallOption{}, |
| 69 |
GetOperation: []gax.CallOption{}, |
| 70 |
ListOperations: []gax.CallOption{}, |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
// internalApiHubCurateClient is an interface that defines the methods available from API hub API. |
| 75 |
type internalApiHubCurateClient interface { |
| 76 |
Close() error |
| 77 |
setGoogleClientInfo(...string) |
| 78 |
Connection() *grpc.ClientConn |
| 79 |
CreateCuration(context.Context, *apihubpb.CreateCurationRequest, ...gax.CallOption) (*apihubpb.Curation, error) |
| 80 |
GetCuration(context.Context, *apihubpb.GetCurationRequest, ...gax.CallOption) (*apihubpb.Curation, error) |
| 81 |
ListCurations(context.Context, *apihubpb.ListCurationsRequest, ...gax.CallOption) *CurationIterator |
| 82 |
UpdateCuration(context.Context, *apihubpb.UpdateCurationRequest, ...gax.CallOption) (*apihubpb.Curation, error) |
| 83 |
DeleteCuration(context.Context, *apihubpb.DeleteCurationRequest, ...gax.CallOption) error |
| 84 |
GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) |
| 85 |
ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator |
| 86 |
CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error |
| 87 |
DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error |
| 88 |
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) |
| 89 |
ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator |
| 90 |
} |
| 91 |
|
| 92 |
// ApiHubCurateClient is a client for interacting with API hub API. |
| 93 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 94 |
// |
| 95 |
// This service is used for managing curations for processing API data consumed |
| 96 |
// from collect layer. |
| 97 |
type ApiHubCurateClient struct { |
| 98 |
// The internal transport-dependent client. |
| 99 |
internalClient internalApiHubCurateClient |
| 100 |
|
| 101 |
// The call options for this service. |
| 102 |
CallOptions *ApiHubCurateCallOptions |
| 103 |
} |
| 104 |
|
| 105 |
// Wrapper methods routed to the internal client. |
| 106 |
|
| 107 |
// Close closes the connection to the API service. The user should invoke this when |
| 108 |
// the client is no longer required. |
| 109 |
func (c *ApiHubCurateClient) Close() error { |
| 110 |
return c.internalClient.Close() |
| 111 |
} |
| 112 |
|
| 113 |
// setGoogleClientInfo sets the name and version of the application in |
| 114 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 115 |
// use by Google-written clients. |
| 116 |
func (c *ApiHubCurateClient) setGoogleClientInfo(keyval ...string) { |
| 117 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 118 |
} |
| 119 |
|
| 120 |
// Connection returns a connection to the API service. |
| 121 |
// |
| 122 |
// Deprecated: Connections are now pooled so this method does not always |
| 123 |
// return the same resource. |
| 124 |
func (c *ApiHubCurateClient) Connection() *grpc.ClientConn { |
| 125 |
return c.internalClient.Connection() |
| 126 |
} |
| 127 |
|
| 128 |
// CreateCuration create a curation resource in the API hub. |
| 129 |
// Once a curation resource is created, plugin instances can start using it. |
| 130 |
func (c *ApiHubCurateClient) CreateCuration(ctx context.Context, req *apihubpb.CreateCurationRequest, opts ...gax.CallOption) (*apihubpb.Curation, error) { |
| 131 |
return c.internalClient.CreateCuration(ctx, req, opts...) |
| 132 |
} |
| 133 |
|
| 134 |
// GetCuration get curation resource details. |
| 135 |
func (c *ApiHubCurateClient) GetCuration(ctx context.Context, req *apihubpb.GetCurationRequest, opts ...gax.CallOption) (*apihubpb.Curation, error) { |
| 136 |
return c.internalClient.GetCuration(ctx, req, opts...) |
| 137 |
} |
| 138 |
|
| 139 |
// ListCurations list curation resources in the API hub. |
| 140 |
func (c *ApiHubCurateClient) ListCurations(ctx context.Context, req *apihubpb.ListCurationsRequest, opts ...gax.CallOption) *CurationIterator { |
| 141 |
return c.internalClient.ListCurations(ctx, req, opts...) |
| 142 |
} |
| 143 |
|
| 144 |
// UpdateCuration update a curation resource in the API hub. The following fields in the |
| 145 |
// curation can be updated: |
| 146 |
// |
| 147 |
// display_name |
| 148 |
// |
| 149 |
// description |
| 150 |
// |
| 151 |
// The |
| 152 |
// update_mask |
| 153 |
// should be used to specify the fields being updated. |
| 154 |
func (c *ApiHubCurateClient) UpdateCuration(ctx context.Context, req *apihubpb.UpdateCurationRequest, opts ...gax.CallOption) (*apihubpb.Curation, error) { |
| 155 |
return c.internalClient.UpdateCuration(ctx, req, opts...) |
| 156 |
} |
| 157 |
|
| 158 |
// DeleteCuration delete a curation resource in the API hub. A curation can only be deleted |
| 159 |
// if it’s not being used by any plugin instance. |
| 160 |
func (c *ApiHubCurateClient) DeleteCuration(ctx context.Context, req *apihubpb.DeleteCurationRequest, opts ...gax.CallOption) error { |
| 161 |
return c.internalClient.DeleteCuration(ctx, req, opts...) |
| 162 |
} |
| 163 |
|
| 164 |
// GetLocation gets information about a location. |
| 165 |
func (c *ApiHubCurateClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 166 |
return c.internalClient.GetLocation(ctx, req, opts...) |
| 167 |
} |
| 168 |
|
| 169 |
// ListLocations lists information about the supported locations for this service. |
| 170 |
func (c *ApiHubCurateClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 171 |
return c.internalClient.ListLocations(ctx, req, opts...) |
| 172 |
} |
| 173 |
|
| 174 |
// CancelOperation is a utility method from google.longrunning.Operations. |
| 175 |
func (c *ApiHubCurateClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 176 |
return c.internalClient.CancelOperation(ctx, req, opts...) |
| 177 |
} |
| 178 |
|
| 179 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 180 |
func (c *ApiHubCurateClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 181 |
return c.internalClient.DeleteOperation(ctx, req, opts...) |
| 182 |
} |
| 183 |
|
| 184 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 185 |
func (c *ApiHubCurateClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 186 |
return c.internalClient.GetOperation(ctx, req, opts...) |
| 187 |
} |
| 188 |
|
| 189 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 190 |
func (c *ApiHubCurateClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 191 |
return c.internalClient.ListOperations(ctx, req, opts...) |
| 192 |
} |
| 193 |
|
| 194 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 195 |
type apiHubCurateRESTClient struct { |
| 196 |
// The http endpoint to connect to. |
| 197 |
endpoint string |
| 198 |
|
| 199 |
// The http client. |
| 200 |
httpClient *http.Client |
| 201 |
|
| 202 |
// The x-goog-* headers to be sent with each request. |
| 203 |
xGoogHeaders []string |
| 204 |
|
| 205 |
// Points back to the CallOptions field of the containing ApiHubCurateClient |
| 206 |
CallOptions **ApiHubCurateCallOptions |
| 207 |
|
| 208 |
logger *slog.Logger |
| 209 |
} |
| 210 |
|
| 211 |
// NewApiHubCurateRESTClient creates a new api hub curate rest client. |
| 212 |
// |
| 213 |
// This service is used for managing curations for processing API data consumed |
| 214 |
// from collect layer. |
| 215 |
func NewApiHubCurateRESTClient(ctx context.Context, opts ...option.ClientOption) (*ApiHubCurateClient, error) { |
| 216 |
clientOpts := append(defaultApiHubCurateRESTClientOptions(), opts...) |
| 217 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 218 |
if err != nil { |
| 219 |
return nil, err |
| 220 |
} |
| 221 |
|
| 222 |
callOpts := defaultApiHubCurateRESTCallOptions() |
| 223 |
c := &apiHubCurateRESTClient{ |
| 224 |
endpoint: endpoint, |
| 225 |
httpClient: httpClient, |
| 226 |
CallOptions: &callOpts, |
| 227 |
logger: internaloption.GetLogger(opts), |
| 228 |
} |
| 229 |
c.setGoogleClientInfo() |
| 230 |
|
| 231 |
return &ApiHubCurateClient{internalClient: c, CallOptions: callOpts}, nil |
| 232 |
} |
| 233 |
|
| 234 |
func defaultApiHubCurateRESTClientOptions() []option.ClientOption { |
| 235 |
return []option.ClientOption{ |
| 236 |
internaloption.WithDefaultEndpoint("https://apihub.googleapis.com"), |
| 237 |
internaloption.WithDefaultEndpointTemplate("https://apihub.UNIVERSE_DOMAIN"), |
| 238 |
internaloption.WithDefaultMTLSEndpoint("https://apihub.mtls.googleapis.com"), |
| 239 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 240 |
internaloption.WithDefaultAudience("https://apihub.googleapis.com/"), |
| 241 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 242 |
internaloption.EnableNewAuthLibrary(), |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
// setGoogleClientInfo sets the name and version of the application in |
| 247 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 248 |
// use by Google-written clients. |
| 249 |
func (c *apiHubCurateRESTClient) setGoogleClientInfo(keyval ...string) { |
| 250 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 251 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 252 |
c.xGoogHeaders = []string{ |
| 253 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
// Close closes the connection to the API service. The user should invoke this when |
| 258 |
// the client is no longer required. |
| 259 |
func (c *apiHubCurateRESTClient) Close() error { |
| 260 |
// Replace httpClient with nil to force cleanup. |
| 261 |
c.httpClient = nil |
| 262 |
return nil |
| 263 |
} |
| 264 |
|
| 265 |
// Connection returns a connection to the API service. |
| 266 |
// |
| 267 |
// Deprecated: This method always returns nil. |
| 268 |
func (c *apiHubCurateRESTClient) Connection() *grpc.ClientConn { |
| 269 |
return nil |
| 270 |
} |
| 271 |
|
| 272 |
// CreateCuration create a curation resource in the API hub. |
| 273 |
// Once a curation resource is created, plugin instances can start using it. |
| 274 |
func (c *apiHubCurateRESTClient) CreateCuration(ctx context.Context, req *apihubpb.CreateCurationRequest, opts ...gax.CallOption) (*apihubpb.Curation, error) { |
| 275 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 276 |
body := req.GetCuration() |
| 277 |
jsonReq, err := m.Marshal(body) |
| 278 |
if err != nil { |
| 279 |
return nil, err |
| 280 |
} |
| 281 |
|
| 282 |
baseUrl, err := url.Parse(c.endpoint) |
| 283 |
if err != nil { |
| 284 |
return nil, err |
| 285 |
} |
| 286 |
baseUrl.Path += fmt.Sprintf("/v1/%v/curations", req.GetParent()) |
| 287 |
|
| 288 |
params := url.Values{} |
| 289 |
params.Add("$alt", "json;enum-encoding=int") |
| 290 |
if req.GetCurationId() != "" { |
| 291 |
params.Add("curationId", fmt.Sprintf("%v", req.GetCurationId())) |
| 292 |
} |
| 293 |
|
| 294 |
baseUrl.RawQuery = params.Encode() |
| 295 |
|
| 296 |
// Build HTTP headers from client and context metadata. |
| 297 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 298 |
|
| 299 |
hds = append(c.xGoogHeaders, hds...) |
| 300 |
hds = append(hds, "Content-Type", "application/json") |
| 301 |
headers := gax.BuildHeaders(ctx, hds...) |
| 302 |
opts = append((*c.CallOptions).CreateCuration[0:len((*c.CallOptions).CreateCuration):len((*c.CallOptions).CreateCuration)], opts...) |
| 303 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 304 |
resp := &apihubpb.Curation{} |
| 305 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 306 |
if settings.Path != "" { |
| 307 |
baseUrl.Path = settings.Path |
| 308 |
} |
| 309 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 310 |
if err != nil { |
| 311 |
return err |
| 312 |
} |
| 313 |
httpReq = httpReq.WithContext(ctx) |
| 314 |
httpReq.Header = headers |
| 315 |
|
| 316 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateCuration") |
| 317 |
if err != nil { |
| 318 |
return err |
| 319 |
} |
| 320 |
|
| 321 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 322 |
return err |
| 323 |
} |
| 324 |
|
| 325 |
return nil |
| 326 |
}, opts...) |
| 327 |
if e != nil { |
| 328 |
return nil, e |
| 329 |
} |
| 330 |
return resp, nil |
| 331 |
} |
| 332 |
|
| 333 |
// GetCuration get curation resource details. |
| 334 |
func (c *apiHubCurateRESTClient) GetCuration(ctx context.Context, req *apihubpb.GetCurationRequest, opts ...gax.CallOption) (*apihubpb.Curation, error) { |
| 335 |
baseUrl, err := url.Parse(c.endpoint) |
| 336 |
if err != nil { |
| 337 |
return nil, err |
| 338 |
} |
| 339 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 340 |
|
| 341 |
params := url.Values{} |
| 342 |
params.Add("$alt", "json;enum-encoding=int") |
| 343 |
|
| 344 |
baseUrl.RawQuery = params.Encode() |
| 345 |
|
| 346 |
// Build HTTP headers from client and context metadata. |
| 347 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 348 |
|
| 349 |
hds = append(c.xGoogHeaders, hds...) |
| 350 |
hds = append(hds, "Content-Type", "application/json") |
| 351 |
headers := gax.BuildHeaders(ctx, hds...) |
| 352 |
opts = append((*c.CallOptions).GetCuration[0:len((*c.CallOptions).GetCuration):len((*c.CallOptions).GetCuration)], opts...) |
| 353 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 354 |
resp := &apihubpb.Curation{} |
| 355 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 356 |
if settings.Path != "" { |
| 357 |
baseUrl.Path = settings.Path |
| 358 |
} |
| 359 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 360 |
if err != nil { |
| 361 |
return err |
| 362 |
} |
| 363 |
httpReq = httpReq.WithContext(ctx) |
| 364 |
httpReq.Header = headers |
| 365 |
|
| 366 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCuration") |
| 367 |
if err != nil { |
| 368 |
return err |
| 369 |
} |
| 370 |
|
| 371 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 372 |
return err |
| 373 |
} |
| 374 |
|
| 375 |
return nil |
| 376 |
}, opts...) |
| 377 |
if e != nil { |
| 378 |
return nil, e |
| 379 |
} |
| 380 |
return resp, nil |
| 381 |
} |
| 382 |
|
| 383 |
// ListCurations list curation resources in the API hub. |
| 384 |
func (c *apiHubCurateRESTClient) ListCurations(ctx context.Context, req *apihubpb.ListCurationsRequest, opts ...gax.CallOption) *CurationIterator { |
| 385 |
it := &CurationIterator{} |
| 386 |
req = proto.Clone(req).(*apihubpb.ListCurationsRequest) |
| 387 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 388 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Curation, string, error) { |
| 389 |
resp := &apihubpb.ListCurationsResponse{} |
| 390 |
if pageToken != "" { |
| 391 |
req.PageToken = pageToken |
| 392 |
} |
| 393 |
if pageSize > math.MaxInt32 { |
| 394 |
req.PageSize = math.MaxInt32 |
| 395 |
} else if pageSize != 0 { |
| 396 |
req.PageSize = int32(pageSize) |
| 397 |
} |
| 398 |
baseUrl, err := url.Parse(c.endpoint) |
| 399 |
if err != nil { |
| 400 |
return nil, "", err |
| 401 |
} |
| 402 |
baseUrl.Path += fmt.Sprintf("/v1/%v/curations", req.GetParent()) |
| 403 |
|
| 404 |
params := url.Values{} |
| 405 |
params.Add("$alt", "json;enum-encoding=int") |
| 406 |
if req.GetFilter() != "" { |
| 407 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 408 |
} |
| 409 |
if req.GetPageSize() != 0 { |
| 410 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 411 |
} |
| 412 |
if req.GetPageToken() != "" { |
| 413 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 414 |
} |
| 415 |
|
| 416 |
baseUrl.RawQuery = params.Encode() |
| 417 |
|
| 418 |
// Build HTTP headers from client and context metadata. |
| 419 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 420 |
headers := gax.BuildHeaders(ctx, hds...) |
| 421 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 422 |
if settings.Path != "" { |
| 423 |
baseUrl.Path = settings.Path |
| 424 |
} |
| 425 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 426 |
if err != nil { |
| 427 |
return err |
| 428 |
} |
| 429 |
httpReq.Header = headers |
| 430 |
|
| 431 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCurations") |
| 432 |
if err != nil { |
| 433 |
return err |
| 434 |
} |
| 435 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 436 |
return err |
| 437 |
} |
| 438 |
|
| 439 |
return nil |
| 440 |
}, opts...) |
| 441 |
if e != nil { |
| 442 |
return nil, "", e |
| 443 |
} |
| 444 |
it.Response = resp |
| 445 |
return resp.GetCurations(), resp.GetNextPageToken(), nil |
| 446 |
} |
| 447 |
|
| 448 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 449 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 450 |
if err != nil { |
| 451 |
return "", err |
| 452 |
} |
| 453 |
it.items = append(it.items, items...) |
| 454 |
return nextPageToken, nil |
| 455 |
} |
| 456 |
|
| 457 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 458 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 459 |
it.pageInfo.Token = req.GetPageToken() |
| 460 |
|
| 461 |
return it |
| 462 |
} |
| 463 |
|
| 464 |
// UpdateCuration update a curation resource in the API hub. The following fields in the |
| 465 |
// curation can be updated: |
| 466 |
// |
| 467 |
// display_name |
| 468 |
// |
| 469 |
// description |
| 470 |
// |
| 471 |
// The |
| 472 |
// update_mask |
| 473 |
// should be used to specify the fields being updated. |
| 474 |
func (c *apiHubCurateRESTClient) UpdateCuration(ctx context.Context, req *apihubpb.UpdateCurationRequest, opts ...gax.CallOption) (*apihubpb.Curation, error) { |
| 475 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 476 |
body := req.GetCuration() |
| 477 |
jsonReq, err := m.Marshal(body) |
| 478 |
if err != nil { |
| 479 |
return nil, err |
| 480 |
} |
| 481 |
|
| 482 |
baseUrl, err := url.Parse(c.endpoint) |
| 483 |
if err != nil { |
| 484 |
return nil, err |
| 485 |
} |
| 486 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetCuration().GetName()) |
| 487 |
|
| 488 |
params := url.Values{} |
| 489 |
params.Add("$alt", "json;enum-encoding=int") |
| 490 |
if req.GetUpdateMask() != nil { |
| 491 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 492 |
if err != nil { |
| 493 |
return nil, err |
| 494 |
} |
| 495 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 496 |
} |
| 497 |
|
| 498 |
baseUrl.RawQuery = params.Encode() |
| 499 |
|
| 500 |
// Build HTTP headers from client and context metadata. |
| 501 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "curation.name", url.QueryEscape(req.GetCuration().GetName()))} |
| 502 |
|
| 503 |
hds = append(c.xGoogHeaders, hds...) |
| 504 |
hds = append(hds, "Content-Type", "application/json") |
| 505 |
headers := gax.BuildHeaders(ctx, hds...) |
| 506 |
opts = append((*c.CallOptions).UpdateCuration[0:len((*c.CallOptions).UpdateCuration):len((*c.CallOptions).UpdateCuration)], opts...) |
| 507 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 508 |
resp := &apihubpb.Curation{} |
| 509 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 510 |
if settings.Path != "" { |
| 511 |
baseUrl.Path = settings.Path |
| 512 |
} |
| 513 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 514 |
if err != nil { |
| 515 |
return err |
| 516 |
} |
| 517 |
httpReq = httpReq.WithContext(ctx) |
| 518 |
httpReq.Header = headers |
| 519 |
|
| 520 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCuration") |
| 521 |
if err != nil { |
| 522 |
return err |
| 523 |
} |
| 524 |
|
| 525 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 526 |
return err |
| 527 |
} |
| 528 |
|
| 529 |
return nil |
| 530 |
}, opts...) |
| 531 |
if e != nil { |
| 532 |
return nil, e |
| 533 |
} |
| 534 |
return resp, nil |
| 535 |
} |
| 536 |
|
| 537 |
// DeleteCuration delete a curation resource in the API hub. A curation can only be deleted |
| 538 |
// if it’s not being used by any plugin instance. |
| 539 |
func (c *apiHubCurateRESTClient) DeleteCuration(ctx context.Context, req *apihubpb.DeleteCurationRequest, opts ...gax.CallOption) error { |
| 540 |
baseUrl, err := url.Parse(c.endpoint) |
| 541 |
if err != nil { |
| 542 |
return err |
| 543 |
} |
| 544 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 545 |
|
| 546 |
params := url.Values{} |
| 547 |
params.Add("$alt", "json;enum-encoding=int") |
| 548 |
|
| 549 |
baseUrl.RawQuery = params.Encode() |
| 550 |
|
| 551 |
// Build HTTP headers from client and context metadata. |
| 552 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 553 |
|
| 554 |
hds = append(c.xGoogHeaders, hds...) |
| 555 |
hds = append(hds, "Content-Type", "application/json") |
| 556 |
headers := gax.BuildHeaders(ctx, hds...) |
| 557 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 558 |
if settings.Path != "" { |
| 559 |
baseUrl.Path = settings.Path |
| 560 |
} |
| 561 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 562 |
if err != nil { |
| 563 |
return err |
| 564 |
} |
| 565 |
httpReq = httpReq.WithContext(ctx) |
| 566 |
httpReq.Header = headers |
| 567 |
|
| 568 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCuration") |
| 569 |
return err |
| 570 |
}, opts...) |
| 571 |
} |
| 572 |
|
| 573 |
// GetLocation gets information about a location. |
| 574 |
func (c *apiHubCurateRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 575 |
baseUrl, err := url.Parse(c.endpoint) |
| 576 |
if err != nil { |
| 577 |
return nil, err |
| 578 |
} |
| 579 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 580 |
|
| 581 |
params := url.Values{} |
| 582 |
params.Add("$alt", "json;enum-encoding=int") |
| 583 |
|
| 584 |
baseUrl.RawQuery = params.Encode() |
| 585 |
|
| 586 |
// Build HTTP headers from client and context metadata. |
| 587 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 588 |
|
| 589 |
hds = append(c.xGoogHeaders, hds...) |
| 590 |
hds = append(hds, "Content-Type", "application/json") |
| 591 |
headers := gax.BuildHeaders(ctx, hds...) |
| 592 |
opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) |
| 593 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 594 |
resp := &locationpb.Location{} |
| 595 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 596 |
if settings.Path != "" { |
| 597 |
baseUrl.Path = settings.Path |
| 598 |
} |
| 599 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 600 |
if err != nil { |
| 601 |
return err |
| 602 |
} |
| 603 |
httpReq = httpReq.WithContext(ctx) |
| 604 |
httpReq.Header = headers |
| 605 |
|
| 606 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") |
| 607 |
if err != nil { |
| 608 |
return err |
| 609 |
} |
| 610 |
|
| 611 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 612 |
return err |
| 613 |
} |
| 614 |
|
| 615 |
return nil |
| 616 |
}, opts...) |
| 617 |
if e != nil { |
| 618 |
return nil, e |
| 619 |
} |
| 620 |
return resp, nil |
| 621 |
} |
| 622 |
|
| 623 |
// ListLocations lists information about the supported locations for this service. |
| 624 |
func (c *apiHubCurateRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 625 |
it := &LocationIterator{} |
| 626 |
req = proto.Clone(req).(*locationpb.ListLocationsRequest) |
| 627 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 628 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { |
| 629 |
resp := &locationpb.ListLocationsResponse{} |
| 630 |
if pageToken != "" { |
| 631 |
req.PageToken = pageToken |
| 632 |
} |
| 633 |
if pageSize > math.MaxInt32 { |
| 634 |
req.PageSize = math.MaxInt32 |
| 635 |
} else if pageSize != 0 { |
| 636 |
req.PageSize = int32(pageSize) |
| 637 |
} |
| 638 |
baseUrl, err := url.Parse(c.endpoint) |
| 639 |
if err != nil { |
| 640 |
return nil, "", err |
| 641 |
} |
| 642 |
baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName()) |
| 643 |
|
| 644 |
params := url.Values{} |
| 645 |
params.Add("$alt", "json;enum-encoding=int") |
| 646 |
if req.GetFilter() != "" { |
| 647 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 648 |
} |
| 649 |
if req.GetPageSize() != 0 { |
| 650 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 651 |
} |
| 652 |
if req.GetPageToken() != "" { |
| 653 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 654 |
} |
| 655 |
|
| 656 |
baseUrl.RawQuery = params.Encode() |
| 657 |
|
| 658 |
// Build HTTP headers from client and context metadata. |
| 659 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 660 |
headers := gax.BuildHeaders(ctx, hds...) |
| 661 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 662 |
if settings.Path != "" { |
| 663 |
baseUrl.Path = settings.Path |
| 664 |
} |
| 665 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 666 |
if err != nil { |
| 667 |
return err |
| 668 |
} |
| 669 |
httpReq.Header = headers |
| 670 |
|
| 671 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") |
| 672 |
if err != nil { |
| 673 |
return err |
| 674 |
} |
| 675 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 676 |
return err |
| 677 |
} |
| 678 |
|
| 679 |
return nil |
| 680 |
}, opts...) |
| 681 |
if e != nil { |
| 682 |
return nil, "", e |
| 683 |
} |
| 684 |
it.Response = resp |
| 685 |
return resp.GetLocations(), resp.GetNextPageToken(), nil |
| 686 |
} |
| 687 |
|
| 688 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 689 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 690 |
if err != nil { |
| 691 |
return "", err |
| 692 |
} |
| 693 |
it.items = append(it.items, items...) |
| 694 |
return nextPageToken, nil |
| 695 |
} |
| 696 |
|
| 697 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 698 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 699 |
it.pageInfo.Token = req.GetPageToken() |
| 700 |
|
| 701 |
return it |
| 702 |
} |
| 703 |
|
| 704 |
// CancelOperation is a utility method from google.longrunning.Operations. |
| 705 |
func (c *apiHubCurateRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 706 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 707 |
jsonReq, err := m.Marshal(req) |
| 708 |
if err != nil { |
| 709 |
return err |
| 710 |
} |
| 711 |
|
| 712 |
baseUrl, err := url.Parse(c.endpoint) |
| 713 |
if err != nil { |
| 714 |
return err |
| 715 |
} |
| 716 |
baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName()) |
| 717 |
|
| 718 |
params := url.Values{} |
| 719 |
params.Add("$alt", "json;enum-encoding=int") |
| 720 |
|
| 721 |
baseUrl.RawQuery = params.Encode() |
| 722 |
|
| 723 |
// Build HTTP headers from client and context metadata. |
| 724 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 725 |
|
| 726 |
hds = append(c.xGoogHeaders, hds...) |
| 727 |
hds = append(hds, "Content-Type", "application/json") |
| 728 |
headers := gax.BuildHeaders(ctx, hds...) |
| 729 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 730 |
if settings.Path != "" { |
| 731 |
baseUrl.Path = settings.Path |
| 732 |
} |
| 733 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 734 |
if err != nil { |
| 735 |
return err |
| 736 |
} |
| 737 |
httpReq = httpReq.WithContext(ctx) |
| 738 |
httpReq.Header = headers |
| 739 |
|
| 740 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation") |
| 741 |
return err |
| 742 |
}, opts...) |
| 743 |
} |
| 744 |
|
| 745 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 746 |
func (c *apiHubCurateRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 747 |
baseUrl, err := url.Parse(c.endpoint) |
| 748 |
if err != nil { |
| 749 |
return err |
| 750 |
} |
| 751 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 752 |
|
| 753 |
params := url.Values{} |
| 754 |
params.Add("$alt", "json;enum-encoding=int") |
| 755 |
|
| 756 |
baseUrl.RawQuery = params.Encode() |
| 757 |
|
| 758 |
// Build HTTP headers from client and context metadata. |
| 759 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 760 |
|
| 761 |
hds = append(c.xGoogHeaders, hds...) |
| 762 |
hds = append(hds, "Content-Type", "application/json") |
| 763 |
headers := gax.BuildHeaders(ctx, hds...) |
| 764 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 765 |
if settings.Path != "" { |
| 766 |
baseUrl.Path = settings.Path |
| 767 |
} |
| 768 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 769 |
if err != nil { |
| 770 |
return err |
| 771 |
} |
| 772 |
httpReq = httpReq.WithContext(ctx) |
| 773 |
httpReq.Header = headers |
| 774 |
|
| 775 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") |
| 776 |
return err |
| 777 |
}, opts...) |
| 778 |
} |
| 779 |
|
| 780 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 781 |
func (c *apiHubCurateRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 782 |
baseUrl, err := url.Parse(c.endpoint) |
| 783 |
if err != nil { |
| 784 |
return nil, err |
| 785 |
} |
| 786 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 787 |
|
| 788 |
params := url.Values{} |
| 789 |
params.Add("$alt", "json;enum-encoding=int") |
| 790 |
|
| 791 |
baseUrl.RawQuery = params.Encode() |
| 792 |
|
| 793 |
// Build HTTP headers from client and context metadata. |
| 794 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 795 |
|
| 796 |
hds = append(c.xGoogHeaders, hds...) |
| 797 |
hds = append(hds, "Content-Type", "application/json") |
| 798 |
headers := gax.BuildHeaders(ctx, hds...) |
| 799 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 800 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 801 |
resp := &longrunningpb.Operation{} |
| 802 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 803 |
if settings.Path != "" { |
| 804 |
baseUrl.Path = settings.Path |
| 805 |
} |
| 806 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 807 |
if err != nil { |
| 808 |
return err |
| 809 |
} |
| 810 |
httpReq = httpReq.WithContext(ctx) |
| 811 |
httpReq.Header = headers |
| 812 |
|
| 813 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") |
| 814 |
if err != nil { |
| 815 |
return err |
| 816 |
} |
| 817 |
|
| 818 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 819 |
return err |
| 820 |
} |
| 821 |
|
| 822 |
return nil |
| 823 |
}, opts...) |
| 824 |
if e != nil { |
| 825 |
return nil, e |
| 826 |
} |
| 827 |
return resp, nil |
| 828 |
} |
| 829 |
|
| 830 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 831 |
func (c *apiHubCurateRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 832 |
it := &OperationIterator{} |
| 833 |
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| 834 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 835 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| 836 |
resp := &longrunningpb.ListOperationsResponse{} |
| 837 |
if pageToken != "" { |
| 838 |
req.PageToken = pageToken |
| 839 |
} |
| 840 |
if pageSize > math.MaxInt32 { |
| 841 |
req.PageSize = math.MaxInt32 |
| 842 |
} else if pageSize != 0 { |
| 843 |
req.PageSize = int32(pageSize) |
| 844 |
} |
| 845 |
baseUrl, err := url.Parse(c.endpoint) |
| 846 |
if err != nil { |
| 847 |
return nil, "", err |
| 848 |
} |
| 849 |
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName()) |
| 850 |
|
| 851 |
params := url.Values{} |
| 852 |
params.Add("$alt", "json;enum-encoding=int") |
| 853 |
if req.GetFilter() != "" { |
| 854 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 855 |
} |
| 856 |
if req.GetPageSize() != 0 { |
| 857 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 858 |
} |
| 859 |
if req.GetPageToken() != "" { |
| 860 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 861 |
} |
| 862 |
|
| 863 |
baseUrl.RawQuery = params.Encode() |
| 864 |
|
| 865 |
// Build HTTP headers from client and context metadata. |
| 866 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 867 |
headers := gax.BuildHeaders(ctx, hds...) |
| 868 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 869 |
if settings.Path != "" { |
| 870 |
baseUrl.Path = settings.Path |
| 871 |
} |
| 872 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 873 |
if err != nil { |
| 874 |
return err |
| 875 |
} |
| 876 |
httpReq.Header = headers |
| 877 |
|
| 878 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") |
| 879 |
if err != nil { |
| 880 |
return err |
| 881 |
} |
| 882 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 883 |
return err |
| 884 |
} |
| 885 |
|
| 886 |
return nil |
| 887 |
}, opts...) |
| 888 |
if e != nil { |
| 889 |
return nil, "", e |
| 890 |
} |
| 891 |
it.Response = resp |
| 892 |
return resp.GetOperations(), resp.GetNextPageToken(), nil |
| 893 |
} |
| 894 |
|
| 895 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 896 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 897 |
if err != nil { |
| 898 |
return "", err |
| 899 |
} |
| 900 |
it.items = append(it.items, items...) |
| 901 |
return nextPageToken, nil |
| 902 |
} |
| 903 |
|
| 904 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 905 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 906 |
it.pageInfo.Token = req.GetPageToken() |
| 907 |
|
| 908 |
return it |
| 909 |
} |