| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package policysimulator |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"time" |
| 22 |
|
| 23 |
"cloud.google.com/go/longrunning" |
| 24 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 25 |
policysimulatorpb "cloud.google.com/go/policysimulator/apiv1/policysimulatorpb" |
| 26 |
gax "github.com/googleapis/gax-go/v2" |
| 27 |
"google.golang.org/api/iterator" |
| 28 |
) |
| 29 |
|
| 30 |
|
| 31 |
type CreateOrgPolicyViolationsPreviewOperation struct { |
| 32 |
lro *longrunning.Operation |
| 33 |
pollPath string |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
func (op *CreateOrgPolicyViolationsPreviewOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*policysimulatorpb.OrgPolicyViolationsPreview, error) { |
| 40 |
opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 41 |
var resp policysimulatorpb.OrgPolicyViolationsPreview |
| 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 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
func (op *CreateOrgPolicyViolationsPreviewOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*policysimulatorpb.OrgPolicyViolationsPreview, error) { |
| 58 |
opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 59 |
var resp policysimulatorpb.OrgPolicyViolationsPreview |
| 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 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
func (op *CreateOrgPolicyViolationsPreviewOperation) Metadata() (*policysimulatorpb.CreateOrgPolicyViolationsPreviewOperationMetadata, error) { |
| 74 |
var meta policysimulatorpb.CreateOrgPolicyViolationsPreviewOperationMetadata |
| 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 |
|
| 84 |
func (op *CreateOrgPolicyViolationsPreviewOperation) Done() bool { |
| 85 |
return op.lro.Done() |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
func (op *CreateOrgPolicyViolationsPreviewOperation) Name() string { |
| 91 |
return op.lro.Name() |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
type CreateReplayOperation struct { |
| 96 |
lro *longrunning.Operation |
| 97 |
pollPath string |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
func (op *CreateReplayOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*policysimulatorpb.Replay, error) { |
| 104 |
opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 105 |
var resp policysimulatorpb.Replay |
| 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 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
func (op *CreateReplayOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*policysimulatorpb.Replay, error) { |
| 122 |
opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 123 |
var resp policysimulatorpb.Replay |
| 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 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
func (op *CreateReplayOperation) Metadata() (*policysimulatorpb.ReplayOperationMetadata, error) { |
| 138 |
var meta policysimulatorpb.ReplayOperationMetadata |
| 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 |
|
| 148 |
func (op *CreateReplayOperation) Done() bool { |
| 149 |
return op.lro.Done() |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
func (op *CreateReplayOperation) Name() string { |
| 155 |
return op.lro.Name() |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
type OperationIterator struct { |
| 160 |
items []*longrunningpb.Operation |
| 161 |
pageInfo *iterator.PageInfo |
| 162 |
nextFunc func() error |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
Response interface{} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
func (it *OperationIterator) PageInfo() *iterator.PageInfo { |
| 180 |
return it.pageInfo |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { |
| 186 |
var item *longrunningpb.Operation |
| 187 |
if err := it.nextFunc(); err != nil { |
| 188 |
return item, err |
| 189 |
} |
| 190 |
item = it.items[0] |
| 191 |
it.items = it.items[1:] |
| 192 |
return item, nil |
| 193 |
} |
| 194 |
|
| 195 |
func (it *OperationIterator) bufLen() int { |
| 196 |
return len(it.items) |
| 197 |
} |
| 198 |
|
| 199 |
func (it *OperationIterator) takeBuf() interface{} { |
| 200 |
b := it.items |
| 201 |
it.items = nil |
| 202 |
return b |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
type OrgPolicyViolationIterator struct { |
| 207 |
items []*policysimulatorpb.OrgPolicyViolation |
| 208 |
pageInfo *iterator.PageInfo |
| 209 |
nextFunc func() error |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
Response interface{} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
InternalFetch func(pageSize int, pageToken string) (results []*policysimulatorpb.OrgPolicyViolation, nextPageToken string, err error) |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
func (it *OrgPolicyViolationIterator) PageInfo() *iterator.PageInfo { |
| 227 |
return it.pageInfo |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
func (it *OrgPolicyViolationIterator) Next() (*policysimulatorpb.OrgPolicyViolation, error) { |
| 233 |
var item *policysimulatorpb.OrgPolicyViolation |
| 234 |
if err := it.nextFunc(); err != nil { |
| 235 |
return item, err |
| 236 |
} |
| 237 |
item = it.items[0] |
| 238 |
it.items = it.items[1:] |
| 239 |
return item, nil |
| 240 |
} |
| 241 |
|
| 242 |
func (it *OrgPolicyViolationIterator) bufLen() int { |
| 243 |
return len(it.items) |
| 244 |
} |
| 245 |
|
| 246 |
func (it *OrgPolicyViolationIterator) takeBuf() interface{} { |
| 247 |
b := it.items |
| 248 |
it.items = nil |
| 249 |
return b |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
type OrgPolicyViolationsPreviewIterator struct { |
| 254 |
items []*policysimulatorpb.OrgPolicyViolationsPreview |
| 255 |
pageInfo *iterator.PageInfo |
| 256 |
nextFunc func() error |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
Response interface{} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
InternalFetch func(pageSize int, pageToken string) (results []*policysimulatorpb.OrgPolicyViolationsPreview, nextPageToken string, err error) |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
func (it *OrgPolicyViolationsPreviewIterator) PageInfo() *iterator.PageInfo { |
| 274 |
return it.pageInfo |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
func (it *OrgPolicyViolationsPreviewIterator) Next() (*policysimulatorpb.OrgPolicyViolationsPreview, error) { |
| 280 |
var item *policysimulatorpb.OrgPolicyViolationsPreview |
| 281 |
if err := it.nextFunc(); err != nil { |
| 282 |
return item, err |
| 283 |
} |
| 284 |
item = it.items[0] |
| 285 |
it.items = it.items[1:] |
| 286 |
return item, nil |
| 287 |
} |
| 288 |
|
| 289 |
func (it *OrgPolicyViolationsPreviewIterator) bufLen() int { |
| 290 |
return len(it.items) |
| 291 |
} |
| 292 |
|
| 293 |
func (it *OrgPolicyViolationsPreviewIterator) takeBuf() interface{} { |
| 294 |
b := it.items |
| 295 |
it.items = nil |
| 296 |
return b |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
type ReplayResultIterator struct { |
| 301 |
items []*policysimulatorpb.ReplayResult |
| 302 |
pageInfo *iterator.PageInfo |
| 303 |
nextFunc func() error |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
Response interface{} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
InternalFetch func(pageSize int, pageToken string) (results []*policysimulatorpb.ReplayResult, nextPageToken string, err error) |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
func (it *ReplayResultIterator) PageInfo() *iterator.PageInfo { |
| 321 |
return it.pageInfo |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
func (it *ReplayResultIterator) Next() (*policysimulatorpb.ReplayResult, error) { |
| 327 |
var item *policysimulatorpb.ReplayResult |
| 328 |
if err := it.nextFunc(); err != nil { |
| 329 |
return item, err |
| 330 |
} |
| 331 |
item = it.items[0] |
| 332 |
it.items = it.items[1:] |
| 333 |
return item, nil |
| 334 |
} |
| 335 |
|
| 336 |
func (it *ReplayResultIterator) bufLen() int { |
| 337 |
return len(it.items) |
| 338 |
} |
| 339 |
|
| 340 |
func (it *ReplayResultIterator) takeBuf() interface{} { |
| 341 |
b := it.items |
| 342 |
it.items = nil |
| 343 |
return b |
| 344 |
} |