Debian Codegraph @

apikeys/apiv2/auxiliary.go

raw
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 apikeys
18
19 import (
20 "context"
21 "time"
22
23 apikeyspb "cloud.google.com/go/apikeys/apiv2/apikeyspb"
24 "cloud.google.com/go/longrunning"
25 gax "github.com/googleapis/gax-go/v2"
26 "google.golang.org/api/iterator"
27 emptypb "google.golang.org/protobuf/types/known/emptypb"
28 )
29
30 // CreateKeyOperation manages a long-running operation from CreateKey.
31 type CreateKeyOperation struct {
32 lro *longrunning.Operation
33 pollPath string
34 }
35
36 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
37 //
38 // See documentation of Poll for error-handling information.
39 func (op *CreateKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
40 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
41 var resp apikeyspb.Key
42 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
43 return nil, err
44 }
45 return &resp, nil
46 }
47
48 // Poll fetches the latest state of the long-running operation.
49 //
50 // Poll also fetches the latest metadata, which can be retrieved by Metadata.
51 //
52 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
53 // the operation has completed with failure, the error is returned and op.Done will return true.
54 // If Poll succeeds and the operation has completed successfully,
55 // op.Done will return true, and the response of the operation is returned.
56 // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
57 func (op *CreateKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
58 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
59 var resp apikeyspb.Key
60 if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
61 return nil, err
62 }
63 if !op.Done() {
64 return nil, nil
65 }
66 return &resp, nil
67 }
68
69 // Metadata returns metadata associated with the long-running operation.
70 // Metadata itself does not contact the server, but Poll does.
71 // To get the latest metadata, call this method after a successful call to Poll.
72 // If the metadata is not available, the returned metadata and error are both nil.
73 func (op *CreateKeyOperation) Metadata() (*emptypb.Empty, error) {
74 var meta emptypb.Empty
75 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
76 return nil, nil
77 } else if err != nil {
78 return nil, err
79 }
80 return &meta, nil
81 }
82
83 // Done reports whether the long-running operation has completed.
84 func (op *CreateKeyOperation) Done() bool {
85 return op.lro.Done()
86 }
87
88 // Name returns the name of the long-running operation.
89 // The name is assigned by the server and is unique within the service from which the operation is created.
90 func (op *CreateKeyOperation) Name() string {
91 return op.lro.Name()
92 }
93
94 // DeleteKeyOperation manages a long-running operation from DeleteKey.
95 type DeleteKeyOperation struct {
96 lro *longrunning.Operation
97 pollPath string
98 }
99
100 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
101 //
102 // See documentation of Poll for error-handling information.
103 func (op *DeleteKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
104 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
105 var resp apikeyspb.Key
106 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
107 return nil, err
108 }
109 return &resp, nil
110 }
111
112 // Poll fetches the latest state of the long-running operation.
113 //
114 // Poll also fetches the latest metadata, which can be retrieved by Metadata.
115 //
116 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
117 // the operation has completed with failure, the error is returned and op.Done will return true.
118 // If Poll succeeds and the operation has completed successfully,
119 // op.Done will return true, and the response of the operation is returned.
120 // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
121 func (op *DeleteKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
122 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
123 var resp apikeyspb.Key
124 if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
125 return nil, err
126 }
127 if !op.Done() {
128 return nil, nil
129 }
130 return &resp, nil
131 }
132
133 // Metadata returns metadata associated with the long-running operation.
134 // Metadata itself does not contact the server, but Poll does.
135 // To get the latest metadata, call this method after a successful call to Poll.
136 // If the metadata is not available, the returned metadata and error are both nil.
137 func (op *DeleteKeyOperation) Metadata() (*emptypb.Empty, error) {
138 var meta emptypb.Empty
139 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
140 return nil, nil
141 } else if err != nil {
142 return nil, err
143 }
144 return &meta, nil
145 }
146
147 // Done reports whether the long-running operation has completed.
148 func (op *DeleteKeyOperation) Done() bool {
149 return op.lro.Done()
150 }
151
152 // Name returns the name of the long-running operation.
153 // The name is assigned by the server and is unique within the service from which the operation is created.
154 func (op *DeleteKeyOperation) Name() string {
155 return op.lro.Name()
156 }
157
158 // UndeleteKeyOperation manages a long-running operation from UndeleteKey.
159 type UndeleteKeyOperation struct {
160 lro *longrunning.Operation
161 pollPath string
162 }
163
164 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
165 //
166 // See documentation of Poll for error-handling information.
167 func (op *UndeleteKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
168 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
169 var resp apikeyspb.Key
170 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
171 return nil, err
172 }
173 return &resp, nil
174 }
175
176 // Poll fetches the latest state of the long-running operation.
177 //
178 // Poll also fetches the latest metadata, which can be retrieved by Metadata.
179 //
180 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
181 // the operation has completed with failure, the error is returned and op.Done will return true.
182 // If Poll succeeds and the operation has completed successfully,
183 // op.Done will return true, and the response of the operation is returned.
184 // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
185 func (op *UndeleteKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
186 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
187 var resp apikeyspb.Key
188 if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
189 return nil, err
190 }
191 if !op.Done() {
192 return nil, nil
193 }
194 return &resp, nil
195 }
196
197 // Metadata returns metadata associated with the long-running operation.
198 // Metadata itself does not contact the server, but Poll does.
199 // To get the latest metadata, call this method after a successful call to Poll.
200 // If the metadata is not available, the returned metadata and error are both nil.
201 func (op *UndeleteKeyOperation) Metadata() (*emptypb.Empty, error) {
202 var meta emptypb.Empty
203 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
204 return nil, nil
205 } else if err != nil {
206 return nil, err
207 }
208 return &meta, nil
209 }
210
211 // Done reports whether the long-running operation has completed.
212 func (op *UndeleteKeyOperation) Done() bool {
213 return op.lro.Done()
214 }
215
216 // Name returns the name of the long-running operation.
217 // The name is assigned by the server and is unique within the service from which the operation is created.
218 func (op *UndeleteKeyOperation) Name() string {
219 return op.lro.Name()
220 }
221
222 // UpdateKeyOperation manages a long-running operation from UpdateKey.
223 type UpdateKeyOperation struct {
224 lro *longrunning.Operation
225 pollPath string
226 }
227
228 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
229 //
230 // See documentation of Poll for error-handling information.
231 func (op *UpdateKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
232 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
233 var resp apikeyspb.Key
234 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
235 return nil, err
236 }
237 return &resp, nil
238 }
239
240 // Poll fetches the latest state of the long-running operation.
241 //
242 // Poll also fetches the latest metadata, which can be retrieved by Metadata.
243 //
244 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
245 // the operation has completed with failure, the error is returned and op.Done will return true.
246 // If Poll succeeds and the operation has completed successfully,
247 // op.Done will return true, and the response of the operation is returned.
248 // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
249 func (op *UpdateKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*apikeyspb.Key, error) {
250 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
251 var resp apikeyspb.Key
252 if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
253 return nil, err
254 }
255 if !op.Done() {
256 return nil, nil
257 }
258 return &resp, nil
259 }
260
261 // Metadata returns metadata associated with the long-running operation.
262 // Metadata itself does not contact the server, but Poll does.
263 // To get the latest metadata, call this method after a successful call to Poll.
264 // If the metadata is not available, the returned metadata and error are both nil.
265 func (op *UpdateKeyOperation) Metadata() (*emptypb.Empty, error) {
266 var meta emptypb.Empty
267 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
268 return nil, nil
269 } else if err != nil {
270 return nil, err
271 }
272 return &meta, nil
273 }
274
275 // Done reports whether the long-running operation has completed.
276 func (op *UpdateKeyOperation) Done() bool {
277 return op.lro.Done()
278 }
279
280 // Name returns the name of the long-running operation.
281 // The name is assigned by the server and is unique within the service from which the operation is created.
282 func (op *UpdateKeyOperation) Name() string {
283 return op.lro.Name()
284 }
285
286 // KeyIterator manages a stream of *apikeyspb.Key.
287 type KeyIterator struct {
288 items []*apikeyspb.Key
289 pageInfo *iterator.PageInfo
290 nextFunc func() error
291
292 // Response is the raw response for the current page.
293 // It must be cast to the RPC response type.
294 // Calling Next() or InternalFetch() updates this value.
295 Response interface{}
296
297 // InternalFetch is for use by the Google Cloud Libraries only.
298 // It is not part of the stable interface of this package.
299 //
300 // InternalFetch returns results from a single call to the underlying RPC.
301 // The number of results is no greater than pageSize.
302 // If there are no more results, nextPageToken is empty and err is nil.
303 InternalFetch func(pageSize int, pageToken string) (results []*apikeyspb.Key, nextPageToken string, err error)
304 }
305
306 // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
307 func (it *KeyIterator) PageInfo() *iterator.PageInfo {
308 return it.pageInfo
309 }
310
311 // Next returns the next result. Its second return value is iterator.Done if there are no more
312 // results. Once Next returns Done, all subsequent calls will return Done.
313 func (it *KeyIterator) Next() (*apikeyspb.Key, error) {
314 var item *apikeyspb.Key
315 if err := it.nextFunc(); err != nil {
316 return item, err
317 }
318 item = it.items[0]
319 it.items = it.items[1:]
320 return item, nil
321 }
322
323 func (it *KeyIterator) bufLen() int {
324 return len(it.items)
325 }
326
327 func (it *KeyIterator) takeBuf() interface{} {
328 b := it.items
329 it.items = nil
330 return b
331 }