You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

793 lines
30 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package securitycenter
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "cloud.google.com/go/longrunning"
  21. lroauto "cloud.google.com/go/longrunning/autogen"
  22. "github.com/golang/protobuf/proto"
  23. gax "github.com/googleapis/gax-go/v2"
  24. "google.golang.org/api/iterator"
  25. "google.golang.org/api/option"
  26. "google.golang.org/api/transport"
  27. securitycenterpb "google.golang.org/genproto/googleapis/cloud/securitycenter/v1beta1"
  28. iampb "google.golang.org/genproto/googleapis/iam/v1"
  29. longrunningpb "google.golang.org/genproto/googleapis/longrunning"
  30. "google.golang.org/grpc"
  31. "google.golang.org/grpc/codes"
  32. "google.golang.org/grpc/metadata"
  33. )
  34. // CallOptions contains the retry settings for each method of Client.
  35. type CallOptions struct {
  36. CreateSource []gax.CallOption
  37. CreateFinding []gax.CallOption
  38. GetIamPolicy []gax.CallOption
  39. GetOrganizationSettings []gax.CallOption
  40. GetSource []gax.CallOption
  41. GroupAssets []gax.CallOption
  42. GroupFindings []gax.CallOption
  43. ListAssets []gax.CallOption
  44. ListFindings []gax.CallOption
  45. ListSources []gax.CallOption
  46. RunAssetDiscovery []gax.CallOption
  47. SetFindingState []gax.CallOption
  48. SetIamPolicy []gax.CallOption
  49. TestIamPermissions []gax.CallOption
  50. UpdateFinding []gax.CallOption
  51. UpdateOrganizationSettings []gax.CallOption
  52. UpdateSource []gax.CallOption
  53. UpdateSecurityMarks []gax.CallOption
  54. }
  55. func defaultClientOptions() []option.ClientOption {
  56. return []option.ClientOption{
  57. option.WithEndpoint("securitycenter.googleapis.com:443"),
  58. option.WithScopes(DefaultAuthScopes()...),
  59. }
  60. }
  61. func defaultCallOptions() *CallOptions {
  62. retry := map[[2]string][]gax.CallOption{
  63. {"default", "idempotent"}: {
  64. gax.WithRetry(func() gax.Retryer {
  65. return gax.OnCodes([]codes.Code{
  66. codes.DeadlineExceeded,
  67. codes.Unavailable,
  68. }, gax.Backoff{
  69. Initial: 100 * time.Millisecond,
  70. Max: 60000 * time.Millisecond,
  71. Multiplier: 1.3,
  72. })
  73. }),
  74. },
  75. }
  76. return &CallOptions{
  77. CreateSource: retry[[2]string{"default", "non_idempotent"}],
  78. CreateFinding: retry[[2]string{"default", "non_idempotent"}],
  79. GetIamPolicy: retry[[2]string{"default", "idempotent"}],
  80. GetOrganizationSettings: retry[[2]string{"default", "idempotent"}],
  81. GetSource: retry[[2]string{"default", "idempotent"}],
  82. GroupAssets: retry[[2]string{"default", "idempotent"}],
  83. GroupFindings: retry[[2]string{"default", "idempotent"}],
  84. ListAssets: retry[[2]string{"default", "idempotent"}],
  85. ListFindings: retry[[2]string{"default", "idempotent"}],
  86. ListSources: retry[[2]string{"default", "idempotent"}],
  87. RunAssetDiscovery: retry[[2]string{"default", "non_idempotent"}],
  88. SetFindingState: retry[[2]string{"default", "non_idempotent"}],
  89. SetIamPolicy: retry[[2]string{"default", "non_idempotent"}],
  90. TestIamPermissions: retry[[2]string{"default", "idempotent"}],
  91. UpdateFinding: retry[[2]string{"default", "non_idempotent"}],
  92. UpdateOrganizationSettings: retry[[2]string{"default", "non_idempotent"}],
  93. UpdateSource: retry[[2]string{"default", "non_idempotent"}],
  94. UpdateSecurityMarks: retry[[2]string{"default", "non_idempotent"}],
  95. }
  96. }
  97. // Client is a client for interacting with Cloud Security Command Center API.
  98. //
  99. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  100. type Client struct {
  101. // The connection to the service.
  102. conn *grpc.ClientConn
  103. // The gRPC API client.
  104. client securitycenterpb.SecurityCenterClient
  105. // LROClient is used internally to handle longrunning operations.
  106. // It is exposed so that its CallOptions can be modified if required.
  107. // Users should not Close this client.
  108. LROClient *lroauto.OperationsClient
  109. // The call options for this service.
  110. CallOptions *CallOptions
  111. // The x-goog-* metadata to be sent with each request.
  112. xGoogMetadata metadata.MD
  113. }
  114. // NewClient creates a new security center client.
  115. //
  116. // V1 Beta APIs for Security Center service.
  117. func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
  118. conn, err := transport.DialGRPC(ctx, append(defaultClientOptions(), opts...)...)
  119. if err != nil {
  120. return nil, err
  121. }
  122. c := &Client{
  123. conn: conn,
  124. CallOptions: defaultCallOptions(),
  125. client: securitycenterpb.NewSecurityCenterClient(conn),
  126. }
  127. c.setGoogleClientInfo()
  128. c.LROClient, err = lroauto.NewOperationsClient(ctx, option.WithGRPCConn(conn))
  129. if err != nil {
  130. // This error "should not happen", since we are just reusing old connection
  131. // and never actually need to dial.
  132. // If this does happen, we could leak conn. However, we cannot close conn:
  133. // If the user invoked the function with option.WithGRPCConn,
  134. // we would close a connection that's still in use.
  135. // TODO(pongad): investigate error conditions.
  136. return nil, err
  137. }
  138. return c, nil
  139. }
  140. // Connection returns the client's connection to the API service.
  141. func (c *Client) Connection() *grpc.ClientConn {
  142. return c.conn
  143. }
  144. // Close closes the connection to the API service. The user should invoke this when
  145. // the client is no longer required.
  146. func (c *Client) Close() error {
  147. return c.conn.Close()
  148. }
  149. // setGoogleClientInfo sets the name and version of the application in
  150. // the `x-goog-api-client` header passed on each request. Intended for
  151. // use by Google-written clients.
  152. func (c *Client) setGoogleClientInfo(keyval ...string) {
  153. kv := append([]string{"gl-go", versionGo()}, keyval...)
  154. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  155. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  156. }
  157. // CreateSource creates a source.
  158. func (c *Client) CreateSource(ctx context.Context, req *securitycenterpb.CreateSourceRequest, opts ...gax.CallOption) (*securitycenterpb.Source, error) {
  159. ctx = insertMetadata(ctx, c.xGoogMetadata)
  160. opts = append(c.CallOptions.CreateSource[0:len(c.CallOptions.CreateSource):len(c.CallOptions.CreateSource)], opts...)
  161. var resp *securitycenterpb.Source
  162. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  163. var err error
  164. resp, err = c.client.CreateSource(ctx, req, settings.GRPC...)
  165. return err
  166. }, opts...)
  167. if err != nil {
  168. return nil, err
  169. }
  170. return resp, nil
  171. }
  172. // CreateFinding creates a finding. The corresponding source must exist for finding creation
  173. // to succeed.
  174. func (c *Client) CreateFinding(ctx context.Context, req *securitycenterpb.CreateFindingRequest, opts ...gax.CallOption) (*securitycenterpb.Finding, error) {
  175. ctx = insertMetadata(ctx, c.xGoogMetadata)
  176. opts = append(c.CallOptions.CreateFinding[0:len(c.CallOptions.CreateFinding):len(c.CallOptions.CreateFinding)], opts...)
  177. var resp *securitycenterpb.Finding
  178. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  179. var err error
  180. resp, err = c.client.CreateFinding(ctx, req, settings.GRPC...)
  181. return err
  182. }, opts...)
  183. if err != nil {
  184. return nil, err
  185. }
  186. return resp, nil
  187. }
  188. // GetIamPolicy gets the access control policy on the specified Source.
  189. func (c *Client) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  190. ctx = insertMetadata(ctx, c.xGoogMetadata)
  191. opts = append(c.CallOptions.GetIamPolicy[0:len(c.CallOptions.GetIamPolicy):len(c.CallOptions.GetIamPolicy)], opts...)
  192. var resp *iampb.Policy
  193. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  194. var err error
  195. resp, err = c.client.GetIamPolicy(ctx, req, settings.GRPC...)
  196. return err
  197. }, opts...)
  198. if err != nil {
  199. return nil, err
  200. }
  201. return resp, nil
  202. }
  203. // GetOrganizationSettings gets the settings for an organization.
  204. func (c *Client) GetOrganizationSettings(ctx context.Context, req *securitycenterpb.GetOrganizationSettingsRequest, opts ...gax.CallOption) (*securitycenterpb.OrganizationSettings, error) {
  205. ctx = insertMetadata(ctx, c.xGoogMetadata)
  206. opts = append(c.CallOptions.GetOrganizationSettings[0:len(c.CallOptions.GetOrganizationSettings):len(c.CallOptions.GetOrganizationSettings)], opts...)
  207. var resp *securitycenterpb.OrganizationSettings
  208. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  209. var err error
  210. resp, err = c.client.GetOrganizationSettings(ctx, req, settings.GRPC...)
  211. return err
  212. }, opts...)
  213. if err != nil {
  214. return nil, err
  215. }
  216. return resp, nil
  217. }
  218. // GetSource gets a source.
  219. func (c *Client) GetSource(ctx context.Context, req *securitycenterpb.GetSourceRequest, opts ...gax.CallOption) (*securitycenterpb.Source, error) {
  220. ctx = insertMetadata(ctx, c.xGoogMetadata)
  221. opts = append(c.CallOptions.GetSource[0:len(c.CallOptions.GetSource):len(c.CallOptions.GetSource)], opts...)
  222. var resp *securitycenterpb.Source
  223. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  224. var err error
  225. resp, err = c.client.GetSource(ctx, req, settings.GRPC...)
  226. return err
  227. }, opts...)
  228. if err != nil {
  229. return nil, err
  230. }
  231. return resp, nil
  232. }
  233. // GroupAssets filters an organization's assets and groups them by their specified
  234. // properties.
  235. func (c *Client) GroupAssets(ctx context.Context, req *securitycenterpb.GroupAssetsRequest, opts ...gax.CallOption) *GroupResultIterator {
  236. ctx = insertMetadata(ctx, c.xGoogMetadata)
  237. opts = append(c.CallOptions.GroupAssets[0:len(c.CallOptions.GroupAssets):len(c.CallOptions.GroupAssets)], opts...)
  238. it := &GroupResultIterator{}
  239. req = proto.Clone(req).(*securitycenterpb.GroupAssetsRequest)
  240. it.InternalFetch = func(pageSize int, pageToken string) ([]*securitycenterpb.GroupResult, string, error) {
  241. var resp *securitycenterpb.GroupAssetsResponse
  242. req.PageToken = pageToken
  243. if pageSize > math.MaxInt32 {
  244. req.PageSize = math.MaxInt32
  245. } else {
  246. req.PageSize = int32(pageSize)
  247. }
  248. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  249. var err error
  250. resp, err = c.client.GroupAssets(ctx, req, settings.GRPC...)
  251. return err
  252. }, opts...)
  253. if err != nil {
  254. return nil, "", err
  255. }
  256. return resp.GroupByResults, resp.NextPageToken, nil
  257. }
  258. fetch := func(pageSize int, pageToken string) (string, error) {
  259. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  260. if err != nil {
  261. return "", err
  262. }
  263. it.items = append(it.items, items...)
  264. return nextPageToken, nil
  265. }
  266. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  267. it.pageInfo.MaxSize = int(req.PageSize)
  268. return it
  269. }
  270. // GroupFindings filters an organization or source's findings and groups them by their
  271. // specified properties.
  272. //
  273. // To group across all sources provide a - as the source id.
  274. // Example: /v1beta1/organizations/123/sources/-/findings
  275. func (c *Client) GroupFindings(ctx context.Context, req *securitycenterpb.GroupFindingsRequest, opts ...gax.CallOption) *GroupResultIterator {
  276. ctx = insertMetadata(ctx, c.xGoogMetadata)
  277. opts = append(c.CallOptions.GroupFindings[0:len(c.CallOptions.GroupFindings):len(c.CallOptions.GroupFindings)], opts...)
  278. it := &GroupResultIterator{}
  279. req = proto.Clone(req).(*securitycenterpb.GroupFindingsRequest)
  280. it.InternalFetch = func(pageSize int, pageToken string) ([]*securitycenterpb.GroupResult, string, error) {
  281. var resp *securitycenterpb.GroupFindingsResponse
  282. req.PageToken = pageToken
  283. if pageSize > math.MaxInt32 {
  284. req.PageSize = math.MaxInt32
  285. } else {
  286. req.PageSize = int32(pageSize)
  287. }
  288. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  289. var err error
  290. resp, err = c.client.GroupFindings(ctx, req, settings.GRPC...)
  291. return err
  292. }, opts...)
  293. if err != nil {
  294. return nil, "", err
  295. }
  296. return resp.GroupByResults, resp.NextPageToken, nil
  297. }
  298. fetch := func(pageSize int, pageToken string) (string, error) {
  299. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  300. if err != nil {
  301. return "", err
  302. }
  303. it.items = append(it.items, items...)
  304. return nextPageToken, nil
  305. }
  306. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  307. it.pageInfo.MaxSize = int(req.PageSize)
  308. return it
  309. }
  310. // ListAssets lists an organization's assets.
  311. func (c *Client) ListAssets(ctx context.Context, req *securitycenterpb.ListAssetsRequest, opts ...gax.CallOption) *ListAssetsResponse_ListAssetsResultIterator {
  312. ctx = insertMetadata(ctx, c.xGoogMetadata)
  313. opts = append(c.CallOptions.ListAssets[0:len(c.CallOptions.ListAssets):len(c.CallOptions.ListAssets)], opts...)
  314. it := &ListAssetsResponse_ListAssetsResultIterator{}
  315. req = proto.Clone(req).(*securitycenterpb.ListAssetsRequest)
  316. it.InternalFetch = func(pageSize int, pageToken string) ([]*securitycenterpb.ListAssetsResponse_ListAssetsResult, string, error) {
  317. var resp *securitycenterpb.ListAssetsResponse
  318. req.PageToken = pageToken
  319. if pageSize > math.MaxInt32 {
  320. req.PageSize = math.MaxInt32
  321. } else {
  322. req.PageSize = int32(pageSize)
  323. }
  324. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  325. var err error
  326. resp, err = c.client.ListAssets(ctx, req, settings.GRPC...)
  327. return err
  328. }, opts...)
  329. if err != nil {
  330. return nil, "", err
  331. }
  332. return resp.ListAssetsResults, resp.NextPageToken, nil
  333. }
  334. fetch := func(pageSize int, pageToken string) (string, error) {
  335. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  336. if err != nil {
  337. return "", err
  338. }
  339. it.items = append(it.items, items...)
  340. return nextPageToken, nil
  341. }
  342. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  343. it.pageInfo.MaxSize = int(req.PageSize)
  344. return it
  345. }
  346. // ListFindings lists an organization or source's findings.
  347. //
  348. // To list across all sources provide a - as the source id.
  349. // Example: /v1beta1/organizations/123/sources/-/findings
  350. func (c *Client) ListFindings(ctx context.Context, req *securitycenterpb.ListFindingsRequest, opts ...gax.CallOption) *FindingIterator {
  351. ctx = insertMetadata(ctx, c.xGoogMetadata)
  352. opts = append(c.CallOptions.ListFindings[0:len(c.CallOptions.ListFindings):len(c.CallOptions.ListFindings)], opts...)
  353. it := &FindingIterator{}
  354. req = proto.Clone(req).(*securitycenterpb.ListFindingsRequest)
  355. it.InternalFetch = func(pageSize int, pageToken string) ([]*securitycenterpb.Finding, string, error) {
  356. var resp *securitycenterpb.ListFindingsResponse
  357. req.PageToken = pageToken
  358. if pageSize > math.MaxInt32 {
  359. req.PageSize = math.MaxInt32
  360. } else {
  361. req.PageSize = int32(pageSize)
  362. }
  363. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  364. var err error
  365. resp, err = c.client.ListFindings(ctx, req, settings.GRPC...)
  366. return err
  367. }, opts...)
  368. if err != nil {
  369. return nil, "", err
  370. }
  371. return resp.Findings, resp.NextPageToken, nil
  372. }
  373. fetch := func(pageSize int, pageToken string) (string, error) {
  374. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  375. if err != nil {
  376. return "", err
  377. }
  378. it.items = append(it.items, items...)
  379. return nextPageToken, nil
  380. }
  381. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  382. it.pageInfo.MaxSize = int(req.PageSize)
  383. return it
  384. }
  385. // ListSources lists all sources belonging to an organization.
  386. func (c *Client) ListSources(ctx context.Context, req *securitycenterpb.ListSourcesRequest, opts ...gax.CallOption) *SourceIterator {
  387. ctx = insertMetadata(ctx, c.xGoogMetadata)
  388. opts = append(c.CallOptions.ListSources[0:len(c.CallOptions.ListSources):len(c.CallOptions.ListSources)], opts...)
  389. it := &SourceIterator{}
  390. req = proto.Clone(req).(*securitycenterpb.ListSourcesRequest)
  391. it.InternalFetch = func(pageSize int, pageToken string) ([]*securitycenterpb.Source, string, error) {
  392. var resp *securitycenterpb.ListSourcesResponse
  393. req.PageToken = pageToken
  394. if pageSize > math.MaxInt32 {
  395. req.PageSize = math.MaxInt32
  396. } else {
  397. req.PageSize = int32(pageSize)
  398. }
  399. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  400. var err error
  401. resp, err = c.client.ListSources(ctx, req, settings.GRPC...)
  402. return err
  403. }, opts...)
  404. if err != nil {
  405. return nil, "", err
  406. }
  407. return resp.Sources, resp.NextPageToken, nil
  408. }
  409. fetch := func(pageSize int, pageToken string) (string, error) {
  410. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  411. if err != nil {
  412. return "", err
  413. }
  414. it.items = append(it.items, items...)
  415. return nextPageToken, nil
  416. }
  417. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  418. it.pageInfo.MaxSize = int(req.PageSize)
  419. return it
  420. }
  421. // RunAssetDiscovery runs asset discovery. The discovery is tracked with a long-running
  422. // operation.
  423. //
  424. // This API can only be called with limited frequency for an organization. If
  425. // it is called too frequently the caller will receive a TOO_MANY_REQUESTS
  426. // error.
  427. func (c *Client) RunAssetDiscovery(ctx context.Context, req *securitycenterpb.RunAssetDiscoveryRequest, opts ...gax.CallOption) (*RunAssetDiscoveryOperation, error) {
  428. ctx = insertMetadata(ctx, c.xGoogMetadata)
  429. opts = append(c.CallOptions.RunAssetDiscovery[0:len(c.CallOptions.RunAssetDiscovery):len(c.CallOptions.RunAssetDiscovery)], opts...)
  430. var resp *longrunningpb.Operation
  431. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  432. var err error
  433. resp, err = c.client.RunAssetDiscovery(ctx, req, settings.GRPC...)
  434. return err
  435. }, opts...)
  436. if err != nil {
  437. return nil, err
  438. }
  439. return &RunAssetDiscoveryOperation{
  440. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  441. }, nil
  442. }
  443. // SetFindingState updates the state of a finding.
  444. func (c *Client) SetFindingState(ctx context.Context, req *securitycenterpb.SetFindingStateRequest, opts ...gax.CallOption) (*securitycenterpb.Finding, error) {
  445. ctx = insertMetadata(ctx, c.xGoogMetadata)
  446. opts = append(c.CallOptions.SetFindingState[0:len(c.CallOptions.SetFindingState):len(c.CallOptions.SetFindingState)], opts...)
  447. var resp *securitycenterpb.Finding
  448. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  449. var err error
  450. resp, err = c.client.SetFindingState(ctx, req, settings.GRPC...)
  451. return err
  452. }, opts...)
  453. if err != nil {
  454. return nil, err
  455. }
  456. return resp, nil
  457. }
  458. // SetIamPolicy sets the access control policy on the specified Source.
  459. func (c *Client) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  460. ctx = insertMetadata(ctx, c.xGoogMetadata)
  461. opts = append(c.CallOptions.SetIamPolicy[0:len(c.CallOptions.SetIamPolicy):len(c.CallOptions.SetIamPolicy)], opts...)
  462. var resp *iampb.Policy
  463. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  464. var err error
  465. resp, err = c.client.SetIamPolicy(ctx, req, settings.GRPC...)
  466. return err
  467. }, opts...)
  468. if err != nil {
  469. return nil, err
  470. }
  471. return resp, nil
  472. }
  473. // TestIamPermissions returns the permissions that a caller has on the specified source.
  474. func (c *Client) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  475. ctx = insertMetadata(ctx, c.xGoogMetadata)
  476. opts = append(c.CallOptions.TestIamPermissions[0:len(c.CallOptions.TestIamPermissions):len(c.CallOptions.TestIamPermissions)], opts...)
  477. var resp *iampb.TestIamPermissionsResponse
  478. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  479. var err error
  480. resp, err = c.client.TestIamPermissions(ctx, req, settings.GRPC...)
  481. return err
  482. }, opts...)
  483. if err != nil {
  484. return nil, err
  485. }
  486. return resp, nil
  487. }
  488. // UpdateFinding creates or updates a finding. The corresponding source must exist for a
  489. // finding creation to succeed.
  490. func (c *Client) UpdateFinding(ctx context.Context, req *securitycenterpb.UpdateFindingRequest, opts ...gax.CallOption) (*securitycenterpb.Finding, error) {
  491. ctx = insertMetadata(ctx, c.xGoogMetadata)
  492. opts = append(c.CallOptions.UpdateFinding[0:len(c.CallOptions.UpdateFinding):len(c.CallOptions.UpdateFinding)], opts...)
  493. var resp *securitycenterpb.Finding
  494. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  495. var err error
  496. resp, err = c.client.UpdateFinding(ctx, req, settings.GRPC...)
  497. return err
  498. }, opts...)
  499. if err != nil {
  500. return nil, err
  501. }
  502. return resp, nil
  503. }
  504. // UpdateOrganizationSettings updates an organization's settings.
  505. func (c *Client) UpdateOrganizationSettings(ctx context.Context, req *securitycenterpb.UpdateOrganizationSettingsRequest, opts ...gax.CallOption) (*securitycenterpb.OrganizationSettings, error) {
  506. ctx = insertMetadata(ctx, c.xGoogMetadata)
  507. opts = append(c.CallOptions.UpdateOrganizationSettings[0:len(c.CallOptions.UpdateOrganizationSettings):len(c.CallOptions.UpdateOrganizationSettings)], opts...)
  508. var resp *securitycenterpb.OrganizationSettings
  509. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  510. var err error
  511. resp, err = c.client.UpdateOrganizationSettings(ctx, req, settings.GRPC...)
  512. return err
  513. }, opts...)
  514. if err != nil {
  515. return nil, err
  516. }
  517. return resp, nil
  518. }
  519. // UpdateSource updates a source.
  520. func (c *Client) UpdateSource(ctx context.Context, req *securitycenterpb.UpdateSourceRequest, opts ...gax.CallOption) (*securitycenterpb.Source, error) {
  521. ctx = insertMetadata(ctx, c.xGoogMetadata)
  522. opts = append(c.CallOptions.UpdateSource[0:len(c.CallOptions.UpdateSource):len(c.CallOptions.UpdateSource)], opts...)
  523. var resp *securitycenterpb.Source
  524. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  525. var err error
  526. resp, err = c.client.UpdateSource(ctx, req, settings.GRPC...)
  527. return err
  528. }, opts...)
  529. if err != nil {
  530. return nil, err
  531. }
  532. return resp, nil
  533. }
  534. // UpdateSecurityMarks updates security marks.
  535. func (c *Client) UpdateSecurityMarks(ctx context.Context, req *securitycenterpb.UpdateSecurityMarksRequest, opts ...gax.CallOption) (*securitycenterpb.SecurityMarks, error) {
  536. ctx = insertMetadata(ctx, c.xGoogMetadata)
  537. opts = append(c.CallOptions.UpdateSecurityMarks[0:len(c.CallOptions.UpdateSecurityMarks):len(c.CallOptions.UpdateSecurityMarks)], opts...)
  538. var resp *securitycenterpb.SecurityMarks
  539. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  540. var err error
  541. resp, err = c.client.UpdateSecurityMarks(ctx, req, settings.GRPC...)
  542. return err
  543. }, opts...)
  544. if err != nil {
  545. return nil, err
  546. }
  547. return resp, nil
  548. }
  549. // FindingIterator manages a stream of *securitycenterpb.Finding.
  550. type FindingIterator struct {
  551. items []*securitycenterpb.Finding
  552. pageInfo *iterator.PageInfo
  553. nextFunc func() error
  554. // InternalFetch is for use by the Google Cloud Libraries only.
  555. // It is not part of the stable interface of this package.
  556. //
  557. // InternalFetch returns results from a single call to the underlying RPC.
  558. // The number of results is no greater than pageSize.
  559. // If there are no more results, nextPageToken is empty and err is nil.
  560. InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.Finding, nextPageToken string, err error)
  561. }
  562. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  563. func (it *FindingIterator) PageInfo() *iterator.PageInfo {
  564. return it.pageInfo
  565. }
  566. // Next returns the next result. Its second return value is iterator.Done if there are no more
  567. // results. Once Next returns Done, all subsequent calls will return Done.
  568. func (it *FindingIterator) Next() (*securitycenterpb.Finding, error) {
  569. var item *securitycenterpb.Finding
  570. if err := it.nextFunc(); err != nil {
  571. return item, err
  572. }
  573. item = it.items[0]
  574. it.items = it.items[1:]
  575. return item, nil
  576. }
  577. func (it *FindingIterator) bufLen() int {
  578. return len(it.items)
  579. }
  580. func (it *FindingIterator) takeBuf() interface{} {
  581. b := it.items
  582. it.items = nil
  583. return b
  584. }
  585. // GroupResultIterator manages a stream of *securitycenterpb.GroupResult.
  586. type GroupResultIterator struct {
  587. items []*securitycenterpb.GroupResult
  588. pageInfo *iterator.PageInfo
  589. nextFunc func() error
  590. // InternalFetch is for use by the Google Cloud Libraries only.
  591. // It is not part of the stable interface of this package.
  592. //
  593. // InternalFetch returns results from a single call to the underlying RPC.
  594. // The number of results is no greater than pageSize.
  595. // If there are no more results, nextPageToken is empty and err is nil.
  596. InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.GroupResult, nextPageToken string, err error)
  597. }
  598. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  599. func (it *GroupResultIterator) PageInfo() *iterator.PageInfo {
  600. return it.pageInfo
  601. }
  602. // Next returns the next result. Its second return value is iterator.Done if there are no more
  603. // results. Once Next returns Done, all subsequent calls will return Done.
  604. func (it *GroupResultIterator) Next() (*securitycenterpb.GroupResult, error) {
  605. var item *securitycenterpb.GroupResult
  606. if err := it.nextFunc(); err != nil {
  607. return item, err
  608. }
  609. item = it.items[0]
  610. it.items = it.items[1:]
  611. return item, nil
  612. }
  613. func (it *GroupResultIterator) bufLen() int {
  614. return len(it.items)
  615. }
  616. func (it *GroupResultIterator) takeBuf() interface{} {
  617. b := it.items
  618. it.items = nil
  619. return b
  620. }
  621. // ListAssetsResponse_ListAssetsResultIterator manages a stream of *securitycenterpb.ListAssetsResponse_ListAssetsResult.
  622. type ListAssetsResponse_ListAssetsResultIterator struct {
  623. items []*securitycenterpb.ListAssetsResponse_ListAssetsResult
  624. pageInfo *iterator.PageInfo
  625. nextFunc func() error
  626. // InternalFetch is for use by the Google Cloud Libraries only.
  627. // It is not part of the stable interface of this package.
  628. //
  629. // InternalFetch returns results from a single call to the underlying RPC.
  630. // The number of results is no greater than pageSize.
  631. // If there are no more results, nextPageToken is empty and err is nil.
  632. InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.ListAssetsResponse_ListAssetsResult, nextPageToken string, err error)
  633. }
  634. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  635. func (it *ListAssetsResponse_ListAssetsResultIterator) PageInfo() *iterator.PageInfo {
  636. return it.pageInfo
  637. }
  638. // Next returns the next result. Its second return value is iterator.Done if there are no more
  639. // results. Once Next returns Done, all subsequent calls will return Done.
  640. func (it *ListAssetsResponse_ListAssetsResultIterator) Next() (*securitycenterpb.ListAssetsResponse_ListAssetsResult, error) {
  641. var item *securitycenterpb.ListAssetsResponse_ListAssetsResult
  642. if err := it.nextFunc(); err != nil {
  643. return item, err
  644. }
  645. item = it.items[0]
  646. it.items = it.items[1:]
  647. return item, nil
  648. }
  649. func (it *ListAssetsResponse_ListAssetsResultIterator) bufLen() int {
  650. return len(it.items)
  651. }
  652. func (it *ListAssetsResponse_ListAssetsResultIterator) takeBuf() interface{} {
  653. b := it.items
  654. it.items = nil
  655. return b
  656. }
  657. // SourceIterator manages a stream of *securitycenterpb.Source.
  658. type SourceIterator struct {
  659. items []*securitycenterpb.Source
  660. pageInfo *iterator.PageInfo
  661. nextFunc func() error
  662. // InternalFetch is for use by the Google Cloud Libraries only.
  663. // It is not part of the stable interface of this package.
  664. //
  665. // InternalFetch returns results from a single call to the underlying RPC.
  666. // The number of results is no greater than pageSize.
  667. // If there are no more results, nextPageToken is empty and err is nil.
  668. InternalFetch func(pageSize int, pageToken string) (results []*securitycenterpb.Source, nextPageToken string, err error)
  669. }
  670. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  671. func (it *SourceIterator) PageInfo() *iterator.PageInfo {
  672. return it.pageInfo
  673. }
  674. // Next returns the next result. Its second return value is iterator.Done if there are no more
  675. // results. Once Next returns Done, all subsequent calls will return Done.
  676. func (it *SourceIterator) Next() (*securitycenterpb.Source, error) {
  677. var item *securitycenterpb.Source
  678. if err := it.nextFunc(); err != nil {
  679. return item, err
  680. }
  681. item = it.items[0]
  682. it.items = it.items[1:]
  683. return item, nil
  684. }
  685. func (it *SourceIterator) bufLen() int {
  686. return len(it.items)
  687. }
  688. func (it *SourceIterator) takeBuf() interface{} {
  689. b := it.items
  690. it.items = nil
  691. return b
  692. }
  693. // RunAssetDiscoveryOperation manages a long-running operation from RunAssetDiscovery.
  694. type RunAssetDiscoveryOperation struct {
  695. lro *longrunning.Operation
  696. }
  697. // RunAssetDiscoveryOperation returns a new RunAssetDiscoveryOperation from a given name.
  698. // The name must be that of a previously created RunAssetDiscoveryOperation, possibly from a different process.
  699. func (c *Client) RunAssetDiscoveryOperation(name string) *RunAssetDiscoveryOperation {
  700. return &RunAssetDiscoveryOperation{
  701. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  702. }
  703. }
  704. // Wait blocks until the long-running operation is completed, returning any error encountered.
  705. //
  706. // See documentation of Poll for error-handling information.
  707. func (op *RunAssetDiscoveryOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  708. return op.lro.WaitWithInterval(ctx, nil, 5000*time.Millisecond, opts...)
  709. }
  710. // Poll fetches the latest state of the long-running operation.
  711. //
  712. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  713. // the operation has completed with failure, the error is returned and op.Done will return true.
  714. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  715. func (op *RunAssetDiscoveryOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  716. return op.lro.Poll(ctx, nil, opts...)
  717. }
  718. // Done reports whether the long-running operation has completed.
  719. func (op *RunAssetDiscoveryOperation) Done() bool {
  720. return op.lro.Done()
  721. }
  722. // Name returns the name of the long-running operation.
  723. // The name is assigned by the server and is unique within the service from which the operation is created.
  724. func (op *RunAssetDiscoveryOperation) Name() string {
  725. return op.lro.Name()
  726. }