| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package securitycenter |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"time" |
| 22 |
|
| 23 |
"cloud.google.com/go/longrunning" |
| 24 |
securitycenterpb "cloud.google.com/go/securitycenter/apiv1p1beta1/securitycenterpb" |
| 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 |
|
| 31 |
type RunAssetDiscoveryOperation struct { |
| 32 |
lro *longrunning.Operation |
| 33 |
pollPath string |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
func (op *RunAssetDiscoveryOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*securitycenterpb.RunAssetDiscoveryResponse, error) { |
| 40 |
opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 41 |
var resp securitycenterpb.RunAssetDiscoveryResponse |
| 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 *RunAssetDiscoveryOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*securitycenterpb.RunAssetDiscoveryResponse, error) { |
| 58 |
opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 59 |
var resp securitycenterpb.RunAssetDiscoveryResponse |
| 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 *RunAssetDiscoveryOperation) 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 |
|
| 84 |
func (op *RunAssetDiscoveryOperation) Done() bool { |
| 85 |
return op.lro.Done() |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
func (op *RunAssetDiscoveryOperation) Name() string { |
| 91 |
return op.lro.Name() |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
type GroupResultIterator struct { |
| 96 |
items []*securitycenterpb.GroupResult |
| 97 |
pageInfo *iterator.PageInfo |
| 98 |
nextFunc func() error |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
Response interface{} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.GroupResult, nextPageToken string, err error) |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
func (it *GroupResultIterator) PageInfo() *iterator.PageInfo { |
| 116 |
return it.pageInfo |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
func (it *GroupResultIterator) Next() (*securitycenterpb.GroupResult, error) { |
| 122 |
var item *securitycenterpb.GroupResult |
| 123 |
if err := it.nextFunc(); err != nil { |
| 124 |
return item, err |
| 125 |
} |
| 126 |
item = it.items[0] |
| 127 |
it.items = it.items[1:] |
| 128 |
return item, nil |
| 129 |
} |
| 130 |
|
| 131 |
func (it *GroupResultIterator) bufLen() int { |
| 132 |
return len(it.items) |
| 133 |
} |
| 134 |
|
| 135 |
func (it *GroupResultIterator) takeBuf() interface{} { |
| 136 |
b := it.items |
| 137 |
it.items = nil |
| 138 |
return b |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
type ListAssetsResponse_ListAssetsResultIterator struct { |
| 143 |
items []*securitycenterpb.ListAssetsResponse_ListAssetsResult |
| 144 |
pageInfo *iterator.PageInfo |
| 145 |
nextFunc func() error |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
Response interface{} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.ListAssetsResponse_ListAssetsResult, nextPageToken string, err error) |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
func (it *ListAssetsResponse_ListAssetsResultIterator) PageInfo() *iterator.PageInfo { |
| 163 |
return it.pageInfo |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
func (it *ListAssetsResponse_ListAssetsResultIterator) Next() (*securitycenterpb.ListAssetsResponse_ListAssetsResult, error) { |
| 169 |
var item *securitycenterpb.ListAssetsResponse_ListAssetsResult |
| 170 |
if err := it.nextFunc(); err != nil { |
| 171 |
return item, err |
| 172 |
} |
| 173 |
item = it.items[0] |
| 174 |
it.items = it.items[1:] |
| 175 |
return item, nil |
| 176 |
} |
| 177 |
|
| 178 |
func (it *ListAssetsResponse_ListAssetsResultIterator) bufLen() int { |
| 179 |
return len(it.items) |
| 180 |
} |
| 181 |
|
| 182 |
func (it *ListAssetsResponse_ListAssetsResultIterator) takeBuf() interface{} { |
| 183 |
b := it.items |
| 184 |
it.items = nil |
| 185 |
return b |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
type ListFindingsResponse_ListFindingsResultIterator struct { |
| 190 |
items []*securitycenterpb.ListFindingsResponse_ListFindingsResult |
| 191 |
pageInfo *iterator.PageInfo |
| 192 |
nextFunc func() error |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
Response interface{} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.ListFindingsResponse_ListFindingsResult, nextPageToken string, err error) |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
func (it *ListFindingsResponse_ListFindingsResultIterator) PageInfo() *iterator.PageInfo { |
| 210 |
return it.pageInfo |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
func (it *ListFindingsResponse_ListFindingsResultIterator) Next() (*securitycenterpb.ListFindingsResponse_ListFindingsResult, error) { |
| 216 |
var item *securitycenterpb.ListFindingsResponse_ListFindingsResult |
| 217 |
if err := it.nextFunc(); err != nil { |
| 218 |
return item, err |
| 219 |
} |
| 220 |
item = it.items[0] |
| 221 |
it.items = it.items[1:] |
| 222 |
return item, nil |
| 223 |
} |
| 224 |
|
| 225 |
func (it *ListFindingsResponse_ListFindingsResultIterator) bufLen() int { |
| 226 |
return len(it.items) |
| 227 |
} |
| 228 |
|
| 229 |
func (it *ListFindingsResponse_ListFindingsResultIterator) takeBuf() interface{} { |
| 230 |
b := it.items |
| 231 |
it.items = nil |
| 232 |
return b |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
type NotificationConfigIterator struct { |
| 237 |
items []*securitycenterpb.NotificationConfig |
| 238 |
pageInfo *iterator.PageInfo |
| 239 |
nextFunc func() error |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
Response interface{} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.NotificationConfig, nextPageToken string, err error) |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
func (it *NotificationConfigIterator) PageInfo() *iterator.PageInfo { |
| 257 |
return it.pageInfo |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
func (it *NotificationConfigIterator) Next() (*securitycenterpb.NotificationConfig, error) { |
| 263 |
var item *securitycenterpb.NotificationConfig |
| 264 |
if err := it.nextFunc(); err != nil { |
| 265 |
return item, err |
| 266 |
} |
| 267 |
item = it.items[0] |
| 268 |
it.items = it.items[1:] |
| 269 |
return item, nil |
| 270 |
} |
| 271 |
|
| 272 |
func (it *NotificationConfigIterator) bufLen() int { |
| 273 |
return len(it.items) |
| 274 |
} |
| 275 |
|
| 276 |
func (it *NotificationConfigIterator) takeBuf() interface{} { |
| 277 |
b := it.items |
| 278 |
it.items = nil |
| 279 |
return b |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
type SourceIterator struct { |
| 284 |
items []*securitycenterpb.Source |
| 285 |
pageInfo *iterator.PageInfo |
| 286 |
nextFunc func() error |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
Response interface{} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.Source, nextPageToken string, err error) |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
func (it *SourceIterator) PageInfo() *iterator.PageInfo { |
| 304 |
return it.pageInfo |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
func (it *SourceIterator) Next() (*securitycenterpb.Source, error) { |
| 310 |
var item *securitycenterpb.Source |
| 311 |
if err := it.nextFunc(); err != nil { |
| 312 |
return item, err |
| 313 |
} |
| 314 |
item = it.items[0] |
| 315 |
it.items = it.items[1:] |
| 316 |
return item, nil |
| 317 |
} |
| 318 |
|
| 319 |
func (it *SourceIterator) bufLen() int { |
| 320 |
return len(it.items) |
| 321 |
} |
| 322 |
|
| 323 |
func (it *SourceIterator) takeBuf() interface{} { |
| 324 |
b := it.items |
| 325 |
it.items = nil |
| 326 |
return b |
| 327 |
} |