diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 30efb6924c2b..f8929438c446 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -887,6 +887,14 @@ "docs_url": "https://pkg.go.dev/cloud.google.com/go/webrisk/apiv1beta1", "release_level": "beta" }, + "cloud.google.com/go/websecurityscanner/apiv1": { + "distribution_name": "cloud.google.com/go/websecurityscanner/apiv1", + "description": "Web Security Scanner API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://pkg.go.dev/cloud.google.com/go/websecurityscanner/apiv1", + "release_level": "beta" + }, "cloud.google.com/go/workflows/apiv1beta": { "distribution_name": "cloud.google.com/go/workflows/apiv1beta", "description": "", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 1df0d7533938..4647978fe237 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -833,6 +833,15 @@ var microgenGapicConfigs = []*microgenConfig{ // GA after 2020/11/12 releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/websecurityscanner/v1", + pkg: "websecurityscanner", + importPath: "cloud.google.com/go/websecurityscanner/apiv1", + gRPCServiceConfigPath: "google/cloud/websecurityscanner/v1/websecurityscanner_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/websecurityscanner/v1/websecurityscanner_v1.yaml", + // GA after 2020/13/12 + releaseLevel: "beta", + }, // Non-Cloud APIs { diff --git a/websecurityscanner/apiv1/doc.go b/websecurityscanner/apiv1/doc.go new file mode 100644 index 000000000000..51545184bf3d --- /dev/null +++ b/websecurityscanner/apiv1/doc.go @@ -0,0 +1,106 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +// Package websecurityscanner is an auto-generated package for the +// Web Security Scanner API. +// +// Scans your Compute and App Engine apps for common web vulnerabilities. +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// Use of Context +// +// The ctx passed to NewClient is used for authentication requests and +// for creating the underlying connection, but is not used for subsequent calls. +// Individual methods on the client use the ctx given to them. +// +// To close the open connection, use the Close() method. +// +// For information about setting deadlines, reusing contexts, and more +// please visit godoc.org/cloud.google.com/go. +package websecurityscanner // import "cloud.google.com/go/websecurityscanner/apiv1" + +import ( + "context" + "runtime" + "strings" + "unicode" + + "google.golang.org/api/option" + "google.golang.org/grpc/metadata" +) + +// For more information on implementing a client constructor hook, see +// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. +type clientHookParams struct{} +type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) + +const versionClient = "20201013" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/websecurityscanner/apiv1/web_security_scanner_client.go b/websecurityscanner/apiv1/web_security_scanner_client.go new file mode 100644 index 000000000000..50ec6d706b64 --- /dev/null +++ b/websecurityscanner/apiv1/web_security_scanner_client.go @@ -0,0 +1,753 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package websecurityscanner + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + gtransport "google.golang.org/api/transport/grpc" + websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newClientHook clientHook + +// CallOptions contains the retry settings for each method of Client. +type CallOptions struct { + CreateScanConfig []gax.CallOption + DeleteScanConfig []gax.CallOption + GetScanConfig []gax.CallOption + ListScanConfigs []gax.CallOption + UpdateScanConfig []gax.CallOption + StartScanRun []gax.CallOption + GetScanRun []gax.CallOption + ListScanRuns []gax.CallOption + StopScanRun []gax.CallOption + ListCrawledUrls []gax.CallOption + GetFinding []gax.CallOption + ListFindings []gax.CallOption + ListFindingTypeStats []gax.CallOption +} + +func defaultClientOptions() []option.ClientOption { + return []option.ClientOption{ + option.WithEndpoint("websecurityscanner.googleapis.com:443"), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + CreateScanConfig: []gax.CallOption{}, + DeleteScanConfig: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetScanConfig: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListScanConfigs: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateScanConfig: []gax.CallOption{}, + StartScanRun: []gax.CallOption{}, + GetScanRun: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListScanRuns: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + StopScanRun: []gax.CallOption{}, + ListCrawledUrls: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetFinding: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListFindings: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListFindingTypeStats: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// Client is a client for interacting with Web Security Scanner API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type Client struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // The gRPC API client. + client websecurityscannerpb.WebSecurityScannerClient + + // The call options for this service. + CallOptions *CallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new web security scanner client. +// +// Web Security Scanner Service identifies security vulnerabilities in web +// applications hosted on Google Cloud. It crawls your application, and +// attempts to exercise as many user inputs and event handlers as possible. +func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { + clientOpts := defaultClientOptions() + + if newClientHook != nil { + hookOpts, err := newClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &Client{ + connPool: connPool, + CallOptions: defaultCallOptions(), + + client: websecurityscannerpb.NewWebSecurityScannerClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *Client) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *Client) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *Client) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateScanConfig creates a new ScanConfig. +func (c *Client) CreateScanConfig(ctx context.Context, req *websecurityscannerpb.CreateScanConfigRequest, opts ...gax.CallOption) (*websecurityscannerpb.ScanConfig, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateScanConfig[0:len(c.CallOptions.CreateScanConfig):len(c.CallOptions.CreateScanConfig)], opts...) + var resp *websecurityscannerpb.ScanConfig + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateScanConfig(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteScanConfig deletes an existing ScanConfig and its child resources. +func (c *Client) DeleteScanConfig(ctx context.Context, req *websecurityscannerpb.DeleteScanConfigRequest, opts ...gax.CallOption) error { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteScanConfig[0:len(c.CallOptions.DeleteScanConfig):len(c.CallOptions.DeleteScanConfig)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteScanConfig(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// GetScanConfig gets a ScanConfig. +func (c *Client) GetScanConfig(ctx context.Context, req *websecurityscannerpb.GetScanConfigRequest, opts ...gax.CallOption) (*websecurityscannerpb.ScanConfig, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetScanConfig[0:len(c.CallOptions.GetScanConfig):len(c.CallOptions.GetScanConfig)], opts...) + var resp *websecurityscannerpb.ScanConfig + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetScanConfig(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListScanConfigs lists ScanConfigs under a given project. +func (c *Client) ListScanConfigs(ctx context.Context, req *websecurityscannerpb.ListScanConfigsRequest, opts ...gax.CallOption) *ScanConfigIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListScanConfigs[0:len(c.CallOptions.ListScanConfigs):len(c.CallOptions.ListScanConfigs)], opts...) + it := &ScanConfigIterator{} + req = proto.Clone(req).(*websecurityscannerpb.ListScanConfigsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*websecurityscannerpb.ScanConfig, string, error) { + var resp *websecurityscannerpb.ListScanConfigsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListScanConfigs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.ScanConfigs, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// UpdateScanConfig updates a ScanConfig. This method support partial update of a ScanConfig. +func (c *Client) UpdateScanConfig(ctx context.Context, req *websecurityscannerpb.UpdateScanConfigRequest, opts ...gax.CallOption) (*websecurityscannerpb.ScanConfig, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "scan_config.name", url.QueryEscape(req.GetScanConfig().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateScanConfig[0:len(c.CallOptions.UpdateScanConfig):len(c.CallOptions.UpdateScanConfig)], opts...) + var resp *websecurityscannerpb.ScanConfig + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateScanConfig(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// StartScanRun start a ScanRun according to the given ScanConfig. +func (c *Client) StartScanRun(ctx context.Context, req *websecurityscannerpb.StartScanRunRequest, opts ...gax.CallOption) (*websecurityscannerpb.ScanRun, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.StartScanRun[0:len(c.CallOptions.StartScanRun):len(c.CallOptions.StartScanRun)], opts...) + var resp *websecurityscannerpb.ScanRun + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.StartScanRun(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetScanRun gets a ScanRun. +func (c *Client) GetScanRun(ctx context.Context, req *websecurityscannerpb.GetScanRunRequest, opts ...gax.CallOption) (*websecurityscannerpb.ScanRun, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetScanRun[0:len(c.CallOptions.GetScanRun):len(c.CallOptions.GetScanRun)], opts...) + var resp *websecurityscannerpb.ScanRun + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetScanRun(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListScanRuns lists ScanRuns under a given ScanConfig, in descending order of ScanRun +// stop time. +func (c *Client) ListScanRuns(ctx context.Context, req *websecurityscannerpb.ListScanRunsRequest, opts ...gax.CallOption) *ScanRunIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListScanRuns[0:len(c.CallOptions.ListScanRuns):len(c.CallOptions.ListScanRuns)], opts...) + it := &ScanRunIterator{} + req = proto.Clone(req).(*websecurityscannerpb.ListScanRunsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*websecurityscannerpb.ScanRun, string, error) { + var resp *websecurityscannerpb.ListScanRunsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListScanRuns(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.ScanRuns, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// StopScanRun stops a ScanRun. The stopped ScanRun is returned. +func (c *Client) StopScanRun(ctx context.Context, req *websecurityscannerpb.StopScanRunRequest, opts ...gax.CallOption) (*websecurityscannerpb.ScanRun, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.StopScanRun[0:len(c.CallOptions.StopScanRun):len(c.CallOptions.StopScanRun)], opts...) + var resp *websecurityscannerpb.ScanRun + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.StopScanRun(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListCrawledUrls list CrawledUrls under a given ScanRun. +func (c *Client) ListCrawledUrls(ctx context.Context, req *websecurityscannerpb.ListCrawledUrlsRequest, opts ...gax.CallOption) *CrawledUrlIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListCrawledUrls[0:len(c.CallOptions.ListCrawledUrls):len(c.CallOptions.ListCrawledUrls)], opts...) + it := &CrawledUrlIterator{} + req = proto.Clone(req).(*websecurityscannerpb.ListCrawledUrlsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*websecurityscannerpb.CrawledUrl, string, error) { + var resp *websecurityscannerpb.ListCrawledUrlsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListCrawledUrls(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.CrawledUrls, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// GetFinding gets a Finding. +func (c *Client) GetFinding(ctx context.Context, req *websecurityscannerpb.GetFindingRequest, opts ...gax.CallOption) (*websecurityscannerpb.Finding, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetFinding[0:len(c.CallOptions.GetFinding):len(c.CallOptions.GetFinding)], opts...) + var resp *websecurityscannerpb.Finding + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetFinding(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListFindings list Findings under a given ScanRun. +func (c *Client) ListFindings(ctx context.Context, req *websecurityscannerpb.ListFindingsRequest, opts ...gax.CallOption) *FindingIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListFindings[0:len(c.CallOptions.ListFindings):len(c.CallOptions.ListFindings)], opts...) + it := &FindingIterator{} + req = proto.Clone(req).(*websecurityscannerpb.ListFindingsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*websecurityscannerpb.Finding, string, error) { + var resp *websecurityscannerpb.ListFindingsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListFindings(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.Findings, resp.NextPageToken, nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.PageSize) + it.pageInfo.Token = req.PageToken + return it +} + +// ListFindingTypeStats list all FindingTypeStats under a given ScanRun. +func (c *Client) ListFindingTypeStats(ctx context.Context, req *websecurityscannerpb.ListFindingTypeStatsRequest, opts ...gax.CallOption) (*websecurityscannerpb.ListFindingTypeStatsResponse, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListFindingTypeStats[0:len(c.CallOptions.ListFindingTypeStats):len(c.CallOptions.ListFindingTypeStats)], opts...) + var resp *websecurityscannerpb.ListFindingTypeStatsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListFindingTypeStats(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CrawledUrlIterator manages a stream of *websecurityscannerpb.CrawledUrl. +type CrawledUrlIterator struct { + items []*websecurityscannerpb.CrawledUrl + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*websecurityscannerpb.CrawledUrl, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *CrawledUrlIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *CrawledUrlIterator) Next() (*websecurityscannerpb.CrawledUrl, error) { + var item *websecurityscannerpb.CrawledUrl + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *CrawledUrlIterator) bufLen() int { + return len(it.items) +} + +func (it *CrawledUrlIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// FindingIterator manages a stream of *websecurityscannerpb.Finding. +type FindingIterator struct { + items []*websecurityscannerpb.Finding + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*websecurityscannerpb.Finding, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *FindingIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *FindingIterator) Next() (*websecurityscannerpb.Finding, error) { + var item *websecurityscannerpb.Finding + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *FindingIterator) bufLen() int { + return len(it.items) +} + +func (it *FindingIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// ScanConfigIterator manages a stream of *websecurityscannerpb.ScanConfig. +type ScanConfigIterator struct { + items []*websecurityscannerpb.ScanConfig + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*websecurityscannerpb.ScanConfig, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ScanConfigIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *ScanConfigIterator) Next() (*websecurityscannerpb.ScanConfig, error) { + var item *websecurityscannerpb.ScanConfig + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ScanConfigIterator) bufLen() int { + return len(it.items) +} + +func (it *ScanConfigIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// ScanRunIterator manages a stream of *websecurityscannerpb.ScanRun. +type ScanRunIterator struct { + items []*websecurityscannerpb.ScanRun + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*websecurityscannerpb.ScanRun, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ScanRunIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *ScanRunIterator) Next() (*websecurityscannerpb.ScanRun, error) { + var item *websecurityscannerpb.ScanRun + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ScanRunIterator) bufLen() int { + return len(it.items) +} + +func (it *ScanRunIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/websecurityscanner/apiv1/web_security_scanner_client_example_test.go b/websecurityscanner/apiv1/web_security_scanner_client_example_test.go new file mode 100644 index 000000000000..9b3732fd1f89 --- /dev/null +++ b/websecurityscanner/apiv1/web_security_scanner_client_example_test.go @@ -0,0 +1,319 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package websecurityscanner_test + +import ( + "context" + + websecurityscanner "cloud.google.com/go/websecurityscanner/apiv1" + "google.golang.org/api/iterator" + websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleClient_CreateScanConfig() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.CreateScanConfigRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateScanConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteScanConfig() { + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.DeleteScanConfigRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteScanConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetScanConfig() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.GetScanConfigRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetScanConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListScanConfigs() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.ListScanConfigsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListScanConfigs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_UpdateScanConfig() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.UpdateScanConfigRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateScanConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_StartScanRun() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.StartScanRunRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.StartScanRun(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_GetScanRun() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.GetScanRunRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetScanRun(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListScanRuns() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.ListScanRunsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListScanRuns(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_StopScanRun() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.StopScanRunRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.StopScanRun(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListCrawledUrls() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.ListCrawledUrlsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListCrawledUrls(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_GetFinding() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.GetFindingRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetFinding(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListFindings() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.ListFindingsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListFindings(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_ListFindingTypeStats() { + // import websecurityscannerpb "google.golang.org/genproto/googleapis/cloud/websecurityscanner/v1" + + ctx := context.Background() + c, err := websecurityscanner.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &websecurityscannerpb.ListFindingTypeStatsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListFindingTypeStats(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +}