| 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 |
"time" |
| 28 |
|
| 29 |
apihubpb "cloud.google.com/go/apihub/apiv1/apihubpb" |
| 30 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 31 |
gax "github.com/googleapis/gax-go/v2" |
| 32 |
"google.golang.org/api/iterator" |
| 33 |
"google.golang.org/api/option" |
| 34 |
"google.golang.org/api/option/internaloption" |
| 35 |
httptransport "google.golang.org/api/transport/http" |
| 36 |
locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| 37 |
"google.golang.org/grpc" |
| 38 |
"google.golang.org/protobuf/encoding/protojson" |
| 39 |
"google.golang.org/protobuf/proto" |
| 40 |
) |
| 41 |
|
| 42 |
var newClientHook clientHook |
| 43 |
|
| 44 |
// CallOptions contains the retry settings for each method of Client. |
| 45 |
type CallOptions struct { |
| 46 |
CreateApi []gax.CallOption |
| 47 |
GetApi []gax.CallOption |
| 48 |
ListApis []gax.CallOption |
| 49 |
UpdateApi []gax.CallOption |
| 50 |
DeleteApi []gax.CallOption |
| 51 |
CreateVersion []gax.CallOption |
| 52 |
GetVersion []gax.CallOption |
| 53 |
ListVersions []gax.CallOption |
| 54 |
UpdateVersion []gax.CallOption |
| 55 |
DeleteVersion []gax.CallOption |
| 56 |
CreateSpec []gax.CallOption |
| 57 |
GetSpec []gax.CallOption |
| 58 |
GetSpecContents []gax.CallOption |
| 59 |
ListSpecs []gax.CallOption |
| 60 |
UpdateSpec []gax.CallOption |
| 61 |
DeleteSpec []gax.CallOption |
| 62 |
CreateApiOperation []gax.CallOption |
| 63 |
GetApiOperation []gax.CallOption |
| 64 |
ListApiOperations []gax.CallOption |
| 65 |
UpdateApiOperation []gax.CallOption |
| 66 |
DeleteApiOperation []gax.CallOption |
| 67 |
GetDefinition []gax.CallOption |
| 68 |
CreateDeployment []gax.CallOption |
| 69 |
GetDeployment []gax.CallOption |
| 70 |
ListDeployments []gax.CallOption |
| 71 |
UpdateDeployment []gax.CallOption |
| 72 |
DeleteDeployment []gax.CallOption |
| 73 |
CreateAttribute []gax.CallOption |
| 74 |
GetAttribute []gax.CallOption |
| 75 |
UpdateAttribute []gax.CallOption |
| 76 |
DeleteAttribute []gax.CallOption |
| 77 |
ListAttributes []gax.CallOption |
| 78 |
SearchResources []gax.CallOption |
| 79 |
CreateExternalApi []gax.CallOption |
| 80 |
GetExternalApi []gax.CallOption |
| 81 |
UpdateExternalApi []gax.CallOption |
| 82 |
DeleteExternalApi []gax.CallOption |
| 83 |
ListExternalApis []gax.CallOption |
| 84 |
GetLocation []gax.CallOption |
| 85 |
ListLocations []gax.CallOption |
| 86 |
CancelOperation []gax.CallOption |
| 87 |
DeleteOperation []gax.CallOption |
| 88 |
GetOperation []gax.CallOption |
| 89 |
ListOperations []gax.CallOption |
| 90 |
} |
| 91 |
|
| 92 |
func defaultRESTCallOptions() *CallOptions { |
| 93 |
return &CallOptions{ |
| 94 |
CreateApi: []gax.CallOption{ |
| 95 |
gax.WithTimeout(60000 * time.Millisecond), |
| 96 |
}, |
| 97 |
GetApi: []gax.CallOption{ |
| 98 |
gax.WithTimeout(60000 * time.Millisecond), |
| 99 |
gax.WithRetry(func() gax.Retryer { |
| 100 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 101 |
Initial: 1000 * time.Millisecond, |
| 102 |
Max: 10000 * time.Millisecond, |
| 103 |
Multiplier: 1.30, |
| 104 |
}, |
| 105 |
http.StatusServiceUnavailable) |
| 106 |
}), |
| 107 |
}, |
| 108 |
ListApis: []gax.CallOption{ |
| 109 |
gax.WithTimeout(60000 * time.Millisecond), |
| 110 |
gax.WithRetry(func() gax.Retryer { |
| 111 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 112 |
Initial: 1000 * time.Millisecond, |
| 113 |
Max: 10000 * time.Millisecond, |
| 114 |
Multiplier: 1.30, |
| 115 |
}, |
| 116 |
http.StatusServiceUnavailable) |
| 117 |
}), |
| 118 |
}, |
| 119 |
UpdateApi: []gax.CallOption{ |
| 120 |
gax.WithTimeout(60000 * time.Millisecond), |
| 121 |
}, |
| 122 |
DeleteApi: []gax.CallOption{ |
| 123 |
gax.WithTimeout(300000 * time.Millisecond), |
| 124 |
}, |
| 125 |
CreateVersion: []gax.CallOption{ |
| 126 |
gax.WithTimeout(60000 * time.Millisecond), |
| 127 |
}, |
| 128 |
GetVersion: []gax.CallOption{ |
| 129 |
gax.WithTimeout(60000 * time.Millisecond), |
| 130 |
gax.WithRetry(func() gax.Retryer { |
| 131 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 132 |
Initial: 1000 * time.Millisecond, |
| 133 |
Max: 10000 * time.Millisecond, |
| 134 |
Multiplier: 1.30, |
| 135 |
}, |
| 136 |
http.StatusServiceUnavailable) |
| 137 |
}), |
| 138 |
}, |
| 139 |
ListVersions: []gax.CallOption{ |
| 140 |
gax.WithTimeout(60000 * time.Millisecond), |
| 141 |
gax.WithRetry(func() gax.Retryer { |
| 142 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 143 |
Initial: 1000 * time.Millisecond, |
| 144 |
Max: 10000 * time.Millisecond, |
| 145 |
Multiplier: 1.30, |
| 146 |
}, |
| 147 |
http.StatusServiceUnavailable) |
| 148 |
}), |
| 149 |
}, |
| 150 |
UpdateVersion: []gax.CallOption{ |
| 151 |
gax.WithTimeout(60000 * time.Millisecond), |
| 152 |
}, |
| 153 |
DeleteVersion: []gax.CallOption{ |
| 154 |
gax.WithTimeout(300000 * time.Millisecond), |
| 155 |
}, |
| 156 |
CreateSpec: []gax.CallOption{ |
| 157 |
gax.WithTimeout(60000 * time.Millisecond), |
| 158 |
}, |
| 159 |
GetSpec: []gax.CallOption{ |
| 160 |
gax.WithTimeout(60000 * time.Millisecond), |
| 161 |
gax.WithRetry(func() gax.Retryer { |
| 162 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 163 |
Initial: 1000 * time.Millisecond, |
| 164 |
Max: 10000 * time.Millisecond, |
| 165 |
Multiplier: 1.30, |
| 166 |
}, |
| 167 |
http.StatusServiceUnavailable) |
| 168 |
}), |
| 169 |
}, |
| 170 |
GetSpecContents: []gax.CallOption{ |
| 171 |
gax.WithTimeout(60000 * time.Millisecond), |
| 172 |
gax.WithRetry(func() gax.Retryer { |
| 173 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 174 |
Initial: 1000 * time.Millisecond, |
| 175 |
Max: 10000 * time.Millisecond, |
| 176 |
Multiplier: 1.30, |
| 177 |
}, |
| 178 |
http.StatusServiceUnavailable) |
| 179 |
}), |
| 180 |
}, |
| 181 |
ListSpecs: []gax.CallOption{ |
| 182 |
gax.WithTimeout(60000 * time.Millisecond), |
| 183 |
gax.WithRetry(func() gax.Retryer { |
| 184 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 185 |
Initial: 1000 * time.Millisecond, |
| 186 |
Max: 10000 * time.Millisecond, |
| 187 |
Multiplier: 1.30, |
| 188 |
}, |
| 189 |
http.StatusServiceUnavailable) |
| 190 |
}), |
| 191 |
}, |
| 192 |
UpdateSpec: []gax.CallOption{ |
| 193 |
gax.WithTimeout(60000 * time.Millisecond), |
| 194 |
}, |
| 195 |
DeleteSpec: []gax.CallOption{ |
| 196 |
gax.WithTimeout(300000 * time.Millisecond), |
| 197 |
}, |
| 198 |
CreateApiOperation: []gax.CallOption{}, |
| 199 |
GetApiOperation: []gax.CallOption{ |
| 200 |
gax.WithTimeout(60000 * time.Millisecond), |
| 201 |
gax.WithRetry(func() gax.Retryer { |
| 202 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 203 |
Initial: 1000 * time.Millisecond, |
| 204 |
Max: 10000 * time.Millisecond, |
| 205 |
Multiplier: 1.30, |
| 206 |
}, |
| 207 |
http.StatusServiceUnavailable) |
| 208 |
}), |
| 209 |
}, |
| 210 |
ListApiOperations: []gax.CallOption{ |
| 211 |
gax.WithTimeout(60000 * time.Millisecond), |
| 212 |
gax.WithRetry(func() gax.Retryer { |
| 213 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 214 |
Initial: 1000 * time.Millisecond, |
| 215 |
Max: 10000 * time.Millisecond, |
| 216 |
Multiplier: 1.30, |
| 217 |
}, |
| 218 |
http.StatusServiceUnavailable) |
| 219 |
}), |
| 220 |
}, |
| 221 |
UpdateApiOperation: []gax.CallOption{}, |
| 222 |
DeleteApiOperation: []gax.CallOption{}, |
| 223 |
GetDefinition: []gax.CallOption{ |
| 224 |
gax.WithTimeout(60000 * time.Millisecond), |
| 225 |
gax.WithRetry(func() gax.Retryer { |
| 226 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 227 |
Initial: 1000 * time.Millisecond, |
| 228 |
Max: 10000 * time.Millisecond, |
| 229 |
Multiplier: 1.30, |
| 230 |
}, |
| 231 |
http.StatusServiceUnavailable) |
| 232 |
}), |
| 233 |
}, |
| 234 |
CreateDeployment: []gax.CallOption{ |
| 235 |
gax.WithTimeout(60000 * time.Millisecond), |
| 236 |
}, |
| 237 |
GetDeployment: []gax.CallOption{ |
| 238 |
gax.WithTimeout(60000 * time.Millisecond), |
| 239 |
gax.WithRetry(func() gax.Retryer { |
| 240 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 241 |
Initial: 1000 * time.Millisecond, |
| 242 |
Max: 10000 * time.Millisecond, |
| 243 |
Multiplier: 1.30, |
| 244 |
}, |
| 245 |
http.StatusServiceUnavailable) |
| 246 |
}), |
| 247 |
}, |
| 248 |
ListDeployments: []gax.CallOption{ |
| 249 |
gax.WithTimeout(60000 * time.Millisecond), |
| 250 |
gax.WithRetry(func() gax.Retryer { |
| 251 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 252 |
Initial: 1000 * time.Millisecond, |
| 253 |
Max: 10000 * time.Millisecond, |
| 254 |
Multiplier: 1.30, |
| 255 |
}, |
| 256 |
http.StatusServiceUnavailable) |
| 257 |
}), |
| 258 |
}, |
| 259 |
UpdateDeployment: []gax.CallOption{ |
| 260 |
gax.WithTimeout(60000 * time.Millisecond), |
| 261 |
}, |
| 262 |
DeleteDeployment: []gax.CallOption{ |
| 263 |
gax.WithTimeout(60000 * time.Millisecond), |
| 264 |
}, |
| 265 |
CreateAttribute: []gax.CallOption{ |
| 266 |
gax.WithTimeout(60000 * time.Millisecond), |
| 267 |
}, |
| 268 |
GetAttribute: []gax.CallOption{ |
| 269 |
gax.WithTimeout(60000 * time.Millisecond), |
| 270 |
gax.WithRetry(func() gax.Retryer { |
| 271 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 272 |
Initial: 1000 * time.Millisecond, |
| 273 |
Max: 10000 * time.Millisecond, |
| 274 |
Multiplier: 1.30, |
| 275 |
}, |
| 276 |
http.StatusServiceUnavailable) |
| 277 |
}), |
| 278 |
}, |
| 279 |
UpdateAttribute: []gax.CallOption{ |
| 280 |
gax.WithTimeout(60000 * time.Millisecond), |
| 281 |
}, |
| 282 |
DeleteAttribute: []gax.CallOption{ |
| 283 |
gax.WithTimeout(60000 * time.Millisecond), |
| 284 |
}, |
| 285 |
ListAttributes: []gax.CallOption{ |
| 286 |
gax.WithTimeout(60000 * time.Millisecond), |
| 287 |
gax.WithRetry(func() gax.Retryer { |
| 288 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 289 |
Initial: 1000 * time.Millisecond, |
| 290 |
Max: 10000 * time.Millisecond, |
| 291 |
Multiplier: 1.30, |
| 292 |
}, |
| 293 |
http.StatusServiceUnavailable) |
| 294 |
}), |
| 295 |
}, |
| 296 |
SearchResources: []gax.CallOption{ |
| 297 |
gax.WithTimeout(60000 * time.Millisecond), |
| 298 |
gax.WithRetry(func() gax.Retryer { |
| 299 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 300 |
Initial: 1000 * time.Millisecond, |
| 301 |
Max: 10000 * time.Millisecond, |
| 302 |
Multiplier: 1.30, |
| 303 |
}, |
| 304 |
http.StatusServiceUnavailable) |
| 305 |
}), |
| 306 |
}, |
| 307 |
CreateExternalApi: []gax.CallOption{ |
| 308 |
gax.WithTimeout(60000 * time.Millisecond), |
| 309 |
}, |
| 310 |
GetExternalApi: []gax.CallOption{ |
| 311 |
gax.WithTimeout(60000 * time.Millisecond), |
| 312 |
gax.WithRetry(func() gax.Retryer { |
| 313 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 314 |
Initial: 1000 * time.Millisecond, |
| 315 |
Max: 10000 * time.Millisecond, |
| 316 |
Multiplier: 1.30, |
| 317 |
}, |
| 318 |
http.StatusServiceUnavailable) |
| 319 |
}), |
| 320 |
}, |
| 321 |
UpdateExternalApi: []gax.CallOption{ |
| 322 |
gax.WithTimeout(60000 * time.Millisecond), |
| 323 |
}, |
| 324 |
DeleteExternalApi: []gax.CallOption{ |
| 325 |
gax.WithTimeout(60000 * time.Millisecond), |
| 326 |
}, |
| 327 |
ListExternalApis: []gax.CallOption{ |
| 328 |
gax.WithTimeout(60000 * time.Millisecond), |
| 329 |
gax.WithRetry(func() gax.Retryer { |
| 330 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 331 |
Initial: 1000 * time.Millisecond, |
| 332 |
Max: 10000 * time.Millisecond, |
| 333 |
Multiplier: 1.30, |
| 334 |
}, |
| 335 |
http.StatusServiceUnavailable) |
| 336 |
}), |
| 337 |
}, |
| 338 |
GetLocation: []gax.CallOption{}, |
| 339 |
ListLocations: []gax.CallOption{}, |
| 340 |
CancelOperation: []gax.CallOption{}, |
| 341 |
DeleteOperation: []gax.CallOption{}, |
| 342 |
GetOperation: []gax.CallOption{}, |
| 343 |
ListOperations: []gax.CallOption{}, |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
// internalClient is an interface that defines the methods available from API hub API. |
| 348 |
type internalClient interface { |
| 349 |
Close() error |
| 350 |
setGoogleClientInfo(...string) |
| 351 |
Connection() *grpc.ClientConn |
| 352 |
CreateApi(context.Context, *apihubpb.CreateApiRequest, ...gax.CallOption) (*apihubpb.Api, error) |
| 353 |
GetApi(context.Context, *apihubpb.GetApiRequest, ...gax.CallOption) (*apihubpb.Api, error) |
| 354 |
ListApis(context.Context, *apihubpb.ListApisRequest, ...gax.CallOption) *ApiIterator |
| 355 |
UpdateApi(context.Context, *apihubpb.UpdateApiRequest, ...gax.CallOption) (*apihubpb.Api, error) |
| 356 |
DeleteApi(context.Context, *apihubpb.DeleteApiRequest, ...gax.CallOption) error |
| 357 |
CreateVersion(context.Context, *apihubpb.CreateVersionRequest, ...gax.CallOption) (*apihubpb.Version, error) |
| 358 |
GetVersion(context.Context, *apihubpb.GetVersionRequest, ...gax.CallOption) (*apihubpb.Version, error) |
| 359 |
ListVersions(context.Context, *apihubpb.ListVersionsRequest, ...gax.CallOption) *VersionIterator |
| 360 |
UpdateVersion(context.Context, *apihubpb.UpdateVersionRequest, ...gax.CallOption) (*apihubpb.Version, error) |
| 361 |
DeleteVersion(context.Context, *apihubpb.DeleteVersionRequest, ...gax.CallOption) error |
| 362 |
CreateSpec(context.Context, *apihubpb.CreateSpecRequest, ...gax.CallOption) (*apihubpb.Spec, error) |
| 363 |
GetSpec(context.Context, *apihubpb.GetSpecRequest, ...gax.CallOption) (*apihubpb.Spec, error) |
| 364 |
GetSpecContents(context.Context, *apihubpb.GetSpecContentsRequest, ...gax.CallOption) (*apihubpb.SpecContents, error) |
| 365 |
ListSpecs(context.Context, *apihubpb.ListSpecsRequest, ...gax.CallOption) *SpecIterator |
| 366 |
UpdateSpec(context.Context, *apihubpb.UpdateSpecRequest, ...gax.CallOption) (*apihubpb.Spec, error) |
| 367 |
DeleteSpec(context.Context, *apihubpb.DeleteSpecRequest, ...gax.CallOption) error |
| 368 |
CreateApiOperation(context.Context, *apihubpb.CreateApiOperationRequest, ...gax.CallOption) (*apihubpb.ApiOperation, error) |
| 369 |
GetApiOperation(context.Context, *apihubpb.GetApiOperationRequest, ...gax.CallOption) (*apihubpb.ApiOperation, error) |
| 370 |
ListApiOperations(context.Context, *apihubpb.ListApiOperationsRequest, ...gax.CallOption) *ApiOperationIterator |
| 371 |
UpdateApiOperation(context.Context, *apihubpb.UpdateApiOperationRequest, ...gax.CallOption) (*apihubpb.ApiOperation, error) |
| 372 |
DeleteApiOperation(context.Context, *apihubpb.DeleteApiOperationRequest, ...gax.CallOption) error |
| 373 |
GetDefinition(context.Context, *apihubpb.GetDefinitionRequest, ...gax.CallOption) (*apihubpb.Definition, error) |
| 374 |
CreateDeployment(context.Context, *apihubpb.CreateDeploymentRequest, ...gax.CallOption) (*apihubpb.Deployment, error) |
| 375 |
GetDeployment(context.Context, *apihubpb.GetDeploymentRequest, ...gax.CallOption) (*apihubpb.Deployment, error) |
| 376 |
ListDeployments(context.Context, *apihubpb.ListDeploymentsRequest, ...gax.CallOption) *DeploymentIterator |
| 377 |
UpdateDeployment(context.Context, *apihubpb.UpdateDeploymentRequest, ...gax.CallOption) (*apihubpb.Deployment, error) |
| 378 |
DeleteDeployment(context.Context, *apihubpb.DeleteDeploymentRequest, ...gax.CallOption) error |
| 379 |
CreateAttribute(context.Context, *apihubpb.CreateAttributeRequest, ...gax.CallOption) (*apihubpb.Attribute, error) |
| 380 |
GetAttribute(context.Context, *apihubpb.GetAttributeRequest, ...gax.CallOption) (*apihubpb.Attribute, error) |
| 381 |
UpdateAttribute(context.Context, *apihubpb.UpdateAttributeRequest, ...gax.CallOption) (*apihubpb.Attribute, error) |
| 382 |
DeleteAttribute(context.Context, *apihubpb.DeleteAttributeRequest, ...gax.CallOption) error |
| 383 |
ListAttributes(context.Context, *apihubpb.ListAttributesRequest, ...gax.CallOption) *AttributeIterator |
| 384 |
SearchResources(context.Context, *apihubpb.SearchResourcesRequest, ...gax.CallOption) *SearchResultIterator |
| 385 |
CreateExternalApi(context.Context, *apihubpb.CreateExternalApiRequest, ...gax.CallOption) (*apihubpb.ExternalApi, error) |
| 386 |
GetExternalApi(context.Context, *apihubpb.GetExternalApiRequest, ...gax.CallOption) (*apihubpb.ExternalApi, error) |
| 387 |
UpdateExternalApi(context.Context, *apihubpb.UpdateExternalApiRequest, ...gax.CallOption) (*apihubpb.ExternalApi, error) |
| 388 |
DeleteExternalApi(context.Context, *apihubpb.DeleteExternalApiRequest, ...gax.CallOption) error |
| 389 |
ListExternalApis(context.Context, *apihubpb.ListExternalApisRequest, ...gax.CallOption) *ExternalApiIterator |
| 390 |
GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) |
| 391 |
ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator |
| 392 |
CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error |
| 393 |
DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error |
| 394 |
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) |
| 395 |
ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator |
| 396 |
} |
| 397 |
|
| 398 |
// Client is a client for interacting with API hub API. |
| 399 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 400 |
// |
| 401 |
// This service provides all methods related to the API hub. |
| 402 |
type Client struct { |
| 403 |
// The internal transport-dependent client. |
| 404 |
internalClient internalClient |
| 405 |
|
| 406 |
// The call options for this service. |
| 407 |
CallOptions *CallOptions |
| 408 |
} |
| 409 |
|
| 410 |
// Wrapper methods routed to the internal client. |
| 411 |
|
| 412 |
// Close closes the connection to the API service. The user should invoke this when |
| 413 |
// the client is no longer required. |
| 414 |
func (c *Client) Close() error { |
| 415 |
return c.internalClient.Close() |
| 416 |
} |
| 417 |
|
| 418 |
// setGoogleClientInfo sets the name and version of the application in |
| 419 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 420 |
// use by Google-written clients. |
| 421 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 422 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 423 |
} |
| 424 |
|
| 425 |
// Connection returns a connection to the API service. |
| 426 |
// |
| 427 |
// Deprecated: Connections are now pooled so this method does not always |
| 428 |
// return the same resource. |
| 429 |
func (c *Client) Connection() *grpc.ClientConn { |
| 430 |
return c.internalClient.Connection() |
| 431 |
} |
| 432 |
|
| 433 |
// CreateApi create an API resource in the API hub. |
| 434 |
// Once an API resource is created, versions can be added to it. |
| 435 |
func (c *Client) CreateApi(ctx context.Context, req *apihubpb.CreateApiRequest, opts ...gax.CallOption) (*apihubpb.Api, error) { |
| 436 |
return c.internalClient.CreateApi(ctx, req, opts...) |
| 437 |
} |
| 438 |
|
| 439 |
// GetApi get API resource details including the API versions contained in it. |
| 440 |
func (c *Client) GetApi(ctx context.Context, req *apihubpb.GetApiRequest, opts ...gax.CallOption) (*apihubpb.Api, error) { |
| 441 |
return c.internalClient.GetApi(ctx, req, opts...) |
| 442 |
} |
| 443 |
|
| 444 |
// ListApis list API resources in the API hub. |
| 445 |
func (c *Client) ListApis(ctx context.Context, req *apihubpb.ListApisRequest, opts ...gax.CallOption) *ApiIterator { |
| 446 |
return c.internalClient.ListApis(ctx, req, opts...) |
| 447 |
} |
| 448 |
|
| 449 |
// UpdateApi update an API resource in the API hub. The following fields in the |
| 450 |
// API can be updated: |
| 451 |
// |
| 452 |
// display_name |
| 453 |
// |
| 454 |
// description |
| 455 |
// |
| 456 |
// owner |
| 457 |
// |
| 458 |
// documentation |
| 459 |
// |
| 460 |
// target_user |
| 461 |
// |
| 462 |
// [team][google.cloud.apihub.v1.Api.team (at http://google.cloud.apihub.v1.Api.team)] |
| 463 |
// |
| 464 |
// business_unit |
| 465 |
// |
| 466 |
// maturity_level |
| 467 |
// |
| 468 |
// api_style |
| 469 |
// |
| 470 |
// attributes |
| 471 |
// |
| 472 |
// The |
| 473 |
// update_mask |
| 474 |
// should be used to specify the fields being updated. |
| 475 |
// |
| 476 |
// Updating the owner field requires complete owner message |
| 477 |
// and updates both owner and email fields. |
| 478 |
func (c *Client) UpdateApi(ctx context.Context, req *apihubpb.UpdateApiRequest, opts ...gax.CallOption) (*apihubpb.Api, error) { |
| 479 |
return c.internalClient.UpdateApi(ctx, req, opts...) |
| 480 |
} |
| 481 |
|
| 482 |
// DeleteApi delete an API resource in the API hub. API can only be deleted if all |
| 483 |
// underlying versions are deleted. |
| 484 |
func (c *Client) DeleteApi(ctx context.Context, req *apihubpb.DeleteApiRequest, opts ...gax.CallOption) error { |
| 485 |
return c.internalClient.DeleteApi(ctx, req, opts...) |
| 486 |
} |
| 487 |
|
| 488 |
// CreateVersion create an API version for an API resource in the API hub. |
| 489 |
func (c *Client) CreateVersion(ctx context.Context, req *apihubpb.CreateVersionRequest, opts ...gax.CallOption) (*apihubpb.Version, error) { |
| 490 |
return c.internalClient.CreateVersion(ctx, req, opts...) |
| 491 |
} |
| 492 |
|
| 493 |
// GetVersion get details about the API version of an API resource. This will include |
| 494 |
// information about the specs and operations present in the API |
| 495 |
// version as well as the deployments linked to it. |
| 496 |
func (c *Client) GetVersion(ctx context.Context, req *apihubpb.GetVersionRequest, opts ...gax.CallOption) (*apihubpb.Version, error) { |
| 497 |
return c.internalClient.GetVersion(ctx, req, opts...) |
| 498 |
} |
| 499 |
|
| 500 |
// ListVersions list API versions of an API resource in the API hub. |
| 501 |
func (c *Client) ListVersions(ctx context.Context, req *apihubpb.ListVersionsRequest, opts ...gax.CallOption) *VersionIterator { |
| 502 |
return c.internalClient.ListVersions(ctx, req, opts...) |
| 503 |
} |
| 504 |
|
| 505 |
// UpdateVersion update API version. The following fields in the |
| 506 |
// version can be updated currently: |
| 507 |
// |
| 508 |
// display_name |
| 509 |
// |
| 510 |
// description |
| 511 |
// |
| 512 |
// documentation |
| 513 |
// |
| 514 |
// deployments |
| 515 |
// |
| 516 |
// lifecycle |
| 517 |
// |
| 518 |
// compliance |
| 519 |
// |
| 520 |
// accreditation |
| 521 |
// |
| 522 |
// attributes |
| 523 |
// |
| 524 |
// The |
| 525 |
// update_mask |
| 526 |
// should be used to specify the fields being updated. |
| 527 |
func (c *Client) UpdateVersion(ctx context.Context, req *apihubpb.UpdateVersionRequest, opts ...gax.CallOption) (*apihubpb.Version, error) { |
| 528 |
return c.internalClient.UpdateVersion(ctx, req, opts...) |
| 529 |
} |
| 530 |
|
| 531 |
// DeleteVersion delete an API version. Version can only be deleted if all underlying specs, |
| 532 |
// operations, definitions and linked deployments are deleted. |
| 533 |
func (c *Client) DeleteVersion(ctx context.Context, req *apihubpb.DeleteVersionRequest, opts ...gax.CallOption) error { |
| 534 |
return c.internalClient.DeleteVersion(ctx, req, opts...) |
| 535 |
} |
| 536 |
|
| 537 |
// CreateSpec add a spec to an API version in the API hub. |
| 538 |
// Multiple specs can be added to an API version. |
| 539 |
// Note, while adding a spec, at least one of contents or source_uri must |
| 540 |
// be provided. If contents is provided, then spec_type must also be |
| 541 |
// provided. |
| 542 |
// |
| 543 |
// On adding a spec with contents to the version, the operations present in it |
| 544 |
// will be added to the version.Note that the file contents in the spec should |
| 545 |
// be of the same type as defined in the |
| 546 |
// projects/{project}/locations/{location}/attributes/system-spec-type |
| 547 |
// attribute associated with spec resource. Note that specs of various types |
| 548 |
// can be uploaded, however parsing of details is supported for OpenAPI spec |
| 549 |
// currently. |
| 550 |
// |
| 551 |
// In order to access the information parsed from the spec, use the |
| 552 |
// GetSpec method. |
| 553 |
// In order to access the raw contents for a particular spec, use the |
| 554 |
// GetSpecContents method. |
| 555 |
// In order to access the operations parsed from the spec, use the |
| 556 |
// ListAPIOperations |
| 557 |
// method. |
| 558 |
func (c *Client) CreateSpec(ctx context.Context, req *apihubpb.CreateSpecRequest, opts ...gax.CallOption) (*apihubpb.Spec, error) { |
| 559 |
return c.internalClient.CreateSpec(ctx, req, opts...) |
| 560 |
} |
| 561 |
|
| 562 |
// GetSpec get details about the information parsed from a spec. |
| 563 |
// Note that this method does not return the raw spec contents. |
| 564 |
// Use GetSpecContents method |
| 565 |
// to retrieve the same. |
| 566 |
func (c *Client) GetSpec(ctx context.Context, req *apihubpb.GetSpecRequest, opts ...gax.CallOption) (*apihubpb.Spec, error) { |
| 567 |
return c.internalClient.GetSpec(ctx, req, opts...) |
| 568 |
} |
| 569 |
|
| 570 |
// GetSpecContents get spec contents. |
| 571 |
func (c *Client) GetSpecContents(ctx context.Context, req *apihubpb.GetSpecContentsRequest, opts ...gax.CallOption) (*apihubpb.SpecContents, error) { |
| 572 |
return c.internalClient.GetSpecContents(ctx, req, opts...) |
| 573 |
} |
| 574 |
|
| 575 |
// ListSpecs list specs corresponding to a particular API resource. |
| 576 |
func (c *Client) ListSpecs(ctx context.Context, req *apihubpb.ListSpecsRequest, opts ...gax.CallOption) *SpecIterator { |
| 577 |
return c.internalClient.ListSpecs(ctx, req, opts...) |
| 578 |
} |
| 579 |
|
| 580 |
// UpdateSpec update spec. The following fields in the |
| 581 |
// spec can be updated: |
| 582 |
// |
| 583 |
// display_name |
| 584 |
// |
| 585 |
// source_uri |
| 586 |
// |
| 587 |
// lint_response |
| 588 |
// |
| 589 |
// attributes |
| 590 |
// |
| 591 |
// contents |
| 592 |
// |
| 593 |
// spec_type |
| 594 |
// |
| 595 |
// In case of an OAS spec, updating spec contents can lead to: |
| 596 |
// |
| 597 |
// Creation, deletion and update of operations. |
| 598 |
// |
| 599 |
// Creation, deletion and update of definitions. |
| 600 |
// |
| 601 |
// Update of other info parsed out from the new spec. |
| 602 |
// |
| 603 |
// In case of contents or source_uri being present in update mask, spec_type |
| 604 |
// must also be present. Also, spec_type can not be present in update mask if |
| 605 |
// contents or source_uri is not present. |
| 606 |
// |
| 607 |
// The |
| 608 |
// update_mask |
| 609 |
// should be used to specify the fields being updated. |
| 610 |
func (c *Client) UpdateSpec(ctx context.Context, req *apihubpb.UpdateSpecRequest, opts ...gax.CallOption) (*apihubpb.Spec, error) { |
| 611 |
return c.internalClient.UpdateSpec(ctx, req, opts...) |
| 612 |
} |
| 613 |
|
| 614 |
// DeleteSpec delete a spec. |
| 615 |
// Deleting a spec will also delete the associated operations from the |
| 616 |
// version. |
| 617 |
func (c *Client) DeleteSpec(ctx context.Context, req *apihubpb.DeleteSpecRequest, opts ...gax.CallOption) error { |
| 618 |
return c.internalClient.DeleteSpec(ctx, req, opts...) |
| 619 |
} |
| 620 |
|
| 621 |
// CreateApiOperation create an apiOperation in an API version. |
| 622 |
// An apiOperation can be created only if the version has no apiOperations |
| 623 |
// which were created by parsing a spec. |
| 624 |
func (c *Client) CreateApiOperation(ctx context.Context, req *apihubpb.CreateApiOperationRequest, opts ...gax.CallOption) (*apihubpb.ApiOperation, error) { |
| 625 |
return c.internalClient.CreateApiOperation(ctx, req, opts...) |
| 626 |
} |
| 627 |
|
| 628 |
// GetApiOperation get details about a particular operation in API version. |
| 629 |
func (c *Client) GetApiOperation(ctx context.Context, req *apihubpb.GetApiOperationRequest, opts ...gax.CallOption) (*apihubpb.ApiOperation, error) { |
| 630 |
return c.internalClient.GetApiOperation(ctx, req, opts...) |
| 631 |
} |
| 632 |
|
| 633 |
// ListApiOperations list operations in an API version. |
| 634 |
func (c *Client) ListApiOperations(ctx context.Context, req *apihubpb.ListApiOperationsRequest, opts ...gax.CallOption) *ApiOperationIterator { |
| 635 |
return c.internalClient.ListApiOperations(ctx, req, opts...) |
| 636 |
} |
| 637 |
|
| 638 |
// UpdateApiOperation update an operation in an API version. The following fields in the |
| 639 |
// [ApiOperation resource][google.cloud.apihub.v1.ApiOperation] can be |
| 640 |
// updated: |
| 641 |
// |
| 642 |
// details.description |
| 643 |
// |
| 644 |
// details.documentation |
| 645 |
// |
| 646 |
// details.http_operation.path |
| 647 |
// |
| 648 |
// details.http_operation.method |
| 649 |
// |
| 650 |
// details.deprecated |
| 651 |
// |
| 652 |
// attributes |
| 653 |
// |
| 654 |
// The |
| 655 |
// update_mask |
| 656 |
// should be used to specify the fields being updated. |
| 657 |
// |
| 658 |
// An operation can be updated only if the operation was created via |
| 659 |
// CreateApiOperation API. |
| 660 |
// If the operation was created by parsing the spec, then it can be edited by |
| 661 |
// updating the spec. |
| 662 |
func (c *Client) UpdateApiOperation(ctx context.Context, req *apihubpb.UpdateApiOperationRequest, opts ...gax.CallOption) (*apihubpb.ApiOperation, error) { |
| 663 |
return c.internalClient.UpdateApiOperation(ctx, req, opts...) |
| 664 |
} |
| 665 |
|
| 666 |
// DeleteApiOperation delete an operation in an API version and we can delete only the |
| 667 |
// operations created via create API. If the operation was created by parsing |
| 668 |
// the spec, then it can be deleted by editing or deleting the spec. |
| 669 |
func (c *Client) DeleteApiOperation(ctx context.Context, req *apihubpb.DeleteApiOperationRequest, opts ...gax.CallOption) error { |
| 670 |
return c.internalClient.DeleteApiOperation(ctx, req, opts...) |
| 671 |
} |
| 672 |
|
| 673 |
// GetDefinition get details about a definition in an API version. |
| 674 |
func (c *Client) GetDefinition(ctx context.Context, req *apihubpb.GetDefinitionRequest, opts ...gax.CallOption) (*apihubpb.Definition, error) { |
| 675 |
return c.internalClient.GetDefinition(ctx, req, opts...) |
| 676 |
} |
| 677 |
|
| 678 |
// CreateDeployment create a deployment resource in the API hub. |
| 679 |
// Once a deployment resource is created, it can be associated with API |
| 680 |
// versions. |
| 681 |
func (c *Client) CreateDeployment(ctx context.Context, req *apihubpb.CreateDeploymentRequest, opts ...gax.CallOption) (*apihubpb.Deployment, error) { |
| 682 |
return c.internalClient.CreateDeployment(ctx, req, opts...) |
| 683 |
} |
| 684 |
|
| 685 |
// GetDeployment get details about a deployment and the API versions linked to it. |
| 686 |
func (c *Client) GetDeployment(ctx context.Context, req *apihubpb.GetDeploymentRequest, opts ...gax.CallOption) (*apihubpb.Deployment, error) { |
| 687 |
return c.internalClient.GetDeployment(ctx, req, opts...) |
| 688 |
} |
| 689 |
|
| 690 |
// ListDeployments list deployment resources in the API hub. |
| 691 |
func (c *Client) ListDeployments(ctx context.Context, req *apihubpb.ListDeploymentsRequest, opts ...gax.CallOption) *DeploymentIterator { |
| 692 |
return c.internalClient.ListDeployments(ctx, req, opts...) |
| 693 |
} |
| 694 |
|
| 695 |
// UpdateDeployment update a deployment resource in the API hub. The following fields in the |
| 696 |
// [deployment resource][google.cloud.apihub.v1.Deployment] can be |
| 697 |
// updated: |
| 698 |
// |
| 699 |
// display_name |
| 700 |
// |
| 701 |
// description |
| 702 |
// |
| 703 |
// documentation |
| 704 |
// |
| 705 |
// deployment_type |
| 706 |
// |
| 707 |
// resource_uri |
| 708 |
// |
| 709 |
// endpoints |
| 710 |
// |
| 711 |
// slo |
| 712 |
// |
| 713 |
// environment |
| 714 |
// |
| 715 |
// attributes |
| 716 |
// |
| 717 |
// [source_project] [google.cloud.apihub.v1.Deployment.source_project] |
| 718 |
// |
| 719 |
// [source_environment] |
| 720 |
// [google.cloud.apihub.v1.Deployment.source_environment] |
| 721 |
// |
| 722 |
// management_url |
| 723 |
// |
| 724 |
// source_uri |
| 725 |
// The |
| 726 |
// update_mask |
| 727 |
// should be used to specify the fields being updated. |
| 728 |
func (c *Client) UpdateDeployment(ctx context.Context, req *apihubpb.UpdateDeploymentRequest, opts ...gax.CallOption) (*apihubpb.Deployment, error) { |
| 729 |
return c.internalClient.UpdateDeployment(ctx, req, opts...) |
| 730 |
} |
| 731 |
|
| 732 |
// DeleteDeployment delete a deployment resource in the API hub. |
| 733 |
func (c *Client) DeleteDeployment(ctx context.Context, req *apihubpb.DeleteDeploymentRequest, opts ...gax.CallOption) error { |
| 734 |
return c.internalClient.DeleteDeployment(ctx, req, opts...) |
| 735 |
} |
| 736 |
|
| 737 |
// CreateAttribute create a user defined attribute. |
| 738 |
// |
| 739 |
// Certain pre defined attributes are already created by the API hub. These |
| 740 |
// attributes will have type as SYSTEM_DEFINED and can be listed via |
| 741 |
// ListAttributes method. |
| 742 |
// Allowed values for the same can be updated via |
| 743 |
// UpdateAttribute method. |
| 744 |
func (c *Client) CreateAttribute(ctx context.Context, req *apihubpb.CreateAttributeRequest, opts ...gax.CallOption) (*apihubpb.Attribute, error) { |
| 745 |
return c.internalClient.CreateAttribute(ctx, req, opts...) |
| 746 |
} |
| 747 |
|
| 748 |
// GetAttribute get details about the attribute. |
| 749 |
func (c *Client) GetAttribute(ctx context.Context, req *apihubpb.GetAttributeRequest, opts ...gax.CallOption) (*apihubpb.Attribute, error) { |
| 750 |
return c.internalClient.GetAttribute(ctx, req, opts...) |
| 751 |
} |
| 752 |
|
| 753 |
// UpdateAttribute update the attribute. The following fields in the |
| 754 |
// [Attribute resource][google.cloud.apihub.v1.Attribute] can be updated: |
| 755 |
// |
| 756 |
// display_name |
| 757 |
// The display name can be updated for user defined attributes only. |
| 758 |
// |
| 759 |
// description |
| 760 |
// The description can be updated for user defined attributes only. |
| 761 |
// |
| 762 |
// allowed_values |
| 763 |
// To update the list of allowed values, clients need to use the fetched list |
| 764 |
// of allowed values and add or remove values to or from the same list. |
| 765 |
// The mutable allowed values can be updated for both user defined and System |
| 766 |
// defined attributes. The immutable allowed values cannot be updated or |
| 767 |
// deleted. The updated list of allowed values cannot be empty. If an allowed |
| 768 |
// value that is already used by some resource’s attribute is deleted, then |
| 769 |
// the association between the resource and the attribute value will also be |
| 770 |
// deleted. |
| 771 |
// |
| 772 |
// cardinality |
| 773 |
// The cardinality can be updated for user defined attributes only. |
| 774 |
// Cardinality can only be increased during an update. |
| 775 |
// |
| 776 |
// The |
| 777 |
// update_mask |
| 778 |
// should be used to specify the fields being updated. |
| 779 |
func (c *Client) UpdateAttribute(ctx context.Context, req *apihubpb.UpdateAttributeRequest, opts ...gax.CallOption) (*apihubpb.Attribute, error) { |
| 780 |
return c.internalClient.UpdateAttribute(ctx, req, opts...) |
| 781 |
} |
| 782 |
|
| 783 |
// DeleteAttribute delete an attribute. |
| 784 |
// |
| 785 |
// Note: System defined attributes cannot be deleted. All |
| 786 |
// associations of the attribute being deleted with any API hub resource will |
| 787 |
// also get deleted. |
| 788 |
func (c *Client) DeleteAttribute(ctx context.Context, req *apihubpb.DeleteAttributeRequest, opts ...gax.CallOption) error { |
| 789 |
return c.internalClient.DeleteAttribute(ctx, req, opts...) |
| 790 |
} |
| 791 |
|
| 792 |
// ListAttributes list all attributes. |
| 793 |
func (c *Client) ListAttributes(ctx context.Context, req *apihubpb.ListAttributesRequest, opts ...gax.CallOption) *AttributeIterator { |
| 794 |
return c.internalClient.ListAttributes(ctx, req, opts...) |
| 795 |
} |
| 796 |
|
| 797 |
// SearchResources search across API-Hub resources. |
| 798 |
func (c *Client) SearchResources(ctx context.Context, req *apihubpb.SearchResourcesRequest, opts ...gax.CallOption) *SearchResultIterator { |
| 799 |
return c.internalClient.SearchResources(ctx, req, opts...) |
| 800 |
} |
| 801 |
|
| 802 |
// CreateExternalApi create an External API resource in the API hub. |
| 803 |
func (c *Client) CreateExternalApi(ctx context.Context, req *apihubpb.CreateExternalApiRequest, opts ...gax.CallOption) (*apihubpb.ExternalApi, error) { |
| 804 |
return c.internalClient.CreateExternalApi(ctx, req, opts...) |
| 805 |
} |
| 806 |
|
| 807 |
// GetExternalApi get details about an External API resource in the API hub. |
| 808 |
func (c *Client) GetExternalApi(ctx context.Context, req *apihubpb.GetExternalApiRequest, opts ...gax.CallOption) (*apihubpb.ExternalApi, error) { |
| 809 |
return c.internalClient.GetExternalApi(ctx, req, opts...) |
| 810 |
} |
| 811 |
|
| 812 |
// UpdateExternalApi update an External API resource in the API hub. The following fields can be |
| 813 |
// updated: |
| 814 |
// |
| 815 |
// display_name |
| 816 |
// |
| 817 |
// description |
| 818 |
// |
| 819 |
// documentation |
| 820 |
// |
| 821 |
// endpoints |
| 822 |
// |
| 823 |
// paths |
| 824 |
// |
| 825 |
// The |
| 826 |
// update_mask |
| 827 |
// should be used to specify the fields being updated. |
| 828 |
func (c *Client) UpdateExternalApi(ctx context.Context, req *apihubpb.UpdateExternalApiRequest, opts ...gax.CallOption) (*apihubpb.ExternalApi, error) { |
| 829 |
return c.internalClient.UpdateExternalApi(ctx, req, opts...) |
| 830 |
} |
| 831 |
|
| 832 |
// DeleteExternalApi delete an External API resource in the API hub. |
| 833 |
func (c *Client) DeleteExternalApi(ctx context.Context, req *apihubpb.DeleteExternalApiRequest, opts ...gax.CallOption) error { |
| 834 |
return c.internalClient.DeleteExternalApi(ctx, req, opts...) |
| 835 |
} |
| 836 |
|
| 837 |
// ListExternalApis list External API resources in the API hub. |
| 838 |
func (c *Client) ListExternalApis(ctx context.Context, req *apihubpb.ListExternalApisRequest, opts ...gax.CallOption) *ExternalApiIterator { |
| 839 |
return c.internalClient.ListExternalApis(ctx, req, opts...) |
| 840 |
} |
| 841 |
|
| 842 |
// GetLocation gets information about a location. |
| 843 |
func (c *Client) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 844 |
return c.internalClient.GetLocation(ctx, req, opts...) |
| 845 |
} |
| 846 |
|
| 847 |
// ListLocations lists information about the supported locations for this service. |
| 848 |
func (c *Client) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 849 |
return c.internalClient.ListLocations(ctx, req, opts...) |
| 850 |
} |
| 851 |
|
| 852 |
// CancelOperation is a utility method from google.longrunning.Operations. |
| 853 |
func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 854 |
return c.internalClient.CancelOperation(ctx, req, opts...) |
| 855 |
} |
| 856 |
|
| 857 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 858 |
func (c *Client) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 859 |
return c.internalClient.DeleteOperation(ctx, req, opts...) |
| 860 |
} |
| 861 |
|
| 862 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 863 |
func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 864 |
return c.internalClient.GetOperation(ctx, req, opts...) |
| 865 |
} |
| 866 |
|
| 867 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 868 |
func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 869 |
return c.internalClient.ListOperations(ctx, req, opts...) |
| 870 |
} |
| 871 |
|
| 872 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 873 |
type restClient struct { |
| 874 |
// The http endpoint to connect to. |
| 875 |
endpoint string |
| 876 |
|
| 877 |
// The http client. |
| 878 |
httpClient *http.Client |
| 879 |
|
| 880 |
// The x-goog-* headers to be sent with each request. |
| 881 |
xGoogHeaders []string |
| 882 |
|
| 883 |
// Points back to the CallOptions field of the containing Client |
| 884 |
CallOptions **CallOptions |
| 885 |
|
| 886 |
logger *slog.Logger |
| 887 |
} |
| 888 |
|
| 889 |
// NewRESTClient creates a new api hub rest client. |
| 890 |
// |
| 891 |
// This service provides all methods related to the API hub. |
| 892 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 893 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 894 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 895 |
if err != nil { |
| 896 |
return nil, err |
| 897 |
} |
| 898 |
|
| 899 |
callOpts := defaultRESTCallOptions() |
| 900 |
c := &restClient{ |
| 901 |
endpoint: endpoint, |
| 902 |
httpClient: httpClient, |
| 903 |
CallOptions: &callOpts, |
| 904 |
logger: internaloption.GetLogger(opts), |
| 905 |
} |
| 906 |
c.setGoogleClientInfo() |
| 907 |
|
| 908 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 909 |
} |
| 910 |
|
| 911 |
func defaultRESTClientOptions() []option.ClientOption { |
| 912 |
return []option.ClientOption{ |
| 913 |
internaloption.WithDefaultEndpoint("https://apihub.googleapis.com"), |
| 914 |
internaloption.WithDefaultEndpointTemplate("https://apihub.UNIVERSE_DOMAIN"), |
| 915 |
internaloption.WithDefaultMTLSEndpoint("https://apihub.mtls.googleapis.com"), |
| 916 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 917 |
internaloption.WithDefaultAudience("https://apihub.googleapis.com/"), |
| 918 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 919 |
internaloption.EnableNewAuthLibrary(), |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
// setGoogleClientInfo sets the name and version of the application in |
| 924 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 925 |
// use by Google-written clients. |
| 926 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 927 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 928 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 929 |
c.xGoogHeaders = []string{ |
| 930 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
// Close closes the connection to the API service. The user should invoke this when |
| 935 |
// the client is no longer required. |
| 936 |
func (c *restClient) Close() error { |
| 937 |
// Replace httpClient with nil to force cleanup. |
| 938 |
c.httpClient = nil |
| 939 |
return nil |
| 940 |
} |
| 941 |
|
| 942 |
// Connection returns a connection to the API service. |
| 943 |
// |
| 944 |
// Deprecated: This method always returns nil. |
| 945 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 946 |
return nil |
| 947 |
} |
| 948 |
|
| 949 |
// CreateApi create an API resource in the API hub. |
| 950 |
// Once an API resource is created, versions can be added to it. |
| 951 |
func (c *restClient) CreateApi(ctx context.Context, req *apihubpb.CreateApiRequest, opts ...gax.CallOption) (*apihubpb.Api, error) { |
| 952 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 953 |
body := req.GetApi() |
| 954 |
jsonReq, err := m.Marshal(body) |
| 955 |
if err != nil { |
| 956 |
return nil, err |
| 957 |
} |
| 958 |
|
| 959 |
baseUrl, err := url.Parse(c.endpoint) |
| 960 |
if err != nil { |
| 961 |
return nil, err |
| 962 |
} |
| 963 |
baseUrl.Path += fmt.Sprintf("/v1/%v/apis", req.GetParent()) |
| 964 |
|
| 965 |
params := url.Values{} |
| 966 |
params.Add("$alt", "json;enum-encoding=int") |
| 967 |
if req.GetApiId() != "" { |
| 968 |
params.Add("apiId", fmt.Sprintf("%v", req.GetApiId())) |
| 969 |
} |
| 970 |
|
| 971 |
baseUrl.RawQuery = params.Encode() |
| 972 |
|
| 973 |
// Build HTTP headers from client and context metadata. |
| 974 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 975 |
|
| 976 |
hds = append(c.xGoogHeaders, hds...) |
| 977 |
hds = append(hds, "Content-Type", "application/json") |
| 978 |
headers := gax.BuildHeaders(ctx, hds...) |
| 979 |
opts = append((*c.CallOptions).CreateApi[0:len((*c.CallOptions).CreateApi):len((*c.CallOptions).CreateApi)], opts...) |
| 980 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 981 |
resp := &apihubpb.Api{} |
| 982 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 983 |
if settings.Path != "" { |
| 984 |
baseUrl.Path = settings.Path |
| 985 |
} |
| 986 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 987 |
if err != nil { |
| 988 |
return err |
| 989 |
} |
| 990 |
httpReq = httpReq.WithContext(ctx) |
| 991 |
httpReq.Header = headers |
| 992 |
|
| 993 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateApi") |
| 994 |
if err != nil { |
| 995 |
return err |
| 996 |
} |
| 997 |
|
| 998 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 999 |
return err |
| 1000 |
} |
| 1001 |
|
| 1002 |
return nil |
| 1003 |
}, opts...) |
| 1004 |
if e != nil { |
| 1005 |
return nil, e |
| 1006 |
} |
| 1007 |
return resp, nil |
| 1008 |
} |
| 1009 |
|
| 1010 |
// GetApi get API resource details including the API versions contained in it. |
| 1011 |
func (c *restClient) GetApi(ctx context.Context, req *apihubpb.GetApiRequest, opts ...gax.CallOption) (*apihubpb.Api, error) { |
| 1012 |
baseUrl, err := url.Parse(c.endpoint) |
| 1013 |
if err != nil { |
| 1014 |
return nil, err |
| 1015 |
} |
| 1016 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1017 |
|
| 1018 |
params := url.Values{} |
| 1019 |
params.Add("$alt", "json;enum-encoding=int") |
| 1020 |
|
| 1021 |
baseUrl.RawQuery = params.Encode() |
| 1022 |
|
| 1023 |
// Build HTTP headers from client and context metadata. |
| 1024 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1025 |
|
| 1026 |
hds = append(c.xGoogHeaders, hds...) |
| 1027 |
hds = append(hds, "Content-Type", "application/json") |
| 1028 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1029 |
opts = append((*c.CallOptions).GetApi[0:len((*c.CallOptions).GetApi):len((*c.CallOptions).GetApi)], opts...) |
| 1030 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1031 |
resp := &apihubpb.Api{} |
| 1032 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1033 |
if settings.Path != "" { |
| 1034 |
baseUrl.Path = settings.Path |
| 1035 |
} |
| 1036 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1037 |
if err != nil { |
| 1038 |
return err |
| 1039 |
} |
| 1040 |
httpReq = httpReq.WithContext(ctx) |
| 1041 |
httpReq.Header = headers |
| 1042 |
|
| 1043 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetApi") |
| 1044 |
if err != nil { |
| 1045 |
return err |
| 1046 |
} |
| 1047 |
|
| 1048 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1049 |
return err |
| 1050 |
} |
| 1051 |
|
| 1052 |
return nil |
| 1053 |
}, opts...) |
| 1054 |
if e != nil { |
| 1055 |
return nil, e |
| 1056 |
} |
| 1057 |
return resp, nil |
| 1058 |
} |
| 1059 |
|
| 1060 |
// ListApis list API resources in the API hub. |
| 1061 |
func (c *restClient) ListApis(ctx context.Context, req *apihubpb.ListApisRequest, opts ...gax.CallOption) *ApiIterator { |
| 1062 |
it := &ApiIterator{} |
| 1063 |
req = proto.Clone(req).(*apihubpb.ListApisRequest) |
| 1064 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1065 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Api, string, error) { |
| 1066 |
resp := &apihubpb.ListApisResponse{} |
| 1067 |
if pageToken != "" { |
| 1068 |
req.PageToken = pageToken |
| 1069 |
} |
| 1070 |
if pageSize > math.MaxInt32 { |
| 1071 |
req.PageSize = math.MaxInt32 |
| 1072 |
} else if pageSize != 0 { |
| 1073 |
req.PageSize = int32(pageSize) |
| 1074 |
} |
| 1075 |
baseUrl, err := url.Parse(c.endpoint) |
| 1076 |
if err != nil { |
| 1077 |
return nil, "", err |
| 1078 |
} |
| 1079 |
baseUrl.Path += fmt.Sprintf("/v1/%v/apis", req.GetParent()) |
| 1080 |
|
| 1081 |
params := url.Values{} |
| 1082 |
params.Add("$alt", "json;enum-encoding=int") |
| 1083 |
if req.GetFilter() != "" { |
| 1084 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1085 |
} |
| 1086 |
if req.GetPageSize() != 0 { |
| 1087 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1088 |
} |
| 1089 |
if req.GetPageToken() != "" { |
| 1090 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1091 |
} |
| 1092 |
|
| 1093 |
baseUrl.RawQuery = params.Encode() |
| 1094 |
|
| 1095 |
// Build HTTP headers from client and context metadata. |
| 1096 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1097 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1098 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1099 |
if settings.Path != "" { |
| 1100 |
baseUrl.Path = settings.Path |
| 1101 |
} |
| 1102 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1103 |
if err != nil { |
| 1104 |
return err |
| 1105 |
} |
| 1106 |
httpReq.Header = headers |
| 1107 |
|
| 1108 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListApis") |
| 1109 |
if err != nil { |
| 1110 |
return err |
| 1111 |
} |
| 1112 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1113 |
return err |
| 1114 |
} |
| 1115 |
|
| 1116 |
return nil |
| 1117 |
}, opts...) |
| 1118 |
if e != nil { |
| 1119 |
return nil, "", e |
| 1120 |
} |
| 1121 |
it.Response = resp |
| 1122 |
return resp.GetApis(), resp.GetNextPageToken(), nil |
| 1123 |
} |
| 1124 |
|
| 1125 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1126 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1127 |
if err != nil { |
| 1128 |
return "", err |
| 1129 |
} |
| 1130 |
it.items = append(it.items, items...) |
| 1131 |
return nextPageToken, nil |
| 1132 |
} |
| 1133 |
|
| 1134 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1135 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1136 |
it.pageInfo.Token = req.GetPageToken() |
| 1137 |
|
| 1138 |
return it |
| 1139 |
} |
| 1140 |
|
| 1141 |
// UpdateApi update an API resource in the API hub. The following fields in the |
| 1142 |
// API can be updated: |
| 1143 |
// |
| 1144 |
// display_name |
| 1145 |
// |
| 1146 |
// description |
| 1147 |
// |
| 1148 |
// owner |
| 1149 |
// |
| 1150 |
// documentation |
| 1151 |
// |
| 1152 |
// target_user |
| 1153 |
// |
| 1154 |
// [team][google.cloud.apihub.v1.Api.team (at http://google.cloud.apihub.v1.Api.team)] |
| 1155 |
// |
| 1156 |
// business_unit |
| 1157 |
// |
| 1158 |
// maturity_level |
| 1159 |
// |
| 1160 |
// api_style |
| 1161 |
// |
| 1162 |
// attributes |
| 1163 |
// |
| 1164 |
// The |
| 1165 |
// update_mask |
| 1166 |
// should be used to specify the fields being updated. |
| 1167 |
// |
| 1168 |
// Updating the owner field requires complete owner message |
| 1169 |
// and updates both owner and email fields. |
| 1170 |
func (c *restClient) UpdateApi(ctx context.Context, req *apihubpb.UpdateApiRequest, opts ...gax.CallOption) (*apihubpb.Api, error) { |
| 1171 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1172 |
body := req.GetApi() |
| 1173 |
jsonReq, err := m.Marshal(body) |
| 1174 |
if err != nil { |
| 1175 |
return nil, err |
| 1176 |
} |
| 1177 |
|
| 1178 |
baseUrl, err := url.Parse(c.endpoint) |
| 1179 |
if err != nil { |
| 1180 |
return nil, err |
| 1181 |
} |
| 1182 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetApi().GetName()) |
| 1183 |
|
| 1184 |
params := url.Values{} |
| 1185 |
params.Add("$alt", "json;enum-encoding=int") |
| 1186 |
if req.GetUpdateMask() != nil { |
| 1187 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1188 |
if err != nil { |
| 1189 |
return nil, err |
| 1190 |
} |
| 1191 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1192 |
} |
| 1193 |
|
| 1194 |
baseUrl.RawQuery = params.Encode() |
| 1195 |
|
| 1196 |
// Build HTTP headers from client and context metadata. |
| 1197 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "api.name", url.QueryEscape(req.GetApi().GetName()))} |
| 1198 |
|
| 1199 |
hds = append(c.xGoogHeaders, hds...) |
| 1200 |
hds = append(hds, "Content-Type", "application/json") |
| 1201 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1202 |
opts = append((*c.CallOptions).UpdateApi[0:len((*c.CallOptions).UpdateApi):len((*c.CallOptions).UpdateApi)], opts...) |
| 1203 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1204 |
resp := &apihubpb.Api{} |
| 1205 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1206 |
if settings.Path != "" { |
| 1207 |
baseUrl.Path = settings.Path |
| 1208 |
} |
| 1209 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1210 |
if err != nil { |
| 1211 |
return err |
| 1212 |
} |
| 1213 |
httpReq = httpReq.WithContext(ctx) |
| 1214 |
httpReq.Header = headers |
| 1215 |
|
| 1216 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateApi") |
| 1217 |
if err != nil { |
| 1218 |
return err |
| 1219 |
} |
| 1220 |
|
| 1221 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1222 |
return err |
| 1223 |
} |
| 1224 |
|
| 1225 |
return nil |
| 1226 |
}, opts...) |
| 1227 |
if e != nil { |
| 1228 |
return nil, e |
| 1229 |
} |
| 1230 |
return resp, nil |
| 1231 |
} |
| 1232 |
|
| 1233 |
// DeleteApi delete an API resource in the API hub. API can only be deleted if all |
| 1234 |
// underlying versions are deleted. |
| 1235 |
func (c *restClient) DeleteApi(ctx context.Context, req *apihubpb.DeleteApiRequest, opts ...gax.CallOption) error { |
| 1236 |
baseUrl, err := url.Parse(c.endpoint) |
| 1237 |
if err != nil { |
| 1238 |
return err |
| 1239 |
} |
| 1240 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1241 |
|
| 1242 |
params := url.Values{} |
| 1243 |
params.Add("$alt", "json;enum-encoding=int") |
| 1244 |
if req.GetForce() { |
| 1245 |
params.Add("force", fmt.Sprintf("%v", req.GetForce())) |
| 1246 |
} |
| 1247 |
|
| 1248 |
baseUrl.RawQuery = params.Encode() |
| 1249 |
|
| 1250 |
// Build HTTP headers from client and context metadata. |
| 1251 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1252 |
|
| 1253 |
hds = append(c.xGoogHeaders, hds...) |
| 1254 |
hds = append(hds, "Content-Type", "application/json") |
| 1255 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1256 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1257 |
if settings.Path != "" { |
| 1258 |
baseUrl.Path = settings.Path |
| 1259 |
} |
| 1260 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1261 |
if err != nil { |
| 1262 |
return err |
| 1263 |
} |
| 1264 |
httpReq = httpReq.WithContext(ctx) |
| 1265 |
httpReq.Header = headers |
| 1266 |
|
| 1267 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteApi") |
| 1268 |
return err |
| 1269 |
}, opts...) |
| 1270 |
} |
| 1271 |
|
| 1272 |
// CreateVersion create an API version for an API resource in the API hub. |
| 1273 |
func (c *restClient) CreateVersion(ctx context.Context, req *apihubpb.CreateVersionRequest, opts ...gax.CallOption) (*apihubpb.Version, error) { |
| 1274 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1275 |
body := req.GetVersion() |
| 1276 |
jsonReq, err := m.Marshal(body) |
| 1277 |
if err != nil { |
| 1278 |
return nil, err |
| 1279 |
} |
| 1280 |
|
| 1281 |
baseUrl, err := url.Parse(c.endpoint) |
| 1282 |
if err != nil { |
| 1283 |
return nil, err |
| 1284 |
} |
| 1285 |
baseUrl.Path += fmt.Sprintf("/v1/%v/versions", req.GetParent()) |
| 1286 |
|
| 1287 |
params := url.Values{} |
| 1288 |
params.Add("$alt", "json;enum-encoding=int") |
| 1289 |
if req.GetVersionId() != "" { |
| 1290 |
params.Add("versionId", fmt.Sprintf("%v", req.GetVersionId())) |
| 1291 |
} |
| 1292 |
|
| 1293 |
baseUrl.RawQuery = params.Encode() |
| 1294 |
|
| 1295 |
// Build HTTP headers from client and context metadata. |
| 1296 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1297 |
|
| 1298 |
hds = append(c.xGoogHeaders, hds...) |
| 1299 |
hds = append(hds, "Content-Type", "application/json") |
| 1300 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1301 |
opts = append((*c.CallOptions).CreateVersion[0:len((*c.CallOptions).CreateVersion):len((*c.CallOptions).CreateVersion)], opts...) |
| 1302 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1303 |
resp := &apihubpb.Version{} |
| 1304 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1305 |
if settings.Path != "" { |
| 1306 |
baseUrl.Path = settings.Path |
| 1307 |
} |
| 1308 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1309 |
if err != nil { |
| 1310 |
return err |
| 1311 |
} |
| 1312 |
httpReq = httpReq.WithContext(ctx) |
| 1313 |
httpReq.Header = headers |
| 1314 |
|
| 1315 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateVersion") |
| 1316 |
if err != nil { |
| 1317 |
return err |
| 1318 |
} |
| 1319 |
|
| 1320 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1321 |
return err |
| 1322 |
} |
| 1323 |
|
| 1324 |
return nil |
| 1325 |
}, opts...) |
| 1326 |
if e != nil { |
| 1327 |
return nil, e |
| 1328 |
} |
| 1329 |
return resp, nil |
| 1330 |
} |
| 1331 |
|
| 1332 |
// GetVersion get details about the API version of an API resource. This will include |
| 1333 |
// information about the specs and operations present in the API |
| 1334 |
// version as well as the deployments linked to it. |
| 1335 |
func (c *restClient) GetVersion(ctx context.Context, req *apihubpb.GetVersionRequest, opts ...gax.CallOption) (*apihubpb.Version, error) { |
| 1336 |
baseUrl, err := url.Parse(c.endpoint) |
| 1337 |
if err != nil { |
| 1338 |
return nil, err |
| 1339 |
} |
| 1340 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1341 |
|
| 1342 |
params := url.Values{} |
| 1343 |
params.Add("$alt", "json;enum-encoding=int") |
| 1344 |
|
| 1345 |
baseUrl.RawQuery = params.Encode() |
| 1346 |
|
| 1347 |
// Build HTTP headers from client and context metadata. |
| 1348 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1349 |
|
| 1350 |
hds = append(c.xGoogHeaders, hds...) |
| 1351 |
hds = append(hds, "Content-Type", "application/json") |
| 1352 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1353 |
opts = append((*c.CallOptions).GetVersion[0:len((*c.CallOptions).GetVersion):len((*c.CallOptions).GetVersion)], opts...) |
| 1354 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1355 |
resp := &apihubpb.Version{} |
| 1356 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1357 |
if settings.Path != "" { |
| 1358 |
baseUrl.Path = settings.Path |
| 1359 |
} |
| 1360 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1361 |
if err != nil { |
| 1362 |
return err |
| 1363 |
} |
| 1364 |
httpReq = httpReq.WithContext(ctx) |
| 1365 |
httpReq.Header = headers |
| 1366 |
|
| 1367 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetVersion") |
| 1368 |
if err != nil { |
| 1369 |
return err |
| 1370 |
} |
| 1371 |
|
| 1372 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1373 |
return err |
| 1374 |
} |
| 1375 |
|
| 1376 |
return nil |
| 1377 |
}, opts...) |
| 1378 |
if e != nil { |
| 1379 |
return nil, e |
| 1380 |
} |
| 1381 |
return resp, nil |
| 1382 |
} |
| 1383 |
|
| 1384 |
// ListVersions list API versions of an API resource in the API hub. |
| 1385 |
func (c *restClient) ListVersions(ctx context.Context, req *apihubpb.ListVersionsRequest, opts ...gax.CallOption) *VersionIterator { |
| 1386 |
it := &VersionIterator{} |
| 1387 |
req = proto.Clone(req).(*apihubpb.ListVersionsRequest) |
| 1388 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1389 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Version, string, error) { |
| 1390 |
resp := &apihubpb.ListVersionsResponse{} |
| 1391 |
if pageToken != "" { |
| 1392 |
req.PageToken = pageToken |
| 1393 |
} |
| 1394 |
if pageSize > math.MaxInt32 { |
| 1395 |
req.PageSize = math.MaxInt32 |
| 1396 |
} else if pageSize != 0 { |
| 1397 |
req.PageSize = int32(pageSize) |
| 1398 |
} |
| 1399 |
baseUrl, err := url.Parse(c.endpoint) |
| 1400 |
if err != nil { |
| 1401 |
return nil, "", err |
| 1402 |
} |
| 1403 |
baseUrl.Path += fmt.Sprintf("/v1/%v/versions", req.GetParent()) |
| 1404 |
|
| 1405 |
params := url.Values{} |
| 1406 |
params.Add("$alt", "json;enum-encoding=int") |
| 1407 |
if req.GetFilter() != "" { |
| 1408 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1409 |
} |
| 1410 |
if req.GetPageSize() != 0 { |
| 1411 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1412 |
} |
| 1413 |
if req.GetPageToken() != "" { |
| 1414 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1415 |
} |
| 1416 |
|
| 1417 |
baseUrl.RawQuery = params.Encode() |
| 1418 |
|
| 1419 |
// Build HTTP headers from client and context metadata. |
| 1420 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1421 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1422 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1423 |
if settings.Path != "" { |
| 1424 |
baseUrl.Path = settings.Path |
| 1425 |
} |
| 1426 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1427 |
if err != nil { |
| 1428 |
return err |
| 1429 |
} |
| 1430 |
httpReq.Header = headers |
| 1431 |
|
| 1432 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListVersions") |
| 1433 |
if err != nil { |
| 1434 |
return err |
| 1435 |
} |
| 1436 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1437 |
return err |
| 1438 |
} |
| 1439 |
|
| 1440 |
return nil |
| 1441 |
}, opts...) |
| 1442 |
if e != nil { |
| 1443 |
return nil, "", e |
| 1444 |
} |
| 1445 |
it.Response = resp |
| 1446 |
return resp.GetVersions(), resp.GetNextPageToken(), nil |
| 1447 |
} |
| 1448 |
|
| 1449 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1450 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1451 |
if err != nil { |
| 1452 |
return "", err |
| 1453 |
} |
| 1454 |
it.items = append(it.items, items...) |
| 1455 |
return nextPageToken, nil |
| 1456 |
} |
| 1457 |
|
| 1458 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1459 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1460 |
it.pageInfo.Token = req.GetPageToken() |
| 1461 |
|
| 1462 |
return it |
| 1463 |
} |
| 1464 |
|
| 1465 |
// UpdateVersion update API version. The following fields in the |
| 1466 |
// version can be updated currently: |
| 1467 |
// |
| 1468 |
// display_name |
| 1469 |
// |
| 1470 |
// description |
| 1471 |
// |
| 1472 |
// documentation |
| 1473 |
// |
| 1474 |
// deployments |
| 1475 |
// |
| 1476 |
// lifecycle |
| 1477 |
// |
| 1478 |
// compliance |
| 1479 |
// |
| 1480 |
// accreditation |
| 1481 |
// |
| 1482 |
// attributes |
| 1483 |
// |
| 1484 |
// The |
| 1485 |
// update_mask |
| 1486 |
// should be used to specify the fields being updated. |
| 1487 |
func (c *restClient) UpdateVersion(ctx context.Context, req *apihubpb.UpdateVersionRequest, opts ...gax.CallOption) (*apihubpb.Version, error) { |
| 1488 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1489 |
body := req.GetVersion() |
| 1490 |
jsonReq, err := m.Marshal(body) |
| 1491 |
if err != nil { |
| 1492 |
return nil, err |
| 1493 |
} |
| 1494 |
|
| 1495 |
baseUrl, err := url.Parse(c.endpoint) |
| 1496 |
if err != nil { |
| 1497 |
return nil, err |
| 1498 |
} |
| 1499 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetVersion().GetName()) |
| 1500 |
|
| 1501 |
params := url.Values{} |
| 1502 |
params.Add("$alt", "json;enum-encoding=int") |
| 1503 |
if req.GetUpdateMask() != nil { |
| 1504 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1505 |
if err != nil { |
| 1506 |
return nil, err |
| 1507 |
} |
| 1508 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1509 |
} |
| 1510 |
|
| 1511 |
baseUrl.RawQuery = params.Encode() |
| 1512 |
|
| 1513 |
// Build HTTP headers from client and context metadata. |
| 1514 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "version.name", url.QueryEscape(req.GetVersion().GetName()))} |
| 1515 |
|
| 1516 |
hds = append(c.xGoogHeaders, hds...) |
| 1517 |
hds = append(hds, "Content-Type", "application/json") |
| 1518 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1519 |
opts = append((*c.CallOptions).UpdateVersion[0:len((*c.CallOptions).UpdateVersion):len((*c.CallOptions).UpdateVersion)], opts...) |
| 1520 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1521 |
resp := &apihubpb.Version{} |
| 1522 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1523 |
if settings.Path != "" { |
| 1524 |
baseUrl.Path = settings.Path |
| 1525 |
} |
| 1526 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1527 |
if err != nil { |
| 1528 |
return err |
| 1529 |
} |
| 1530 |
httpReq = httpReq.WithContext(ctx) |
| 1531 |
httpReq.Header = headers |
| 1532 |
|
| 1533 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateVersion") |
| 1534 |
if err != nil { |
| 1535 |
return err |
| 1536 |
} |
| 1537 |
|
| 1538 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1539 |
return err |
| 1540 |
} |
| 1541 |
|
| 1542 |
return nil |
| 1543 |
}, opts...) |
| 1544 |
if e != nil { |
| 1545 |
return nil, e |
| 1546 |
} |
| 1547 |
return resp, nil |
| 1548 |
} |
| 1549 |
|
| 1550 |
// DeleteVersion delete an API version. Version can only be deleted if all underlying specs, |
| 1551 |
// operations, definitions and linked deployments are deleted. |
| 1552 |
func (c *restClient) DeleteVersion(ctx context.Context, req *apihubpb.DeleteVersionRequest, opts ...gax.CallOption) error { |
| 1553 |
baseUrl, err := url.Parse(c.endpoint) |
| 1554 |
if err != nil { |
| 1555 |
return err |
| 1556 |
} |
| 1557 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1558 |
|
| 1559 |
params := url.Values{} |
| 1560 |
params.Add("$alt", "json;enum-encoding=int") |
| 1561 |
if req.GetForce() { |
| 1562 |
params.Add("force", fmt.Sprintf("%v", req.GetForce())) |
| 1563 |
} |
| 1564 |
|
| 1565 |
baseUrl.RawQuery = params.Encode() |
| 1566 |
|
| 1567 |
// Build HTTP headers from client and context metadata. |
| 1568 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1569 |
|
| 1570 |
hds = append(c.xGoogHeaders, hds...) |
| 1571 |
hds = append(hds, "Content-Type", "application/json") |
| 1572 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1573 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1574 |
if settings.Path != "" { |
| 1575 |
baseUrl.Path = settings.Path |
| 1576 |
} |
| 1577 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1578 |
if err != nil { |
| 1579 |
return err |
| 1580 |
} |
| 1581 |
httpReq = httpReq.WithContext(ctx) |
| 1582 |
httpReq.Header = headers |
| 1583 |
|
| 1584 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteVersion") |
| 1585 |
return err |
| 1586 |
}, opts...) |
| 1587 |
} |
| 1588 |
|
| 1589 |
// CreateSpec add a spec to an API version in the API hub. |
| 1590 |
// Multiple specs can be added to an API version. |
| 1591 |
// Note, while adding a spec, at least one of contents or source_uri must |
| 1592 |
// be provided. If contents is provided, then spec_type must also be |
| 1593 |
// provided. |
| 1594 |
// |
| 1595 |
// On adding a spec with contents to the version, the operations present in it |
| 1596 |
// will be added to the version.Note that the file contents in the spec should |
| 1597 |
// be of the same type as defined in the |
| 1598 |
// projects/{project}/locations/{location}/attributes/system-spec-type |
| 1599 |
// attribute associated with spec resource. Note that specs of various types |
| 1600 |
// can be uploaded, however parsing of details is supported for OpenAPI spec |
| 1601 |
// currently. |
| 1602 |
// |
| 1603 |
// In order to access the information parsed from the spec, use the |
| 1604 |
// GetSpec method. |
| 1605 |
// In order to access the raw contents for a particular spec, use the |
| 1606 |
// GetSpecContents method. |
| 1607 |
// In order to access the operations parsed from the spec, use the |
| 1608 |
// ListAPIOperations |
| 1609 |
// method. |
| 1610 |
func (c *restClient) CreateSpec(ctx context.Context, req *apihubpb.CreateSpecRequest, opts ...gax.CallOption) (*apihubpb.Spec, error) { |
| 1611 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1612 |
body := req.GetSpec() |
| 1613 |
jsonReq, err := m.Marshal(body) |
| 1614 |
if err != nil { |
| 1615 |
return nil, err |
| 1616 |
} |
| 1617 |
|
| 1618 |
baseUrl, err := url.Parse(c.endpoint) |
| 1619 |
if err != nil { |
| 1620 |
return nil, err |
| 1621 |
} |
| 1622 |
baseUrl.Path += fmt.Sprintf("/v1/%v/specs", req.GetParent()) |
| 1623 |
|
| 1624 |
params := url.Values{} |
| 1625 |
params.Add("$alt", "json;enum-encoding=int") |
| 1626 |
if req.GetSpecId() != "" { |
| 1627 |
params.Add("specId", fmt.Sprintf("%v", req.GetSpecId())) |
| 1628 |
} |
| 1629 |
|
| 1630 |
baseUrl.RawQuery = params.Encode() |
| 1631 |
|
| 1632 |
// Build HTTP headers from client and context metadata. |
| 1633 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1634 |
|
| 1635 |
hds = append(c.xGoogHeaders, hds...) |
| 1636 |
hds = append(hds, "Content-Type", "application/json") |
| 1637 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1638 |
opts = append((*c.CallOptions).CreateSpec[0:len((*c.CallOptions).CreateSpec):len((*c.CallOptions).CreateSpec)], opts...) |
| 1639 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1640 |
resp := &apihubpb.Spec{} |
| 1641 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1642 |
if settings.Path != "" { |
| 1643 |
baseUrl.Path = settings.Path |
| 1644 |
} |
| 1645 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1646 |
if err != nil { |
| 1647 |
return err |
| 1648 |
} |
| 1649 |
httpReq = httpReq.WithContext(ctx) |
| 1650 |
httpReq.Header = headers |
| 1651 |
|
| 1652 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateSpec") |
| 1653 |
if err != nil { |
| 1654 |
return err |
| 1655 |
} |
| 1656 |
|
| 1657 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1658 |
return err |
| 1659 |
} |
| 1660 |
|
| 1661 |
return nil |
| 1662 |
}, opts...) |
| 1663 |
if e != nil { |
| 1664 |
return nil, e |
| 1665 |
} |
| 1666 |
return resp, nil |
| 1667 |
} |
| 1668 |
|
| 1669 |
// GetSpec get details about the information parsed from a spec. |
| 1670 |
// Note that this method does not return the raw spec contents. |
| 1671 |
// Use GetSpecContents method |
| 1672 |
// to retrieve the same. |
| 1673 |
func (c *restClient) GetSpec(ctx context.Context, req *apihubpb.GetSpecRequest, opts ...gax.CallOption) (*apihubpb.Spec, error) { |
| 1674 |
baseUrl, err := url.Parse(c.endpoint) |
| 1675 |
if err != nil { |
| 1676 |
return nil, err |
| 1677 |
} |
| 1678 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1679 |
|
| 1680 |
params := url.Values{} |
| 1681 |
params.Add("$alt", "json;enum-encoding=int") |
| 1682 |
|
| 1683 |
baseUrl.RawQuery = params.Encode() |
| 1684 |
|
| 1685 |
// Build HTTP headers from client and context metadata. |
| 1686 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1687 |
|
| 1688 |
hds = append(c.xGoogHeaders, hds...) |
| 1689 |
hds = append(hds, "Content-Type", "application/json") |
| 1690 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1691 |
opts = append((*c.CallOptions).GetSpec[0:len((*c.CallOptions).GetSpec):len((*c.CallOptions).GetSpec)], opts...) |
| 1692 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1693 |
resp := &apihubpb.Spec{} |
| 1694 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1695 |
if settings.Path != "" { |
| 1696 |
baseUrl.Path = settings.Path |
| 1697 |
} |
| 1698 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1699 |
if err != nil { |
| 1700 |
return err |
| 1701 |
} |
| 1702 |
httpReq = httpReq.WithContext(ctx) |
| 1703 |
httpReq.Header = headers |
| 1704 |
|
| 1705 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSpec") |
| 1706 |
if err != nil { |
| 1707 |
return err |
| 1708 |
} |
| 1709 |
|
| 1710 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1711 |
return err |
| 1712 |
} |
| 1713 |
|
| 1714 |
return nil |
| 1715 |
}, opts...) |
| 1716 |
if e != nil { |
| 1717 |
return nil, e |
| 1718 |
} |
| 1719 |
return resp, nil |
| 1720 |
} |
| 1721 |
|
| 1722 |
// GetSpecContents get spec contents. |
| 1723 |
func (c *restClient) GetSpecContents(ctx context.Context, req *apihubpb.GetSpecContentsRequest, opts ...gax.CallOption) (*apihubpb.SpecContents, error) { |
| 1724 |
baseUrl, err := url.Parse(c.endpoint) |
| 1725 |
if err != nil { |
| 1726 |
return nil, err |
| 1727 |
} |
| 1728 |
baseUrl.Path += fmt.Sprintf("/v1/%v:contents", req.GetName()) |
| 1729 |
|
| 1730 |
params := url.Values{} |
| 1731 |
params.Add("$alt", "json;enum-encoding=int") |
| 1732 |
|
| 1733 |
baseUrl.RawQuery = params.Encode() |
| 1734 |
|
| 1735 |
// Build HTTP headers from client and context metadata. |
| 1736 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1737 |
|
| 1738 |
hds = append(c.xGoogHeaders, hds...) |
| 1739 |
hds = append(hds, "Content-Type", "application/json") |
| 1740 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1741 |
opts = append((*c.CallOptions).GetSpecContents[0:len((*c.CallOptions).GetSpecContents):len((*c.CallOptions).GetSpecContents)], opts...) |
| 1742 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1743 |
resp := &apihubpb.SpecContents{} |
| 1744 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1745 |
if settings.Path != "" { |
| 1746 |
baseUrl.Path = settings.Path |
| 1747 |
} |
| 1748 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1749 |
if err != nil { |
| 1750 |
return err |
| 1751 |
} |
| 1752 |
httpReq = httpReq.WithContext(ctx) |
| 1753 |
httpReq.Header = headers |
| 1754 |
|
| 1755 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSpecContents") |
| 1756 |
if err != nil { |
| 1757 |
return err |
| 1758 |
} |
| 1759 |
|
| 1760 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1761 |
return err |
| 1762 |
} |
| 1763 |
|
| 1764 |
return nil |
| 1765 |
}, opts...) |
| 1766 |
if e != nil { |
| 1767 |
return nil, e |
| 1768 |
} |
| 1769 |
return resp, nil |
| 1770 |
} |
| 1771 |
|
| 1772 |
// ListSpecs list specs corresponding to a particular API resource. |
| 1773 |
func (c *restClient) ListSpecs(ctx context.Context, req *apihubpb.ListSpecsRequest, opts ...gax.CallOption) *SpecIterator { |
| 1774 |
it := &SpecIterator{} |
| 1775 |
req = proto.Clone(req).(*apihubpb.ListSpecsRequest) |
| 1776 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1777 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Spec, string, error) { |
| 1778 |
resp := &apihubpb.ListSpecsResponse{} |
| 1779 |
if pageToken != "" { |
| 1780 |
req.PageToken = pageToken |
| 1781 |
} |
| 1782 |
if pageSize > math.MaxInt32 { |
| 1783 |
req.PageSize = math.MaxInt32 |
| 1784 |
} else if pageSize != 0 { |
| 1785 |
req.PageSize = int32(pageSize) |
| 1786 |
} |
| 1787 |
baseUrl, err := url.Parse(c.endpoint) |
| 1788 |
if err != nil { |
| 1789 |
return nil, "", err |
| 1790 |
} |
| 1791 |
baseUrl.Path += fmt.Sprintf("/v1/%v/specs", req.GetParent()) |
| 1792 |
|
| 1793 |
params := url.Values{} |
| 1794 |
params.Add("$alt", "json;enum-encoding=int") |
| 1795 |
if req.GetFilter() != "" { |
| 1796 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1797 |
} |
| 1798 |
if req.GetPageSize() != 0 { |
| 1799 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1800 |
} |
| 1801 |
if req.GetPageToken() != "" { |
| 1802 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1803 |
} |
| 1804 |
|
| 1805 |
baseUrl.RawQuery = params.Encode() |
| 1806 |
|
| 1807 |
// Build HTTP headers from client and context metadata. |
| 1808 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1809 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1810 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1811 |
if settings.Path != "" { |
| 1812 |
baseUrl.Path = settings.Path |
| 1813 |
} |
| 1814 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1815 |
if err != nil { |
| 1816 |
return err |
| 1817 |
} |
| 1818 |
httpReq.Header = headers |
| 1819 |
|
| 1820 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSpecs") |
| 1821 |
if err != nil { |
| 1822 |
return err |
| 1823 |
} |
| 1824 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1825 |
return err |
| 1826 |
} |
| 1827 |
|
| 1828 |
return nil |
| 1829 |
}, opts...) |
| 1830 |
if e != nil { |
| 1831 |
return nil, "", e |
| 1832 |
} |
| 1833 |
it.Response = resp |
| 1834 |
return resp.GetSpecs(), resp.GetNextPageToken(), nil |
| 1835 |
} |
| 1836 |
|
| 1837 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1838 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1839 |
if err != nil { |
| 1840 |
return "", err |
| 1841 |
} |
| 1842 |
it.items = append(it.items, items...) |
| 1843 |
return nextPageToken, nil |
| 1844 |
} |
| 1845 |
|
| 1846 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1847 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1848 |
it.pageInfo.Token = req.GetPageToken() |
| 1849 |
|
| 1850 |
return it |
| 1851 |
} |
| 1852 |
|
| 1853 |
// UpdateSpec update spec. The following fields in the |
| 1854 |
// spec can be updated: |
| 1855 |
// |
| 1856 |
// display_name |
| 1857 |
// |
| 1858 |
// source_uri |
| 1859 |
// |
| 1860 |
// lint_response |
| 1861 |
// |
| 1862 |
// attributes |
| 1863 |
// |
| 1864 |
// contents |
| 1865 |
// |
| 1866 |
// spec_type |
| 1867 |
// |
| 1868 |
// In case of an OAS spec, updating spec contents can lead to: |
| 1869 |
// |
| 1870 |
// Creation, deletion and update of operations. |
| 1871 |
// |
| 1872 |
// Creation, deletion and update of definitions. |
| 1873 |
// |
| 1874 |
// Update of other info parsed out from the new spec. |
| 1875 |
// |
| 1876 |
// In case of contents or source_uri being present in update mask, spec_type |
| 1877 |
// must also be present. Also, spec_type can not be present in update mask if |
| 1878 |
// contents or source_uri is not present. |
| 1879 |
// |
| 1880 |
// The |
| 1881 |
// update_mask |
| 1882 |
// should be used to specify the fields being updated. |
| 1883 |
func (c *restClient) UpdateSpec(ctx context.Context, req *apihubpb.UpdateSpecRequest, opts ...gax.CallOption) (*apihubpb.Spec, error) { |
| 1884 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1885 |
body := req.GetSpec() |
| 1886 |
jsonReq, err := m.Marshal(body) |
| 1887 |
if err != nil { |
| 1888 |
return nil, err |
| 1889 |
} |
| 1890 |
|
| 1891 |
baseUrl, err := url.Parse(c.endpoint) |
| 1892 |
if err != nil { |
| 1893 |
return nil, err |
| 1894 |
} |
| 1895 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetSpec().GetName()) |
| 1896 |
|
| 1897 |
params := url.Values{} |
| 1898 |
params.Add("$alt", "json;enum-encoding=int") |
| 1899 |
if req.GetUpdateMask() != nil { |
| 1900 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1901 |
if err != nil { |
| 1902 |
return nil, err |
| 1903 |
} |
| 1904 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1905 |
} |
| 1906 |
|
| 1907 |
baseUrl.RawQuery = params.Encode() |
| 1908 |
|
| 1909 |
// Build HTTP headers from client and context metadata. |
| 1910 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "spec.name", url.QueryEscape(req.GetSpec().GetName()))} |
| 1911 |
|
| 1912 |
hds = append(c.xGoogHeaders, hds...) |
| 1913 |
hds = append(hds, "Content-Type", "application/json") |
| 1914 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1915 |
opts = append((*c.CallOptions).UpdateSpec[0:len((*c.CallOptions).UpdateSpec):len((*c.CallOptions).UpdateSpec)], opts...) |
| 1916 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1917 |
resp := &apihubpb.Spec{} |
| 1918 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1919 |
if settings.Path != "" { |
| 1920 |
baseUrl.Path = settings.Path |
| 1921 |
} |
| 1922 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1923 |
if err != nil { |
| 1924 |
return err |
| 1925 |
} |
| 1926 |
httpReq = httpReq.WithContext(ctx) |
| 1927 |
httpReq.Header = headers |
| 1928 |
|
| 1929 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateSpec") |
| 1930 |
if err != nil { |
| 1931 |
return err |
| 1932 |
} |
| 1933 |
|
| 1934 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1935 |
return err |
| 1936 |
} |
| 1937 |
|
| 1938 |
return nil |
| 1939 |
}, opts...) |
| 1940 |
if e != nil { |
| 1941 |
return nil, e |
| 1942 |
} |
| 1943 |
return resp, nil |
| 1944 |
} |
| 1945 |
|
| 1946 |
// DeleteSpec delete a spec. |
| 1947 |
// Deleting a spec will also delete the associated operations from the |
| 1948 |
// version. |
| 1949 |
func (c *restClient) DeleteSpec(ctx context.Context, req *apihubpb.DeleteSpecRequest, opts ...gax.CallOption) error { |
| 1950 |
baseUrl, err := url.Parse(c.endpoint) |
| 1951 |
if err != nil { |
| 1952 |
return err |
| 1953 |
} |
| 1954 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1955 |
|
| 1956 |
params := url.Values{} |
| 1957 |
params.Add("$alt", "json;enum-encoding=int") |
| 1958 |
|
| 1959 |
baseUrl.RawQuery = params.Encode() |
| 1960 |
|
| 1961 |
// Build HTTP headers from client and context metadata. |
| 1962 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1963 |
|
| 1964 |
hds = append(c.xGoogHeaders, hds...) |
| 1965 |
hds = append(hds, "Content-Type", "application/json") |
| 1966 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1967 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1968 |
if settings.Path != "" { |
| 1969 |
baseUrl.Path = settings.Path |
| 1970 |
} |
| 1971 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1972 |
if err != nil { |
| 1973 |
return err |
| 1974 |
} |
| 1975 |
httpReq = httpReq.WithContext(ctx) |
| 1976 |
httpReq.Header = headers |
| 1977 |
|
| 1978 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteSpec") |
| 1979 |
return err |
| 1980 |
}, opts...) |
| 1981 |
} |
| 1982 |
|
| 1983 |
// CreateApiOperation create an apiOperation in an API version. |
| 1984 |
// An apiOperation can be created only if the version has no apiOperations |
| 1985 |
// which were created by parsing a spec. |
| 1986 |
func (c *restClient) CreateApiOperation(ctx context.Context, req *apihubpb.CreateApiOperationRequest, opts ...gax.CallOption) (*apihubpb.ApiOperation, error) { |
| 1987 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1988 |
body := req.GetApiOperation() |
| 1989 |
jsonReq, err := m.Marshal(body) |
| 1990 |
if err != nil { |
| 1991 |
return nil, err |
| 1992 |
} |
| 1993 |
|
| 1994 |
baseUrl, err := url.Parse(c.endpoint) |
| 1995 |
if err != nil { |
| 1996 |
return nil, err |
| 1997 |
} |
| 1998 |
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetParent()) |
| 1999 |
|
| 2000 |
params := url.Values{} |
| 2001 |
params.Add("$alt", "json;enum-encoding=int") |
| 2002 |
if req.GetApiOperationId() != "" { |
| 2003 |
params.Add("apiOperationId", fmt.Sprintf("%v", req.GetApiOperationId())) |
| 2004 |
} |
| 2005 |
|
| 2006 |
baseUrl.RawQuery = params.Encode() |
| 2007 |
|
| 2008 |
// Build HTTP headers from client and context metadata. |
| 2009 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 2010 |
|
| 2011 |
hds = append(c.xGoogHeaders, hds...) |
| 2012 |
hds = append(hds, "Content-Type", "application/json") |
| 2013 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2014 |
opts = append((*c.CallOptions).CreateApiOperation[0:len((*c.CallOptions).CreateApiOperation):len((*c.CallOptions).CreateApiOperation)], opts...) |
| 2015 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2016 |
resp := &apihubpb.ApiOperation{} |
| 2017 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2018 |
if settings.Path != "" { |
| 2019 |
baseUrl.Path = settings.Path |
| 2020 |
} |
| 2021 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2022 |
if err != nil { |
| 2023 |
return err |
| 2024 |
} |
| 2025 |
httpReq = httpReq.WithContext(ctx) |
| 2026 |
httpReq.Header = headers |
| 2027 |
|
| 2028 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateApiOperation") |
| 2029 |
if err != nil { |
| 2030 |
return err |
| 2031 |
} |
| 2032 |
|
| 2033 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2034 |
return err |
| 2035 |
} |
| 2036 |
|
| 2037 |
return nil |
| 2038 |
}, opts...) |
| 2039 |
if e != nil { |
| 2040 |
return nil, e |
| 2041 |
} |
| 2042 |
return resp, nil |
| 2043 |
} |
| 2044 |
|
| 2045 |
// GetApiOperation get details about a particular operation in API version. |
| 2046 |
func (c *restClient) GetApiOperation(ctx context.Context, req *apihubpb.GetApiOperationRequest, opts ...gax.CallOption) (*apihubpb.ApiOperation, error) { |
| 2047 |
baseUrl, err := url.Parse(c.endpoint) |
| 2048 |
if err != nil { |
| 2049 |
return nil, err |
| 2050 |
} |
| 2051 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2052 |
|
| 2053 |
params := url.Values{} |
| 2054 |
params.Add("$alt", "json;enum-encoding=int") |
| 2055 |
|
| 2056 |
baseUrl.RawQuery = params.Encode() |
| 2057 |
|
| 2058 |
// Build HTTP headers from client and context metadata. |
| 2059 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2060 |
|
| 2061 |
hds = append(c.xGoogHeaders, hds...) |
| 2062 |
hds = append(hds, "Content-Type", "application/json") |
| 2063 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2064 |
opts = append((*c.CallOptions).GetApiOperation[0:len((*c.CallOptions).GetApiOperation):len((*c.CallOptions).GetApiOperation)], opts...) |
| 2065 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2066 |
resp := &apihubpb.ApiOperation{} |
| 2067 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2068 |
if settings.Path != "" { |
| 2069 |
baseUrl.Path = settings.Path |
| 2070 |
} |
| 2071 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2072 |
if err != nil { |
| 2073 |
return err |
| 2074 |
} |
| 2075 |
httpReq = httpReq.WithContext(ctx) |
| 2076 |
httpReq.Header = headers |
| 2077 |
|
| 2078 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetApiOperation") |
| 2079 |
if err != nil { |
| 2080 |
return err |
| 2081 |
} |
| 2082 |
|
| 2083 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2084 |
return err |
| 2085 |
} |
| 2086 |
|
| 2087 |
return nil |
| 2088 |
}, opts...) |
| 2089 |
if e != nil { |
| 2090 |
return nil, e |
| 2091 |
} |
| 2092 |
return resp, nil |
| 2093 |
} |
| 2094 |
|
| 2095 |
// ListApiOperations list operations in an API version. |
| 2096 |
func (c *restClient) ListApiOperations(ctx context.Context, req *apihubpb.ListApiOperationsRequest, opts ...gax.CallOption) *ApiOperationIterator { |
| 2097 |
it := &ApiOperationIterator{} |
| 2098 |
req = proto.Clone(req).(*apihubpb.ListApiOperationsRequest) |
| 2099 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2100 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.ApiOperation, string, error) { |
| 2101 |
resp := &apihubpb.ListApiOperationsResponse{} |
| 2102 |
if pageToken != "" { |
| 2103 |
req.PageToken = pageToken |
| 2104 |
} |
| 2105 |
if pageSize > math.MaxInt32 { |
| 2106 |
req.PageSize = math.MaxInt32 |
| 2107 |
} else if pageSize != 0 { |
| 2108 |
req.PageSize = int32(pageSize) |
| 2109 |
} |
| 2110 |
baseUrl, err := url.Parse(c.endpoint) |
| 2111 |
if err != nil { |
| 2112 |
return nil, "", err |
| 2113 |
} |
| 2114 |
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetParent()) |
| 2115 |
|
| 2116 |
params := url.Values{} |
| 2117 |
params.Add("$alt", "json;enum-encoding=int") |
| 2118 |
if req.GetFilter() != "" { |
| 2119 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 2120 |
} |
| 2121 |
if req.GetPageSize() != 0 { |
| 2122 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2123 |
} |
| 2124 |
if req.GetPageToken() != "" { |
| 2125 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2126 |
} |
| 2127 |
|
| 2128 |
baseUrl.RawQuery = params.Encode() |
| 2129 |
|
| 2130 |
// Build HTTP headers from client and context metadata. |
| 2131 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2132 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2133 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2134 |
if settings.Path != "" { |
| 2135 |
baseUrl.Path = settings.Path |
| 2136 |
} |
| 2137 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2138 |
if err != nil { |
| 2139 |
return err |
| 2140 |
} |
| 2141 |
httpReq.Header = headers |
| 2142 |
|
| 2143 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListApiOperations") |
| 2144 |
if err != nil { |
| 2145 |
return err |
| 2146 |
} |
| 2147 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2148 |
return err |
| 2149 |
} |
| 2150 |
|
| 2151 |
return nil |
| 2152 |
}, opts...) |
| 2153 |
if e != nil { |
| 2154 |
return nil, "", e |
| 2155 |
} |
| 2156 |
it.Response = resp |
| 2157 |
return resp.GetApiOperations(), resp.GetNextPageToken(), nil |
| 2158 |
} |
| 2159 |
|
| 2160 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2161 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2162 |
if err != nil { |
| 2163 |
return "", err |
| 2164 |
} |
| 2165 |
it.items = append(it.items, items...) |
| 2166 |
return nextPageToken, nil |
| 2167 |
} |
| 2168 |
|
| 2169 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2170 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2171 |
it.pageInfo.Token = req.GetPageToken() |
| 2172 |
|
| 2173 |
return it |
| 2174 |
} |
| 2175 |
|
| 2176 |
// UpdateApiOperation update an operation in an API version. The following fields in the |
| 2177 |
// [ApiOperation resource][google.cloud.apihub.v1.ApiOperation] can be |
| 2178 |
// updated: |
| 2179 |
// |
| 2180 |
// details.description |
| 2181 |
// |
| 2182 |
// details.documentation |
| 2183 |
// |
| 2184 |
// details.http_operation.path |
| 2185 |
// |
| 2186 |
// details.http_operation.method |
| 2187 |
// |
| 2188 |
// details.deprecated |
| 2189 |
// |
| 2190 |
// attributes |
| 2191 |
// |
| 2192 |
// The |
| 2193 |
// update_mask |
| 2194 |
// should be used to specify the fields being updated. |
| 2195 |
// |
| 2196 |
// An operation can be updated only if the operation was created via |
| 2197 |
// CreateApiOperation API. |
| 2198 |
// If the operation was created by parsing the spec, then it can be edited by |
| 2199 |
// updating the spec. |
| 2200 |
func (c *restClient) UpdateApiOperation(ctx context.Context, req *apihubpb.UpdateApiOperationRequest, opts ...gax.CallOption) (*apihubpb.ApiOperation, error) { |
| 2201 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2202 |
body := req.GetApiOperation() |
| 2203 |
jsonReq, err := m.Marshal(body) |
| 2204 |
if err != nil { |
| 2205 |
return nil, err |
| 2206 |
} |
| 2207 |
|
| 2208 |
baseUrl, err := url.Parse(c.endpoint) |
| 2209 |
if err != nil { |
| 2210 |
return nil, err |
| 2211 |
} |
| 2212 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetApiOperation().GetName()) |
| 2213 |
|
| 2214 |
params := url.Values{} |
| 2215 |
params.Add("$alt", "json;enum-encoding=int") |
| 2216 |
if req.GetUpdateMask() != nil { |
| 2217 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2218 |
if err != nil { |
| 2219 |
return nil, err |
| 2220 |
} |
| 2221 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2222 |
} |
| 2223 |
|
| 2224 |
baseUrl.RawQuery = params.Encode() |
| 2225 |
|
| 2226 |
// Build HTTP headers from client and context metadata. |
| 2227 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "api_operation.name", url.QueryEscape(req.GetApiOperation().GetName()))} |
| 2228 |
|
| 2229 |
hds = append(c.xGoogHeaders, hds...) |
| 2230 |
hds = append(hds, "Content-Type", "application/json") |
| 2231 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2232 |
opts = append((*c.CallOptions).UpdateApiOperation[0:len((*c.CallOptions).UpdateApiOperation):len((*c.CallOptions).UpdateApiOperation)], opts...) |
| 2233 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2234 |
resp := &apihubpb.ApiOperation{} |
| 2235 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2236 |
if settings.Path != "" { |
| 2237 |
baseUrl.Path = settings.Path |
| 2238 |
} |
| 2239 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2240 |
if err != nil { |
| 2241 |
return err |
| 2242 |
} |
| 2243 |
httpReq = httpReq.WithContext(ctx) |
| 2244 |
httpReq.Header = headers |
| 2245 |
|
| 2246 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateApiOperation") |
| 2247 |
if err != nil { |
| 2248 |
return err |
| 2249 |
} |
| 2250 |
|
| 2251 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2252 |
return err |
| 2253 |
} |
| 2254 |
|
| 2255 |
return nil |
| 2256 |
}, opts...) |
| 2257 |
if e != nil { |
| 2258 |
return nil, e |
| 2259 |
} |
| 2260 |
return resp, nil |
| 2261 |
} |
| 2262 |
|
| 2263 |
// DeleteApiOperation delete an operation in an API version and we can delete only the |
| 2264 |
// operations created via create API. If the operation was created by parsing |
| 2265 |
// the spec, then it can be deleted by editing or deleting the spec. |
| 2266 |
func (c *restClient) DeleteApiOperation(ctx context.Context, req *apihubpb.DeleteApiOperationRequest, opts ...gax.CallOption) error { |
| 2267 |
baseUrl, err := url.Parse(c.endpoint) |
| 2268 |
if err != nil { |
| 2269 |
return err |
| 2270 |
} |
| 2271 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2272 |
|
| 2273 |
params := url.Values{} |
| 2274 |
params.Add("$alt", "json;enum-encoding=int") |
| 2275 |
|
| 2276 |
baseUrl.RawQuery = params.Encode() |
| 2277 |
|
| 2278 |
// Build HTTP headers from client and context metadata. |
| 2279 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2280 |
|
| 2281 |
hds = append(c.xGoogHeaders, hds...) |
| 2282 |
hds = append(hds, "Content-Type", "application/json") |
| 2283 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2284 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2285 |
if settings.Path != "" { |
| 2286 |
baseUrl.Path = settings.Path |
| 2287 |
} |
| 2288 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 2289 |
if err != nil { |
| 2290 |
return err |
| 2291 |
} |
| 2292 |
httpReq = httpReq.WithContext(ctx) |
| 2293 |
httpReq.Header = headers |
| 2294 |
|
| 2295 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteApiOperation") |
| 2296 |
return err |
| 2297 |
}, opts...) |
| 2298 |
} |
| 2299 |
|
| 2300 |
// GetDefinition get details about a definition in an API version. |
| 2301 |
func (c *restClient) GetDefinition(ctx context.Context, req *apihubpb.GetDefinitionRequest, opts ...gax.CallOption) (*apihubpb.Definition, error) { |
| 2302 |
baseUrl, err := url.Parse(c.endpoint) |
| 2303 |
if err != nil { |
| 2304 |
return nil, err |
| 2305 |
} |
| 2306 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2307 |
|
| 2308 |
params := url.Values{} |
| 2309 |
params.Add("$alt", "json;enum-encoding=int") |
| 2310 |
|
| 2311 |
baseUrl.RawQuery = params.Encode() |
| 2312 |
|
| 2313 |
// Build HTTP headers from client and context metadata. |
| 2314 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2315 |
|
| 2316 |
hds = append(c.xGoogHeaders, hds...) |
| 2317 |
hds = append(hds, "Content-Type", "application/json") |
| 2318 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2319 |
opts = append((*c.CallOptions).GetDefinition[0:len((*c.CallOptions).GetDefinition):len((*c.CallOptions).GetDefinition)], opts...) |
| 2320 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2321 |
resp := &apihubpb.Definition{} |
| 2322 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2323 |
if settings.Path != "" { |
| 2324 |
baseUrl.Path = settings.Path |
| 2325 |
} |
| 2326 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2327 |
if err != nil { |
| 2328 |
return err |
| 2329 |
} |
| 2330 |
httpReq = httpReq.WithContext(ctx) |
| 2331 |
httpReq.Header = headers |
| 2332 |
|
| 2333 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDefinition") |
| 2334 |
if err != nil { |
| 2335 |
return err |
| 2336 |
} |
| 2337 |
|
| 2338 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2339 |
return err |
| 2340 |
} |
| 2341 |
|
| 2342 |
return nil |
| 2343 |
}, opts...) |
| 2344 |
if e != nil { |
| 2345 |
return nil, e |
| 2346 |
} |
| 2347 |
return resp, nil |
| 2348 |
} |
| 2349 |
|
| 2350 |
// CreateDeployment create a deployment resource in the API hub. |
| 2351 |
// Once a deployment resource is created, it can be associated with API |
| 2352 |
// versions. |
| 2353 |
func (c *restClient) CreateDeployment(ctx context.Context, req *apihubpb.CreateDeploymentRequest, opts ...gax.CallOption) (*apihubpb.Deployment, error) { |
| 2354 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2355 |
body := req.GetDeployment() |
| 2356 |
jsonReq, err := m.Marshal(body) |
| 2357 |
if err != nil { |
| 2358 |
return nil, err |
| 2359 |
} |
| 2360 |
|
| 2361 |
baseUrl, err := url.Parse(c.endpoint) |
| 2362 |
if err != nil { |
| 2363 |
return nil, err |
| 2364 |
} |
| 2365 |
baseUrl.Path += fmt.Sprintf("/v1/%v/deployments", req.GetParent()) |
| 2366 |
|
| 2367 |
params := url.Values{} |
| 2368 |
params.Add("$alt", "json;enum-encoding=int") |
| 2369 |
if req.GetDeploymentId() != "" { |
| 2370 |
params.Add("deploymentId", fmt.Sprintf("%v", req.GetDeploymentId())) |
| 2371 |
} |
| 2372 |
|
| 2373 |
baseUrl.RawQuery = params.Encode() |
| 2374 |
|
| 2375 |
// Build HTTP headers from client and context metadata. |
| 2376 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 2377 |
|
| 2378 |
hds = append(c.xGoogHeaders, hds...) |
| 2379 |
hds = append(hds, "Content-Type", "application/json") |
| 2380 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2381 |
opts = append((*c.CallOptions).CreateDeployment[0:len((*c.CallOptions).CreateDeployment):len((*c.CallOptions).CreateDeployment)], opts...) |
| 2382 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2383 |
resp := &apihubpb.Deployment{} |
| 2384 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2385 |
if settings.Path != "" { |
| 2386 |
baseUrl.Path = settings.Path |
| 2387 |
} |
| 2388 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2389 |
if err != nil { |
| 2390 |
return err |
| 2391 |
} |
| 2392 |
httpReq = httpReq.WithContext(ctx) |
| 2393 |
httpReq.Header = headers |
| 2394 |
|
| 2395 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDeployment") |
| 2396 |
if err != nil { |
| 2397 |
return err |
| 2398 |
} |
| 2399 |
|
| 2400 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2401 |
return err |
| 2402 |
} |
| 2403 |
|
| 2404 |
return nil |
| 2405 |
}, opts...) |
| 2406 |
if e != nil { |
| 2407 |
return nil, e |
| 2408 |
} |
| 2409 |
return resp, nil |
| 2410 |
} |
| 2411 |
|
| 2412 |
// GetDeployment get details about a deployment and the API versions linked to it. |
| 2413 |
func (c *restClient) GetDeployment(ctx context.Context, req *apihubpb.GetDeploymentRequest, opts ...gax.CallOption) (*apihubpb.Deployment, error) { |
| 2414 |
baseUrl, err := url.Parse(c.endpoint) |
| 2415 |
if err != nil { |
| 2416 |
return nil, err |
| 2417 |
} |
| 2418 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2419 |
|
| 2420 |
params := url.Values{} |
| 2421 |
params.Add("$alt", "json;enum-encoding=int") |
| 2422 |
|
| 2423 |
baseUrl.RawQuery = params.Encode() |
| 2424 |
|
| 2425 |
// Build HTTP headers from client and context metadata. |
| 2426 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2427 |
|
| 2428 |
hds = append(c.xGoogHeaders, hds...) |
| 2429 |
hds = append(hds, "Content-Type", "application/json") |
| 2430 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2431 |
opts = append((*c.CallOptions).GetDeployment[0:len((*c.CallOptions).GetDeployment):len((*c.CallOptions).GetDeployment)], opts...) |
| 2432 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2433 |
resp := &apihubpb.Deployment{} |
| 2434 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2435 |
if settings.Path != "" { |
| 2436 |
baseUrl.Path = settings.Path |
| 2437 |
} |
| 2438 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2439 |
if err != nil { |
| 2440 |
return err |
| 2441 |
} |
| 2442 |
httpReq = httpReq.WithContext(ctx) |
| 2443 |
httpReq.Header = headers |
| 2444 |
|
| 2445 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDeployment") |
| 2446 |
if err != nil { |
| 2447 |
return err |
| 2448 |
} |
| 2449 |
|
| 2450 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2451 |
return err |
| 2452 |
} |
| 2453 |
|
| 2454 |
return nil |
| 2455 |
}, opts...) |
| 2456 |
if e != nil { |
| 2457 |
return nil, e |
| 2458 |
} |
| 2459 |
return resp, nil |
| 2460 |
} |
| 2461 |
|
| 2462 |
// ListDeployments list deployment resources in the API hub. |
| 2463 |
func (c *restClient) ListDeployments(ctx context.Context, req *apihubpb.ListDeploymentsRequest, opts ...gax.CallOption) *DeploymentIterator { |
| 2464 |
it := &DeploymentIterator{} |
| 2465 |
req = proto.Clone(req).(*apihubpb.ListDeploymentsRequest) |
| 2466 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2467 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Deployment, string, error) { |
| 2468 |
resp := &apihubpb.ListDeploymentsResponse{} |
| 2469 |
if pageToken != "" { |
| 2470 |
req.PageToken = pageToken |
| 2471 |
} |
| 2472 |
if pageSize > math.MaxInt32 { |
| 2473 |
req.PageSize = math.MaxInt32 |
| 2474 |
} else if pageSize != 0 { |
| 2475 |
req.PageSize = int32(pageSize) |
| 2476 |
} |
| 2477 |
baseUrl, err := url.Parse(c.endpoint) |
| 2478 |
if err != nil { |
| 2479 |
return nil, "", err |
| 2480 |
} |
| 2481 |
baseUrl.Path += fmt.Sprintf("/v1/%v/deployments", req.GetParent()) |
| 2482 |
|
| 2483 |
params := url.Values{} |
| 2484 |
params.Add("$alt", "json;enum-encoding=int") |
| 2485 |
if req.GetFilter() != "" { |
| 2486 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 2487 |
} |
| 2488 |
if req.GetPageSize() != 0 { |
| 2489 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2490 |
} |
| 2491 |
if req.GetPageToken() != "" { |
| 2492 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2493 |
} |
| 2494 |
|
| 2495 |
baseUrl.RawQuery = params.Encode() |
| 2496 |
|
| 2497 |
// Build HTTP headers from client and context metadata. |
| 2498 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2499 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2500 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2501 |
if settings.Path != "" { |
| 2502 |
baseUrl.Path = settings.Path |
| 2503 |
} |
| 2504 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2505 |
if err != nil { |
| 2506 |
return err |
| 2507 |
} |
| 2508 |
httpReq.Header = headers |
| 2509 |
|
| 2510 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDeployments") |
| 2511 |
if err != nil { |
| 2512 |
return err |
| 2513 |
} |
| 2514 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2515 |
return err |
| 2516 |
} |
| 2517 |
|
| 2518 |
return nil |
| 2519 |
}, opts...) |
| 2520 |
if e != nil { |
| 2521 |
return nil, "", e |
| 2522 |
} |
| 2523 |
it.Response = resp |
| 2524 |
return resp.GetDeployments(), resp.GetNextPageToken(), nil |
| 2525 |
} |
| 2526 |
|
| 2527 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2528 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2529 |
if err != nil { |
| 2530 |
return "", err |
| 2531 |
} |
| 2532 |
it.items = append(it.items, items...) |
| 2533 |
return nextPageToken, nil |
| 2534 |
} |
| 2535 |
|
| 2536 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2537 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2538 |
it.pageInfo.Token = req.GetPageToken() |
| 2539 |
|
| 2540 |
return it |
| 2541 |
} |
| 2542 |
|
| 2543 |
// UpdateDeployment update a deployment resource in the API hub. The following fields in the |
| 2544 |
// [deployment resource][google.cloud.apihub.v1.Deployment] can be |
| 2545 |
// updated: |
| 2546 |
// |
| 2547 |
// display_name |
| 2548 |
// |
| 2549 |
// description |
| 2550 |
// |
| 2551 |
// documentation |
| 2552 |
// |
| 2553 |
// deployment_type |
| 2554 |
// |
| 2555 |
// resource_uri |
| 2556 |
// |
| 2557 |
// endpoints |
| 2558 |
// |
| 2559 |
// slo |
| 2560 |
// |
| 2561 |
// environment |
| 2562 |
// |
| 2563 |
// attributes |
| 2564 |
// |
| 2565 |
// [source_project] [google.cloud.apihub.v1.Deployment.source_project] |
| 2566 |
// |
| 2567 |
// [source_environment] |
| 2568 |
// [google.cloud.apihub.v1.Deployment.source_environment] |
| 2569 |
// |
| 2570 |
// management_url |
| 2571 |
// |
| 2572 |
// source_uri |
| 2573 |
// The |
| 2574 |
// update_mask |
| 2575 |
// should be used to specify the fields being updated. |
| 2576 |
func (c *restClient) UpdateDeployment(ctx context.Context, req *apihubpb.UpdateDeploymentRequest, opts ...gax.CallOption) (*apihubpb.Deployment, error) { |
| 2577 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2578 |
body := req.GetDeployment() |
| 2579 |
jsonReq, err := m.Marshal(body) |
| 2580 |
if err != nil { |
| 2581 |
return nil, err |
| 2582 |
} |
| 2583 |
|
| 2584 |
baseUrl, err := url.Parse(c.endpoint) |
| 2585 |
if err != nil { |
| 2586 |
return nil, err |
| 2587 |
} |
| 2588 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetDeployment().GetName()) |
| 2589 |
|
| 2590 |
params := url.Values{} |
| 2591 |
params.Add("$alt", "json;enum-encoding=int") |
| 2592 |
if req.GetUpdateMask() != nil { |
| 2593 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2594 |
if err != nil { |
| 2595 |
return nil, err |
| 2596 |
} |
| 2597 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2598 |
} |
| 2599 |
|
| 2600 |
baseUrl.RawQuery = params.Encode() |
| 2601 |
|
| 2602 |
// Build HTTP headers from client and context metadata. |
| 2603 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "deployment.name", url.QueryEscape(req.GetDeployment().GetName()))} |
| 2604 |
|
| 2605 |
hds = append(c.xGoogHeaders, hds...) |
| 2606 |
hds = append(hds, "Content-Type", "application/json") |
| 2607 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2608 |
opts = append((*c.CallOptions).UpdateDeployment[0:len((*c.CallOptions).UpdateDeployment):len((*c.CallOptions).UpdateDeployment)], opts...) |
| 2609 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2610 |
resp := &apihubpb.Deployment{} |
| 2611 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2612 |
if settings.Path != "" { |
| 2613 |
baseUrl.Path = settings.Path |
| 2614 |
} |
| 2615 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2616 |
if err != nil { |
| 2617 |
return err |
| 2618 |
} |
| 2619 |
httpReq = httpReq.WithContext(ctx) |
| 2620 |
httpReq.Header = headers |
| 2621 |
|
| 2622 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateDeployment") |
| 2623 |
if err != nil { |
| 2624 |
return err |
| 2625 |
} |
| 2626 |
|
| 2627 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2628 |
return err |
| 2629 |
} |
| 2630 |
|
| 2631 |
return nil |
| 2632 |
}, opts...) |
| 2633 |
if e != nil { |
| 2634 |
return nil, e |
| 2635 |
} |
| 2636 |
return resp, nil |
| 2637 |
} |
| 2638 |
|
| 2639 |
// DeleteDeployment delete a deployment resource in the API hub. |
| 2640 |
func (c *restClient) DeleteDeployment(ctx context.Context, req *apihubpb.DeleteDeploymentRequest, opts ...gax.CallOption) error { |
| 2641 |
baseUrl, err := url.Parse(c.endpoint) |
| 2642 |
if err != nil { |
| 2643 |
return err |
| 2644 |
} |
| 2645 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2646 |
|
| 2647 |
params := url.Values{} |
| 2648 |
params.Add("$alt", "json;enum-encoding=int") |
| 2649 |
|
| 2650 |
baseUrl.RawQuery = params.Encode() |
| 2651 |
|
| 2652 |
// Build HTTP headers from client and context metadata. |
| 2653 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2654 |
|
| 2655 |
hds = append(c.xGoogHeaders, hds...) |
| 2656 |
hds = append(hds, "Content-Type", "application/json") |
| 2657 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2658 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2659 |
if settings.Path != "" { |
| 2660 |
baseUrl.Path = settings.Path |
| 2661 |
} |
| 2662 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 2663 |
if err != nil { |
| 2664 |
return err |
| 2665 |
} |
| 2666 |
httpReq = httpReq.WithContext(ctx) |
| 2667 |
httpReq.Header = headers |
| 2668 |
|
| 2669 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDeployment") |
| 2670 |
return err |
| 2671 |
}, opts...) |
| 2672 |
} |
| 2673 |
|
| 2674 |
// CreateAttribute create a user defined attribute. |
| 2675 |
// |
| 2676 |
// Certain pre defined attributes are already created by the API hub. These |
| 2677 |
// attributes will have type as SYSTEM_DEFINED and can be listed via |
| 2678 |
// ListAttributes method. |
| 2679 |
// Allowed values for the same can be updated via |
| 2680 |
// UpdateAttribute method. |
| 2681 |
func (c *restClient) CreateAttribute(ctx context.Context, req *apihubpb.CreateAttributeRequest, opts ...gax.CallOption) (*apihubpb.Attribute, error) { |
| 2682 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2683 |
body := req.GetAttribute() |
| 2684 |
jsonReq, err := m.Marshal(body) |
| 2685 |
if err != nil { |
| 2686 |
return nil, err |
| 2687 |
} |
| 2688 |
|
| 2689 |
baseUrl, err := url.Parse(c.endpoint) |
| 2690 |
if err != nil { |
| 2691 |
return nil, err |
| 2692 |
} |
| 2693 |
baseUrl.Path += fmt.Sprintf("/v1/%v/attributes", req.GetParent()) |
| 2694 |
|
| 2695 |
params := url.Values{} |
| 2696 |
params.Add("$alt", "json;enum-encoding=int") |
| 2697 |
if req.GetAttributeId() != "" { |
| 2698 |
params.Add("attributeId", fmt.Sprintf("%v", req.GetAttributeId())) |
| 2699 |
} |
| 2700 |
|
| 2701 |
baseUrl.RawQuery = params.Encode() |
| 2702 |
|
| 2703 |
// Build HTTP headers from client and context metadata. |
| 2704 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 2705 |
|
| 2706 |
hds = append(c.xGoogHeaders, hds...) |
| 2707 |
hds = append(hds, "Content-Type", "application/json") |
| 2708 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2709 |
opts = append((*c.CallOptions).CreateAttribute[0:len((*c.CallOptions).CreateAttribute):len((*c.CallOptions).CreateAttribute)], opts...) |
| 2710 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2711 |
resp := &apihubpb.Attribute{} |
| 2712 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2713 |
if settings.Path != "" { |
| 2714 |
baseUrl.Path = settings.Path |
| 2715 |
} |
| 2716 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2717 |
if err != nil { |
| 2718 |
return err |
| 2719 |
} |
| 2720 |
httpReq = httpReq.WithContext(ctx) |
| 2721 |
httpReq.Header = headers |
| 2722 |
|
| 2723 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAttribute") |
| 2724 |
if err != nil { |
| 2725 |
return err |
| 2726 |
} |
| 2727 |
|
| 2728 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2729 |
return err |
| 2730 |
} |
| 2731 |
|
| 2732 |
return nil |
| 2733 |
}, opts...) |
| 2734 |
if e != nil { |
| 2735 |
return nil, e |
| 2736 |
} |
| 2737 |
return resp, nil |
| 2738 |
} |
| 2739 |
|
| 2740 |
// GetAttribute get details about the attribute. |
| 2741 |
func (c *restClient) GetAttribute(ctx context.Context, req *apihubpb.GetAttributeRequest, opts ...gax.CallOption) (*apihubpb.Attribute, error) { |
| 2742 |
baseUrl, err := url.Parse(c.endpoint) |
| 2743 |
if err != nil { |
| 2744 |
return nil, err |
| 2745 |
} |
| 2746 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2747 |
|
| 2748 |
params := url.Values{} |
| 2749 |
params.Add("$alt", "json;enum-encoding=int") |
| 2750 |
|
| 2751 |
baseUrl.RawQuery = params.Encode() |
| 2752 |
|
| 2753 |
// Build HTTP headers from client and context metadata. |
| 2754 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2755 |
|
| 2756 |
hds = append(c.xGoogHeaders, hds...) |
| 2757 |
hds = append(hds, "Content-Type", "application/json") |
| 2758 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2759 |
opts = append((*c.CallOptions).GetAttribute[0:len((*c.CallOptions).GetAttribute):len((*c.CallOptions).GetAttribute)], opts...) |
| 2760 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2761 |
resp := &apihubpb.Attribute{} |
| 2762 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2763 |
if settings.Path != "" { |
| 2764 |
baseUrl.Path = settings.Path |
| 2765 |
} |
| 2766 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2767 |
if err != nil { |
| 2768 |
return err |
| 2769 |
} |
| 2770 |
httpReq = httpReq.WithContext(ctx) |
| 2771 |
httpReq.Header = headers |
| 2772 |
|
| 2773 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAttribute") |
| 2774 |
if err != nil { |
| 2775 |
return err |
| 2776 |
} |
| 2777 |
|
| 2778 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2779 |
return err |
| 2780 |
} |
| 2781 |
|
| 2782 |
return nil |
| 2783 |
}, opts...) |
| 2784 |
if e != nil { |
| 2785 |
return nil, e |
| 2786 |
} |
| 2787 |
return resp, nil |
| 2788 |
} |
| 2789 |
|
| 2790 |
// UpdateAttribute update the attribute. The following fields in the |
| 2791 |
// [Attribute resource][google.cloud.apihub.v1.Attribute] can be updated: |
| 2792 |
// |
| 2793 |
// display_name |
| 2794 |
// The display name can be updated for user defined attributes only. |
| 2795 |
// |
| 2796 |
// description |
| 2797 |
// The description can be updated for user defined attributes only. |
| 2798 |
// |
| 2799 |
// allowed_values |
| 2800 |
// To update the list of allowed values, clients need to use the fetched list |
| 2801 |
// of allowed values and add or remove values to or from the same list. |
| 2802 |
// The mutable allowed values can be updated for both user defined and System |
| 2803 |
// defined attributes. The immutable allowed values cannot be updated or |
| 2804 |
// deleted. The updated list of allowed values cannot be empty. If an allowed |
| 2805 |
// value that is already used by some resource’s attribute is deleted, then |
| 2806 |
// the association between the resource and the attribute value will also be |
| 2807 |
// deleted. |
| 2808 |
// |
| 2809 |
// cardinality |
| 2810 |
// The cardinality can be updated for user defined attributes only. |
| 2811 |
// Cardinality can only be increased during an update. |
| 2812 |
// |
| 2813 |
// The |
| 2814 |
// update_mask |
| 2815 |
// should be used to specify the fields being updated. |
| 2816 |
func (c *restClient) UpdateAttribute(ctx context.Context, req *apihubpb.UpdateAttributeRequest, opts ...gax.CallOption) (*apihubpb.Attribute, error) { |
| 2817 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2818 |
body := req.GetAttribute() |
| 2819 |
jsonReq, err := m.Marshal(body) |
| 2820 |
if err != nil { |
| 2821 |
return nil, err |
| 2822 |
} |
| 2823 |
|
| 2824 |
baseUrl, err := url.Parse(c.endpoint) |
| 2825 |
if err != nil { |
| 2826 |
return nil, err |
| 2827 |
} |
| 2828 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetAttribute().GetName()) |
| 2829 |
|
| 2830 |
params := url.Values{} |
| 2831 |
params.Add("$alt", "json;enum-encoding=int") |
| 2832 |
if req.GetUpdateMask() != nil { |
| 2833 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2834 |
if err != nil { |
| 2835 |
return nil, err |
| 2836 |
} |
| 2837 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2838 |
} |
| 2839 |
|
| 2840 |
baseUrl.RawQuery = params.Encode() |
| 2841 |
|
| 2842 |
// Build HTTP headers from client and context metadata. |
| 2843 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "attribute.name", url.QueryEscape(req.GetAttribute().GetName()))} |
| 2844 |
|
| 2845 |
hds = append(c.xGoogHeaders, hds...) |
| 2846 |
hds = append(hds, "Content-Type", "application/json") |
| 2847 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2848 |
opts = append((*c.CallOptions).UpdateAttribute[0:len((*c.CallOptions).UpdateAttribute):len((*c.CallOptions).UpdateAttribute)], opts...) |
| 2849 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2850 |
resp := &apihubpb.Attribute{} |
| 2851 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2852 |
if settings.Path != "" { |
| 2853 |
baseUrl.Path = settings.Path |
| 2854 |
} |
| 2855 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2856 |
if err != nil { |
| 2857 |
return err |
| 2858 |
} |
| 2859 |
httpReq = httpReq.WithContext(ctx) |
| 2860 |
httpReq.Header = headers |
| 2861 |
|
| 2862 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAttribute") |
| 2863 |
if err != nil { |
| 2864 |
return err |
| 2865 |
} |
| 2866 |
|
| 2867 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2868 |
return err |
| 2869 |
} |
| 2870 |
|
| 2871 |
return nil |
| 2872 |
}, opts...) |
| 2873 |
if e != nil { |
| 2874 |
return nil, e |
| 2875 |
} |
| 2876 |
return resp, nil |
| 2877 |
} |
| 2878 |
|
| 2879 |
// DeleteAttribute delete an attribute. |
| 2880 |
// |
| 2881 |
// Note: System defined attributes cannot be deleted. All |
| 2882 |
// associations of the attribute being deleted with any API hub resource will |
| 2883 |
// also get deleted. |
| 2884 |
func (c *restClient) DeleteAttribute(ctx context.Context, req *apihubpb.DeleteAttributeRequest, opts ...gax.CallOption) error { |
| 2885 |
baseUrl, err := url.Parse(c.endpoint) |
| 2886 |
if err != nil { |
| 2887 |
return err |
| 2888 |
} |
| 2889 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2890 |
|
| 2891 |
params := url.Values{} |
| 2892 |
params.Add("$alt", "json;enum-encoding=int") |
| 2893 |
|
| 2894 |
baseUrl.RawQuery = params.Encode() |
| 2895 |
|
| 2896 |
// Build HTTP headers from client and context metadata. |
| 2897 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2898 |
|
| 2899 |
hds = append(c.xGoogHeaders, hds...) |
| 2900 |
hds = append(hds, "Content-Type", "application/json") |
| 2901 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2902 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2903 |
if settings.Path != "" { |
| 2904 |
baseUrl.Path = settings.Path |
| 2905 |
} |
| 2906 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 2907 |
if err != nil { |
| 2908 |
return err |
| 2909 |
} |
| 2910 |
httpReq = httpReq.WithContext(ctx) |
| 2911 |
httpReq.Header = headers |
| 2912 |
|
| 2913 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAttribute") |
| 2914 |
return err |
| 2915 |
}, opts...) |
| 2916 |
} |
| 2917 |
|
| 2918 |
// ListAttributes list all attributes. |
| 2919 |
func (c *restClient) ListAttributes(ctx context.Context, req *apihubpb.ListAttributesRequest, opts ...gax.CallOption) *AttributeIterator { |
| 2920 |
it := &AttributeIterator{} |
| 2921 |
req = proto.Clone(req).(*apihubpb.ListAttributesRequest) |
| 2922 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2923 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Attribute, string, error) { |
| 2924 |
resp := &apihubpb.ListAttributesResponse{} |
| 2925 |
if pageToken != "" { |
| 2926 |
req.PageToken = pageToken |
| 2927 |
} |
| 2928 |
if pageSize > math.MaxInt32 { |
| 2929 |
req.PageSize = math.MaxInt32 |
| 2930 |
} else if pageSize != 0 { |
| 2931 |
req.PageSize = int32(pageSize) |
| 2932 |
} |
| 2933 |
baseUrl, err := url.Parse(c.endpoint) |
| 2934 |
if err != nil { |
| 2935 |
return nil, "", err |
| 2936 |
} |
| 2937 |
baseUrl.Path += fmt.Sprintf("/v1/%v/attributes", req.GetParent()) |
| 2938 |
|
| 2939 |
params := url.Values{} |
| 2940 |
params.Add("$alt", "json;enum-encoding=int") |
| 2941 |
if req.GetFilter() != "" { |
| 2942 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 2943 |
} |
| 2944 |
if req.GetPageSize() != 0 { |
| 2945 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2946 |
} |
| 2947 |
if req.GetPageToken() != "" { |
| 2948 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2949 |
} |
| 2950 |
|
| 2951 |
baseUrl.RawQuery = params.Encode() |
| 2952 |
|
| 2953 |
// Build HTTP headers from client and context metadata. |
| 2954 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2955 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2956 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2957 |
if settings.Path != "" { |
| 2958 |
baseUrl.Path = settings.Path |
| 2959 |
} |
| 2960 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2961 |
if err != nil { |
| 2962 |
return err |
| 2963 |
} |
| 2964 |
httpReq.Header = headers |
| 2965 |
|
| 2966 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAttributes") |
| 2967 |
if err != nil { |
| 2968 |
return err |
| 2969 |
} |
| 2970 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2971 |
return err |
| 2972 |
} |
| 2973 |
|
| 2974 |
return nil |
| 2975 |
}, opts...) |
| 2976 |
if e != nil { |
| 2977 |
return nil, "", e |
| 2978 |
} |
| 2979 |
it.Response = resp |
| 2980 |
return resp.GetAttributes(), resp.GetNextPageToken(), nil |
| 2981 |
} |
| 2982 |
|
| 2983 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2984 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2985 |
if err != nil { |
| 2986 |
return "", err |
| 2987 |
} |
| 2988 |
it.items = append(it.items, items...) |
| 2989 |
return nextPageToken, nil |
| 2990 |
} |
| 2991 |
|
| 2992 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2993 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2994 |
it.pageInfo.Token = req.GetPageToken() |
| 2995 |
|
| 2996 |
return it |
| 2997 |
} |
| 2998 |
|
| 2999 |
// SearchResources search across API-Hub resources. |
| 3000 |
func (c *restClient) SearchResources(ctx context.Context, req *apihubpb.SearchResourcesRequest, opts ...gax.CallOption) *SearchResultIterator { |
| 3001 |
it := &SearchResultIterator{} |
| 3002 |
req = proto.Clone(req).(*apihubpb.SearchResourcesRequest) |
| 3003 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 3004 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3005 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.SearchResult, string, error) { |
| 3006 |
resp := &apihubpb.SearchResourcesResponse{} |
| 3007 |
if pageToken != "" { |
| 3008 |
req.PageToken = pageToken |
| 3009 |
} |
| 3010 |
if pageSize > math.MaxInt32 { |
| 3011 |
req.PageSize = math.MaxInt32 |
| 3012 |
} else if pageSize != 0 { |
| 3013 |
req.PageSize = int32(pageSize) |
| 3014 |
} |
| 3015 |
jsonReq, err := m.Marshal(req) |
| 3016 |
if err != nil { |
| 3017 |
return nil, "", err |
| 3018 |
} |
| 3019 |
|
| 3020 |
baseUrl, err := url.Parse(c.endpoint) |
| 3021 |
if err != nil { |
| 3022 |
return nil, "", err |
| 3023 |
} |
| 3024 |
baseUrl.Path += fmt.Sprintf("/v1/%v:searchResources", req.GetLocation()) |
| 3025 |
|
| 3026 |
params := url.Values{} |
| 3027 |
params.Add("$alt", "json;enum-encoding=int") |
| 3028 |
|
| 3029 |
baseUrl.RawQuery = params.Encode() |
| 3030 |
|
| 3031 |
// Build HTTP headers from client and context metadata. |
| 3032 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 3033 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3034 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3035 |
if settings.Path != "" { |
| 3036 |
baseUrl.Path = settings.Path |
| 3037 |
} |
| 3038 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 3039 |
if err != nil { |
| 3040 |
return err |
| 3041 |
} |
| 3042 |
httpReq.Header = headers |
| 3043 |
|
| 3044 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SearchResources") |
| 3045 |
if err != nil { |
| 3046 |
return err |
| 3047 |
} |
| 3048 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3049 |
return err |
| 3050 |
} |
| 3051 |
|
| 3052 |
return nil |
| 3053 |
}, opts...) |
| 3054 |
if e != nil { |
| 3055 |
return nil, "", e |
| 3056 |
} |
| 3057 |
it.Response = resp |
| 3058 |
return resp.GetSearchResults(), resp.GetNextPageToken(), nil |
| 3059 |
} |
| 3060 |
|
| 3061 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 3062 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 3063 |
if err != nil { |
| 3064 |
return "", err |
| 3065 |
} |
| 3066 |
it.items = append(it.items, items...) |
| 3067 |
return nextPageToken, nil |
| 3068 |
} |
| 3069 |
|
| 3070 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 3071 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 3072 |
it.pageInfo.Token = req.GetPageToken() |
| 3073 |
|
| 3074 |
return it |
| 3075 |
} |
| 3076 |
|
| 3077 |
// CreateExternalApi create an External API resource in the API hub. |
| 3078 |
func (c *restClient) CreateExternalApi(ctx context.Context, req *apihubpb.CreateExternalApiRequest, opts ...gax.CallOption) (*apihubpb.ExternalApi, error) { |
| 3079 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 3080 |
body := req.GetExternalApi() |
| 3081 |
jsonReq, err := m.Marshal(body) |
| 3082 |
if err != nil { |
| 3083 |
return nil, err |
| 3084 |
} |
| 3085 |
|
| 3086 |
baseUrl, err := url.Parse(c.endpoint) |
| 3087 |
if err != nil { |
| 3088 |
return nil, err |
| 3089 |
} |
| 3090 |
baseUrl.Path += fmt.Sprintf("/v1/%v/externalApis", req.GetParent()) |
| 3091 |
|
| 3092 |
params := url.Values{} |
| 3093 |
params.Add("$alt", "json;enum-encoding=int") |
| 3094 |
if req.GetExternalApiId() != "" { |
| 3095 |
params.Add("externalApiId", fmt.Sprintf("%v", req.GetExternalApiId())) |
| 3096 |
} |
| 3097 |
|
| 3098 |
baseUrl.RawQuery = params.Encode() |
| 3099 |
|
| 3100 |
// Build HTTP headers from client and context metadata. |
| 3101 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 3102 |
|
| 3103 |
hds = append(c.xGoogHeaders, hds...) |
| 3104 |
hds = append(hds, "Content-Type", "application/json") |
| 3105 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3106 |
opts = append((*c.CallOptions).CreateExternalApi[0:len((*c.CallOptions).CreateExternalApi):len((*c.CallOptions).CreateExternalApi)], opts...) |
| 3107 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3108 |
resp := &apihubpb.ExternalApi{} |
| 3109 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3110 |
if settings.Path != "" { |
| 3111 |
baseUrl.Path = settings.Path |
| 3112 |
} |
| 3113 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 3114 |
if err != nil { |
| 3115 |
return err |
| 3116 |
} |
| 3117 |
httpReq = httpReq.WithContext(ctx) |
| 3118 |
httpReq.Header = headers |
| 3119 |
|
| 3120 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateExternalApi") |
| 3121 |
if err != nil { |
| 3122 |
return err |
| 3123 |
} |
| 3124 |
|
| 3125 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3126 |
return err |
| 3127 |
} |
| 3128 |
|
| 3129 |
return nil |
| 3130 |
}, opts...) |
| 3131 |
if e != nil { |
| 3132 |
return nil, e |
| 3133 |
} |
| 3134 |
return resp, nil |
| 3135 |
} |
| 3136 |
|
| 3137 |
// GetExternalApi get details about an External API resource in the API hub. |
| 3138 |
func (c *restClient) GetExternalApi(ctx context.Context, req *apihubpb.GetExternalApiRequest, opts ...gax.CallOption) (*apihubpb.ExternalApi, error) { |
| 3139 |
baseUrl, err := url.Parse(c.endpoint) |
| 3140 |
if err != nil { |
| 3141 |
return nil, err |
| 3142 |
} |
| 3143 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 3144 |
|
| 3145 |
params := url.Values{} |
| 3146 |
params.Add("$alt", "json;enum-encoding=int") |
| 3147 |
|
| 3148 |
baseUrl.RawQuery = params.Encode() |
| 3149 |
|
| 3150 |
// Build HTTP headers from client and context metadata. |
| 3151 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 3152 |
|
| 3153 |
hds = append(c.xGoogHeaders, hds...) |
| 3154 |
hds = append(hds, "Content-Type", "application/json") |
| 3155 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3156 |
opts = append((*c.CallOptions).GetExternalApi[0:len((*c.CallOptions).GetExternalApi):len((*c.CallOptions).GetExternalApi)], opts...) |
| 3157 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3158 |
resp := &apihubpb.ExternalApi{} |
| 3159 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3160 |
if settings.Path != "" { |
| 3161 |
baseUrl.Path = settings.Path |
| 3162 |
} |
| 3163 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 3164 |
if err != nil { |
| 3165 |
return err |
| 3166 |
} |
| 3167 |
httpReq = httpReq.WithContext(ctx) |
| 3168 |
httpReq.Header = headers |
| 3169 |
|
| 3170 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetExternalApi") |
| 3171 |
if err != nil { |
| 3172 |
return err |
| 3173 |
} |
| 3174 |
|
| 3175 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3176 |
return err |
| 3177 |
} |
| 3178 |
|
| 3179 |
return nil |
| 3180 |
}, opts...) |
| 3181 |
if e != nil { |
| 3182 |
return nil, e |
| 3183 |
} |
| 3184 |
return resp, nil |
| 3185 |
} |
| 3186 |
|
| 3187 |
// UpdateExternalApi update an External API resource in the API hub. The following fields can be |
| 3188 |
// updated: |
| 3189 |
// |
| 3190 |
// display_name |
| 3191 |
// |
| 3192 |
// description |
| 3193 |
// |
| 3194 |
// documentation |
| 3195 |
// |
| 3196 |
// endpoints |
| 3197 |
// |
| 3198 |
// paths |
| 3199 |
// |
| 3200 |
// The |
| 3201 |
// update_mask |
| 3202 |
// should be used to specify the fields being updated. |
| 3203 |
func (c *restClient) UpdateExternalApi(ctx context.Context, req *apihubpb.UpdateExternalApiRequest, opts ...gax.CallOption) (*apihubpb.ExternalApi, error) { |
| 3204 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 3205 |
body := req.GetExternalApi() |
| 3206 |
jsonReq, err := m.Marshal(body) |
| 3207 |
if err != nil { |
| 3208 |
return nil, err |
| 3209 |
} |
| 3210 |
|
| 3211 |
baseUrl, err := url.Parse(c.endpoint) |
| 3212 |
if err != nil { |
| 3213 |
return nil, err |
| 3214 |
} |
| 3215 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetExternalApi().GetName()) |
| 3216 |
|
| 3217 |
params := url.Values{} |
| 3218 |
params.Add("$alt", "json;enum-encoding=int") |
| 3219 |
if req.GetUpdateMask() != nil { |
| 3220 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 3221 |
if err != nil { |
| 3222 |
return nil, err |
| 3223 |
} |
| 3224 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 3225 |
} |
| 3226 |
|
| 3227 |
baseUrl.RawQuery = params.Encode() |
| 3228 |
|
| 3229 |
// Build HTTP headers from client and context metadata. |
| 3230 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "external_api.name", url.QueryEscape(req.GetExternalApi().GetName()))} |
| 3231 |
|
| 3232 |
hds = append(c.xGoogHeaders, hds...) |
| 3233 |
hds = append(hds, "Content-Type", "application/json") |
| 3234 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3235 |
opts = append((*c.CallOptions).UpdateExternalApi[0:len((*c.CallOptions).UpdateExternalApi):len((*c.CallOptions).UpdateExternalApi)], opts...) |
| 3236 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3237 |
resp := &apihubpb.ExternalApi{} |
| 3238 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3239 |
if settings.Path != "" { |
| 3240 |
baseUrl.Path = settings.Path |
| 3241 |
} |
| 3242 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 3243 |
if err != nil { |
| 3244 |
return err |
| 3245 |
} |
| 3246 |
httpReq = httpReq.WithContext(ctx) |
| 3247 |
httpReq.Header = headers |
| 3248 |
|
| 3249 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateExternalApi") |
| 3250 |
if err != nil { |
| 3251 |
return err |
| 3252 |
} |
| 3253 |
|
| 3254 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3255 |
return err |
| 3256 |
} |
| 3257 |
|
| 3258 |
return nil |
| 3259 |
}, opts...) |
| 3260 |
if e != nil { |
| 3261 |
return nil, e |
| 3262 |
} |
| 3263 |
return resp, nil |
| 3264 |
} |
| 3265 |
|
| 3266 |
// DeleteExternalApi delete an External API resource in the API hub. |
| 3267 |
func (c *restClient) DeleteExternalApi(ctx context.Context, req *apihubpb.DeleteExternalApiRequest, opts ...gax.CallOption) error { |
| 3268 |
baseUrl, err := url.Parse(c.endpoint) |
| 3269 |
if err != nil { |
| 3270 |
return err |
| 3271 |
} |
| 3272 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 3273 |
|
| 3274 |
params := url.Values{} |
| 3275 |
params.Add("$alt", "json;enum-encoding=int") |
| 3276 |
|
| 3277 |
baseUrl.RawQuery = params.Encode() |
| 3278 |
|
| 3279 |
// Build HTTP headers from client and context metadata. |
| 3280 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 3281 |
|
| 3282 |
hds = append(c.xGoogHeaders, hds...) |
| 3283 |
hds = append(hds, "Content-Type", "application/json") |
| 3284 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3285 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3286 |
if settings.Path != "" { |
| 3287 |
baseUrl.Path = settings.Path |
| 3288 |
} |
| 3289 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 3290 |
if err != nil { |
| 3291 |
return err |
| 3292 |
} |
| 3293 |
httpReq = httpReq.WithContext(ctx) |
| 3294 |
httpReq.Header = headers |
| 3295 |
|
| 3296 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteExternalApi") |
| 3297 |
return err |
| 3298 |
}, opts...) |
| 3299 |
} |
| 3300 |
|
| 3301 |
// ListExternalApis list External API resources in the API hub. |
| 3302 |
func (c *restClient) ListExternalApis(ctx context.Context, req *apihubpb.ListExternalApisRequest, opts ...gax.CallOption) *ExternalApiIterator { |
| 3303 |
it := &ExternalApiIterator{} |
| 3304 |
req = proto.Clone(req).(*apihubpb.ListExternalApisRequest) |
| 3305 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3306 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.ExternalApi, string, error) { |
| 3307 |
resp := &apihubpb.ListExternalApisResponse{} |
| 3308 |
if pageToken != "" { |
| 3309 |
req.PageToken = pageToken |
| 3310 |
} |
| 3311 |
if pageSize > math.MaxInt32 { |
| 3312 |
req.PageSize = math.MaxInt32 |
| 3313 |
} else if pageSize != 0 { |
| 3314 |
req.PageSize = int32(pageSize) |
| 3315 |
} |
| 3316 |
baseUrl, err := url.Parse(c.endpoint) |
| 3317 |
if err != nil { |
| 3318 |
return nil, "", err |
| 3319 |
} |
| 3320 |
baseUrl.Path += fmt.Sprintf("/v1/%v/externalApis", req.GetParent()) |
| 3321 |
|
| 3322 |
params := url.Values{} |
| 3323 |
params.Add("$alt", "json;enum-encoding=int") |
| 3324 |
if req.GetPageSize() != 0 { |
| 3325 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 3326 |
} |
| 3327 |
if req.GetPageToken() != "" { |
| 3328 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 3329 |
} |
| 3330 |
|
| 3331 |
baseUrl.RawQuery = params.Encode() |
| 3332 |
|
| 3333 |
// Build HTTP headers from client and context metadata. |
| 3334 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 3335 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3336 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3337 |
if settings.Path != "" { |
| 3338 |
baseUrl.Path = settings.Path |
| 3339 |
} |
| 3340 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 3341 |
if err != nil { |
| 3342 |
return err |
| 3343 |
} |
| 3344 |
httpReq.Header = headers |
| 3345 |
|
| 3346 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListExternalApis") |
| 3347 |
if err != nil { |
| 3348 |
return err |
| 3349 |
} |
| 3350 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3351 |
return err |
| 3352 |
} |
| 3353 |
|
| 3354 |
return nil |
| 3355 |
}, opts...) |
| 3356 |
if e != nil { |
| 3357 |
return nil, "", e |
| 3358 |
} |
| 3359 |
it.Response = resp |
| 3360 |
return resp.GetExternalApis(), resp.GetNextPageToken(), nil |
| 3361 |
} |
| 3362 |
|
| 3363 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 3364 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 3365 |
if err != nil { |
| 3366 |
return "", err |
| 3367 |
} |
| 3368 |
it.items = append(it.items, items...) |
| 3369 |
return nextPageToken, nil |
| 3370 |
} |
| 3371 |
|
| 3372 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 3373 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 3374 |
it.pageInfo.Token = req.GetPageToken() |
| 3375 |
|
| 3376 |
return it |
| 3377 |
} |
| 3378 |
|
| 3379 |
// GetLocation gets information about a location. |
| 3380 |
func (c *restClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 3381 |
baseUrl, err := url.Parse(c.endpoint) |
| 3382 |
if err != nil { |
| 3383 |
return nil, err |
| 3384 |
} |
| 3385 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 3386 |
|
| 3387 |
params := url.Values{} |
| 3388 |
params.Add("$alt", "json;enum-encoding=int") |
| 3389 |
|
| 3390 |
baseUrl.RawQuery = params.Encode() |
| 3391 |
|
| 3392 |
// Build HTTP headers from client and context metadata. |
| 3393 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 3394 |
|
| 3395 |
hds = append(c.xGoogHeaders, hds...) |
| 3396 |
hds = append(hds, "Content-Type", "application/json") |
| 3397 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3398 |
opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) |
| 3399 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3400 |
resp := &locationpb.Location{} |
| 3401 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3402 |
if settings.Path != "" { |
| 3403 |
baseUrl.Path = settings.Path |
| 3404 |
} |
| 3405 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 3406 |
if err != nil { |
| 3407 |
return err |
| 3408 |
} |
| 3409 |
httpReq = httpReq.WithContext(ctx) |
| 3410 |
httpReq.Header = headers |
| 3411 |
|
| 3412 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") |
| 3413 |
if err != nil { |
| 3414 |
return err |
| 3415 |
} |
| 3416 |
|
| 3417 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3418 |
return err |
| 3419 |
} |
| 3420 |
|
| 3421 |
return nil |
| 3422 |
}, opts...) |
| 3423 |
if e != nil { |
| 3424 |
return nil, e |
| 3425 |
} |
| 3426 |
return resp, nil |
| 3427 |
} |
| 3428 |
|
| 3429 |
// ListLocations lists information about the supported locations for this service. |
| 3430 |
func (c *restClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 3431 |
it := &LocationIterator{} |
| 3432 |
req = proto.Clone(req).(*locationpb.ListLocationsRequest) |
| 3433 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3434 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { |
| 3435 |
resp := &locationpb.ListLocationsResponse{} |
| 3436 |
if pageToken != "" { |
| 3437 |
req.PageToken = pageToken |
| 3438 |
} |
| 3439 |
if pageSize > math.MaxInt32 { |
| 3440 |
req.PageSize = math.MaxInt32 |
| 3441 |
} else if pageSize != 0 { |
| 3442 |
req.PageSize = int32(pageSize) |
| 3443 |
} |
| 3444 |
baseUrl, err := url.Parse(c.endpoint) |
| 3445 |
if err != nil { |
| 3446 |
return nil, "", err |
| 3447 |
} |
| 3448 |
baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName()) |
| 3449 |
|
| 3450 |
params := url.Values{} |
| 3451 |
params.Add("$alt", "json;enum-encoding=int") |
| 3452 |
if req.GetFilter() != "" { |
| 3453 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 3454 |
} |
| 3455 |
if req.GetPageSize() != 0 { |
| 3456 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 3457 |
} |
| 3458 |
if req.GetPageToken() != "" { |
| 3459 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 3460 |
} |
| 3461 |
|
| 3462 |
baseUrl.RawQuery = params.Encode() |
| 3463 |
|
| 3464 |
// Build HTTP headers from client and context metadata. |
| 3465 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 3466 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3467 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3468 |
if settings.Path != "" { |
| 3469 |
baseUrl.Path = settings.Path |
| 3470 |
} |
| 3471 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 3472 |
if err != nil { |
| 3473 |
return err |
| 3474 |
} |
| 3475 |
httpReq.Header = headers |
| 3476 |
|
| 3477 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") |
| 3478 |
if err != nil { |
| 3479 |
return err |
| 3480 |
} |
| 3481 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3482 |
return err |
| 3483 |
} |
| 3484 |
|
| 3485 |
return nil |
| 3486 |
}, opts...) |
| 3487 |
if e != nil { |
| 3488 |
return nil, "", e |
| 3489 |
} |
| 3490 |
it.Response = resp |
| 3491 |
return resp.GetLocations(), resp.GetNextPageToken(), nil |
| 3492 |
} |
| 3493 |
|
| 3494 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 3495 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 3496 |
if err != nil { |
| 3497 |
return "", err |
| 3498 |
} |
| 3499 |
it.items = append(it.items, items...) |
| 3500 |
return nextPageToken, nil |
| 3501 |
} |
| 3502 |
|
| 3503 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 3504 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 3505 |
it.pageInfo.Token = req.GetPageToken() |
| 3506 |
|
| 3507 |
return it |
| 3508 |
} |
| 3509 |
|
| 3510 |
// CancelOperation is a utility method from google.longrunning.Operations. |
| 3511 |
func (c *restClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 3512 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 3513 |
jsonReq, err := m.Marshal(req) |
| 3514 |
if err != nil { |
| 3515 |
return err |
| 3516 |
} |
| 3517 |
|
| 3518 |
baseUrl, err := url.Parse(c.endpoint) |
| 3519 |
if err != nil { |
| 3520 |
return err |
| 3521 |
} |
| 3522 |
baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName()) |
| 3523 |
|
| 3524 |
params := url.Values{} |
| 3525 |
params.Add("$alt", "json;enum-encoding=int") |
| 3526 |
|
| 3527 |
baseUrl.RawQuery = params.Encode() |
| 3528 |
|
| 3529 |
// Build HTTP headers from client and context metadata. |
| 3530 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 3531 |
|
| 3532 |
hds = append(c.xGoogHeaders, hds...) |
| 3533 |
hds = append(hds, "Content-Type", "application/json") |
| 3534 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3535 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3536 |
if settings.Path != "" { |
| 3537 |
baseUrl.Path = settings.Path |
| 3538 |
} |
| 3539 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 3540 |
if err != nil { |
| 3541 |
return err |
| 3542 |
} |
| 3543 |
httpReq = httpReq.WithContext(ctx) |
| 3544 |
httpReq.Header = headers |
| 3545 |
|
| 3546 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation") |
| 3547 |
return err |
| 3548 |
}, opts...) |
| 3549 |
} |
| 3550 |
|
| 3551 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 3552 |
func (c *restClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 3553 |
baseUrl, err := url.Parse(c.endpoint) |
| 3554 |
if err != nil { |
| 3555 |
return err |
| 3556 |
} |
| 3557 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 3558 |
|
| 3559 |
params := url.Values{} |
| 3560 |
params.Add("$alt", "json;enum-encoding=int") |
| 3561 |
|
| 3562 |
baseUrl.RawQuery = params.Encode() |
| 3563 |
|
| 3564 |
// Build HTTP headers from client and context metadata. |
| 3565 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 3566 |
|
| 3567 |
hds = append(c.xGoogHeaders, hds...) |
| 3568 |
hds = append(hds, "Content-Type", "application/json") |
| 3569 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3570 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3571 |
if settings.Path != "" { |
| 3572 |
baseUrl.Path = settings.Path |
| 3573 |
} |
| 3574 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 3575 |
if err != nil { |
| 3576 |
return err |
| 3577 |
} |
| 3578 |
httpReq = httpReq.WithContext(ctx) |
| 3579 |
httpReq.Header = headers |
| 3580 |
|
| 3581 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") |
| 3582 |
return err |
| 3583 |
}, opts...) |
| 3584 |
} |
| 3585 |
|
| 3586 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 3587 |
func (c *restClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 3588 |
baseUrl, err := url.Parse(c.endpoint) |
| 3589 |
if err != nil { |
| 3590 |
return nil, err |
| 3591 |
} |
| 3592 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 3593 |
|
| 3594 |
params := url.Values{} |
| 3595 |
params.Add("$alt", "json;enum-encoding=int") |
| 3596 |
|
| 3597 |
baseUrl.RawQuery = params.Encode() |
| 3598 |
|
| 3599 |
// Build HTTP headers from client and context metadata. |
| 3600 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 3601 |
|
| 3602 |
hds = append(c.xGoogHeaders, hds...) |
| 3603 |
hds = append(hds, "Content-Type", "application/json") |
| 3604 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3605 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 3606 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3607 |
resp := &longrunningpb.Operation{} |
| 3608 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3609 |
if settings.Path != "" { |
| 3610 |
baseUrl.Path = settings.Path |
| 3611 |
} |
| 3612 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 3613 |
if err != nil { |
| 3614 |
return err |
| 3615 |
} |
| 3616 |
httpReq = httpReq.WithContext(ctx) |
| 3617 |
httpReq.Header = headers |
| 3618 |
|
| 3619 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") |
| 3620 |
if err != nil { |
| 3621 |
return err |
| 3622 |
} |
| 3623 |
|
| 3624 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3625 |
return err |
| 3626 |
} |
| 3627 |
|
| 3628 |
return nil |
| 3629 |
}, opts...) |
| 3630 |
if e != nil { |
| 3631 |
return nil, e |
| 3632 |
} |
| 3633 |
return resp, nil |
| 3634 |
} |
| 3635 |
|
| 3636 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 3637 |
func (c *restClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 3638 |
it := &OperationIterator{} |
| 3639 |
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| 3640 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 3641 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| 3642 |
resp := &longrunningpb.ListOperationsResponse{} |
| 3643 |
if pageToken != "" { |
| 3644 |
req.PageToken = pageToken |
| 3645 |
} |
| 3646 |
if pageSize > math.MaxInt32 { |
| 3647 |
req.PageSize = math.MaxInt32 |
| 3648 |
} else if pageSize != 0 { |
| 3649 |
req.PageSize = int32(pageSize) |
| 3650 |
} |
| 3651 |
baseUrl, err := url.Parse(c.endpoint) |
| 3652 |
if err != nil { |
| 3653 |
return nil, "", err |
| 3654 |
} |
| 3655 |
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName()) |
| 3656 |
|
| 3657 |
params := url.Values{} |
| 3658 |
params.Add("$alt", "json;enum-encoding=int") |
| 3659 |
if req.GetFilter() != "" { |
| 3660 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 3661 |
} |
| 3662 |
if req.GetPageSize() != 0 { |
| 3663 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 3664 |
} |
| 3665 |
if req.GetPageToken() != "" { |
| 3666 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 3667 |
} |
| 3668 |
|
| 3669 |
baseUrl.RawQuery = params.Encode() |
| 3670 |
|
| 3671 |
// Build HTTP headers from client and context metadata. |
| 3672 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 3673 |
headers := gax.BuildHeaders(ctx, hds...) |
| 3674 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 3675 |
if settings.Path != "" { |
| 3676 |
baseUrl.Path = settings.Path |
| 3677 |
} |
| 3678 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 3679 |
if err != nil { |
| 3680 |
return err |
| 3681 |
} |
| 3682 |
httpReq.Header = headers |
| 3683 |
|
| 3684 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") |
| 3685 |
if err != nil { |
| 3686 |
return err |
| 3687 |
} |
| 3688 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 3689 |
return err |
| 3690 |
} |
| 3691 |
|
| 3692 |
return nil |
| 3693 |
}, opts...) |
| 3694 |
if e != nil { |
| 3695 |
return nil, "", e |
| 3696 |
} |
| 3697 |
it.Response = resp |
| 3698 |
return resp.GetOperations(), resp.GetNextPageToken(), nil |
| 3699 |
} |
| 3700 |
|
| 3701 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 3702 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 3703 |
if err != nil { |
| 3704 |
return "", err |
| 3705 |
} |
| 3706 |
it.items = append(it.items, items...) |
| 3707 |
return nextPageToken, nil |
| 3708 |
} |
| 3709 |
|
| 3710 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 3711 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 3712 |
it.pageInfo.Token = req.GetPageToken() |
| 3713 |
|
| 3714 |
return it |
| 3715 |
} |