| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package apigeeregistry |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"time" |
| 22 |
|
| 23 |
apigeeregistrypb "cloud.google.com/go/apigeeregistry/apiv1/apigeeregistrypb" |
| 24 |
"cloud.google.com/go/longrunning" |
| 25 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 26 |
gax "github.com/googleapis/gax-go/v2" |
| 27 |
"google.golang.org/api/iterator" |
| 28 |
locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| 29 |
) |
| 30 |
|
| 31 |
|
| 32 |
type CreateInstanceOperation struct { |
| 33 |
lro *longrunning.Operation |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
func (op *CreateInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*apigeeregistrypb.Instance, error) { |
| 40 |
var resp apigeeregistrypb.Instance |
| 41 |
if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { |
| 42 |
return nil, err |
| 43 |
} |
| 44 |
return &resp, nil |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
func (op *CreateInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*apigeeregistrypb.Instance, error) { |
| 57 |
var resp apigeeregistrypb.Instance |
| 58 |
if err := op.lro.Poll(ctx, &resp, opts...); err != nil { |
| 59 |
return nil, err |
| 60 |
} |
| 61 |
if !op.Done() { |
| 62 |
return nil, nil |
| 63 |
} |
| 64 |
return &resp, nil |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
func (op *CreateInstanceOperation) Metadata() (*apigeeregistrypb.OperationMetadata, error) { |
| 72 |
var meta apigeeregistrypb.OperationMetadata |
| 73 |
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { |
| 74 |
return nil, nil |
| 75 |
} else if err != nil { |
| 76 |
return nil, err |
| 77 |
} |
| 78 |
return &meta, nil |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
func (op *CreateInstanceOperation) Done() bool { |
| 83 |
return op.lro.Done() |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
func (op *CreateInstanceOperation) Name() string { |
| 89 |
return op.lro.Name() |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
type DeleteInstanceOperation struct { |
| 94 |
lro *longrunning.Operation |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
func (op *DeleteInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { |
| 101 |
return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
func (op *DeleteInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { |
| 114 |
return op.lro.Poll(ctx, nil, opts...) |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
func (op *DeleteInstanceOperation) Metadata() (*apigeeregistrypb.OperationMetadata, error) { |
| 122 |
var meta apigeeregistrypb.OperationMetadata |
| 123 |
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { |
| 124 |
return nil, nil |
| 125 |
} else if err != nil { |
| 126 |
return nil, err |
| 127 |
} |
| 128 |
return &meta, nil |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
func (op *DeleteInstanceOperation) Done() bool { |
| 133 |
return op.lro.Done() |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
func (op *DeleteInstanceOperation) Name() string { |
| 139 |
return op.lro.Name() |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
type ApiDeploymentIterator struct { |
| 144 |
items []*apigeeregistrypb.ApiDeployment |
| 145 |
pageInfo *iterator.PageInfo |
| 146 |
nextFunc func() error |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
Response interface{} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
InternalFetch func(pageSize int, pageToken string) (results []*apigeeregistrypb.ApiDeployment, nextPageToken string, err error) |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
func (it *ApiDeploymentIterator) PageInfo() *iterator.PageInfo { |
| 164 |
return it.pageInfo |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
func (it *ApiDeploymentIterator) Next() (*apigeeregistrypb.ApiDeployment, error) { |
| 170 |
var item *apigeeregistrypb.ApiDeployment |
| 171 |
if err := it.nextFunc(); err != nil { |
| 172 |
return item, err |
| 173 |
} |
| 174 |
item = it.items[0] |
| 175 |
it.items = it.items[1:] |
| 176 |
return item, nil |
| 177 |
} |
| 178 |
|
| 179 |
func (it *ApiDeploymentIterator) bufLen() int { |
| 180 |
return len(it.items) |
| 181 |
} |
| 182 |
|
| 183 |
func (it *ApiDeploymentIterator) takeBuf() interface{} { |
| 184 |
b := it.items |
| 185 |
it.items = nil |
| 186 |
return b |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
type ApiIterator struct { |
| 191 |
items []*apigeeregistrypb.Api |
| 192 |
pageInfo *iterator.PageInfo |
| 193 |
nextFunc func() error |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
Response interface{} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
InternalFetch func(pageSize int, pageToken string) (results []*apigeeregistrypb.Api, nextPageToken string, err error) |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
func (it *ApiIterator) PageInfo() *iterator.PageInfo { |
| 211 |
return it.pageInfo |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
func (it *ApiIterator) Next() (*apigeeregistrypb.Api, error) { |
| 217 |
var item *apigeeregistrypb.Api |
| 218 |
if err := it.nextFunc(); err != nil { |
| 219 |
return item, err |
| 220 |
} |
| 221 |
item = it.items[0] |
| 222 |
it.items = it.items[1:] |
| 223 |
return item, nil |
| 224 |
} |
| 225 |
|
| 226 |
func (it *ApiIterator) bufLen() int { |
| 227 |
return len(it.items) |
| 228 |
} |
| 229 |
|
| 230 |
func (it *ApiIterator) takeBuf() interface{} { |
| 231 |
b := it.items |
| 232 |
it.items = nil |
| 233 |
return b |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
type ApiSpecIterator struct { |
| 238 |
items []*apigeeregistrypb.ApiSpec |
| 239 |
pageInfo *iterator.PageInfo |
| 240 |
nextFunc func() error |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
Response interface{} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
InternalFetch func(pageSize int, pageToken string) (results []*apigeeregistrypb.ApiSpec, nextPageToken string, err error) |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
func (it *ApiSpecIterator) PageInfo() *iterator.PageInfo { |
| 258 |
return it.pageInfo |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
func (it *ApiSpecIterator) Next() (*apigeeregistrypb.ApiSpec, error) { |
| 264 |
var item *apigeeregistrypb.ApiSpec |
| 265 |
if err := it.nextFunc(); err != nil { |
| 266 |
return item, err |
| 267 |
} |
| 268 |
item = it.items[0] |
| 269 |
it.items = it.items[1:] |
| 270 |
return item, nil |
| 271 |
} |
| 272 |
|
| 273 |
func (it *ApiSpecIterator) bufLen() int { |
| 274 |
return len(it.items) |
| 275 |
} |
| 276 |
|
| 277 |
func (it *ApiSpecIterator) takeBuf() interface{} { |
| 278 |
b := it.items |
| 279 |
it.items = nil |
| 280 |
return b |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
type ApiVersionIterator struct { |
| 285 |
items []*apigeeregistrypb.ApiVersion |
| 286 |
pageInfo *iterator.PageInfo |
| 287 |
nextFunc func() error |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
Response interface{} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
InternalFetch func(pageSize int, pageToken string) (results []*apigeeregistrypb.ApiVersion, nextPageToken string, err error) |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
func (it *ApiVersionIterator) PageInfo() *iterator.PageInfo { |
| 305 |
return it.pageInfo |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
func (it *ApiVersionIterator) Next() (*apigeeregistrypb.ApiVersion, error) { |
| 311 |
var item *apigeeregistrypb.ApiVersion |
| 312 |
if err := it.nextFunc(); err != nil { |
| 313 |
return item, err |
| 314 |
} |
| 315 |
item = it.items[0] |
| 316 |
it.items = it.items[1:] |
| 317 |
return item, nil |
| 318 |
} |
| 319 |
|
| 320 |
func (it *ApiVersionIterator) bufLen() int { |
| 321 |
return len(it.items) |
| 322 |
} |
| 323 |
|
| 324 |
func (it *ApiVersionIterator) takeBuf() interface{} { |
| 325 |
b := it.items |
| 326 |
it.items = nil |
| 327 |
return b |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
type ArtifactIterator struct { |
| 332 |
items []*apigeeregistrypb.Artifact |
| 333 |
pageInfo *iterator.PageInfo |
| 334 |
nextFunc func() error |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
Response interface{} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
InternalFetch func(pageSize int, pageToken string) (results []*apigeeregistrypb.Artifact, nextPageToken string, err error) |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
func (it *ArtifactIterator) PageInfo() *iterator.PageInfo { |
| 352 |
return it.pageInfo |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
func (it *ArtifactIterator) Next() (*apigeeregistrypb.Artifact, error) { |
| 358 |
var item *apigeeregistrypb.Artifact |
| 359 |
if err := it.nextFunc(); err != nil { |
| 360 |
return item, err |
| 361 |
} |
| 362 |
item = it.items[0] |
| 363 |
it.items = it.items[1:] |
| 364 |
return item, nil |
| 365 |
} |
| 366 |
|
| 367 |
func (it *ArtifactIterator) bufLen() int { |
| 368 |
return len(it.items) |
| 369 |
} |
| 370 |
|
| 371 |
func (it *ArtifactIterator) takeBuf() interface{} { |
| 372 |
b := it.items |
| 373 |
it.items = nil |
| 374 |
return b |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
type LocationIterator struct { |
| 379 |
items []*locationpb.Location |
| 380 |
pageInfo *iterator.PageInfo |
| 381 |
nextFunc func() error |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
Response interface{} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
InternalFetch func(pageSize int, pageToken string) (results []*locationpb.Location, nextPageToken string, err error) |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
func (it *LocationIterator) PageInfo() *iterator.PageInfo { |
| 399 |
return it.pageInfo |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
func (it *LocationIterator) Next() (*locationpb.Location, error) { |
| 405 |
var item *locationpb.Location |
| 406 |
if err := it.nextFunc(); err != nil { |
| 407 |
return item, err |
| 408 |
} |
| 409 |
item = it.items[0] |
| 410 |
it.items = it.items[1:] |
| 411 |
return item, nil |
| 412 |
} |
| 413 |
|
| 414 |
func (it *LocationIterator) bufLen() int { |
| 415 |
return len(it.items) |
| 416 |
} |
| 417 |
|
| 418 |
func (it *LocationIterator) takeBuf() interface{} { |
| 419 |
b := it.items |
| 420 |
it.items = nil |
| 421 |
return b |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
type OperationIterator struct { |
| 426 |
items []*longrunningpb.Operation |
| 427 |
pageInfo *iterator.PageInfo |
| 428 |
nextFunc func() error |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
Response interface{} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
func (it *OperationIterator) PageInfo() *iterator.PageInfo { |
| 446 |
return it.pageInfo |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { |
| 452 |
var item *longrunningpb.Operation |
| 453 |
if err := it.nextFunc(); err != nil { |
| 454 |
return item, err |
| 455 |
} |
| 456 |
item = it.items[0] |
| 457 |
it.items = it.items[1:] |
| 458 |
return item, nil |
| 459 |
} |
| 460 |
|
| 461 |
func (it *OperationIterator) bufLen() int { |
| 462 |
return len(it.items) |
| 463 |
} |
| 464 |
|
| 465 |
func (it *OperationIterator) takeBuf() interface{} { |
| 466 |
b := it.items |
| 467 |
it.items = nil |
| 468 |
return b |
| 469 |
} |