...

Source file src/google.golang.org/api/policyanalyzer/v1beta1/policyanalyzer-gen.go

Documentation: google.golang.org/api/policyanalyzer/v1beta1

     1  // Copyright 2024 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Code generated file. DO NOT EDIT.
     6  
     7  // Package policyanalyzer provides access to the Policy Analyzer API.
     8  //
     9  // For product documentation, see: https://www.google.com
    10  //
    11  // # Library status
    12  //
    13  // These client libraries are officially supported by Google. However, this
    14  // library is considered complete and is in maintenance mode. This means
    15  // that we will address critical bugs and security issues but will not add
    16  // any new features.
    17  //
    18  // When possible, we recommend using our newer
    19  // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    20  // that are still actively being worked and iterated on.
    21  //
    22  // # Creating a client
    23  //
    24  // Usage example:
    25  //
    26  //	import "google.golang.org/api/policyanalyzer/v1beta1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	policyanalyzerService, err := policyanalyzer.NewService(ctx)
    30  //
    31  // In this example, Google Application Default Credentials are used for
    32  // authentication. For information on how to create and obtain Application
    33  // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    34  //
    35  // # Other authentication options
    36  //
    37  // To use an API key for authentication (note: some APIs do not support API
    38  // keys), use [google.golang.org/api/option.WithAPIKey]:
    39  //
    40  //	policyanalyzerService, err := policyanalyzer.NewService(ctx, option.WithAPIKey("AIza..."))
    41  //
    42  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    43  // flow, use [google.golang.org/api/option.WithTokenSource]:
    44  //
    45  //	config := &oauth2.Config{...}
    46  //	// ...
    47  //	token, err := config.Exchange(ctx, ...)
    48  //	policyanalyzerService, err := policyanalyzer.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package policyanalyzer // import "google.golang.org/api/policyanalyzer/v1beta1"
    52  
    53  import (
    54  	"bytes"
    55  	"context"
    56  	"encoding/json"
    57  	"errors"
    58  	"fmt"
    59  	"io"
    60  	"net/http"
    61  	"net/url"
    62  	"strconv"
    63  	"strings"
    64  
    65  	googleapi "google.golang.org/api/googleapi"
    66  	internal "google.golang.org/api/internal"
    67  	gensupport "google.golang.org/api/internal/gensupport"
    68  	option "google.golang.org/api/option"
    69  	internaloption "google.golang.org/api/option/internaloption"
    70  	htransport "google.golang.org/api/transport/http"
    71  )
    72  
    73  // Always reference these packages, just in case the auto-generated code
    74  // below doesn't.
    75  var _ = bytes.NewBuffer
    76  var _ = strconv.Itoa
    77  var _ = fmt.Sprintf
    78  var _ = json.NewDecoder
    79  var _ = io.Copy
    80  var _ = url.Parse
    81  var _ = gensupport.MarshalJSON
    82  var _ = googleapi.Version
    83  var _ = errors.New
    84  var _ = strings.Replace
    85  var _ = context.Canceled
    86  var _ = internaloption.WithDefaultEndpoint
    87  var _ = internal.Version
    88  
    89  const apiId = "policyanalyzer:v1beta1"
    90  const apiName = "policyanalyzer"
    91  const apiVersion = "v1beta1"
    92  const basePath = "https://policyanalyzer.googleapis.com/"
    93  const basePathTemplate = "https://policyanalyzer.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://policyanalyzer.mtls.googleapis.com/"
    95  
    96  // OAuth2 scopes used by this API.
    97  const (
    98  	// See, edit, configure, and delete your Google Cloud data and see the email
    99  	// address for your Google Account.
   100  	CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
   101  )
   102  
   103  // NewService creates a new Service.
   104  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   105  	scopesOption := internaloption.WithDefaultScopes(
   106  		"https://www.googleapis.com/auth/cloud-platform",
   107  	)
   108  	// NOTE: prepend, so we don't override user-specified scopes.
   109  	opts = append([]option.ClientOption{scopesOption}, opts...)
   110  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   111  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   112  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   113  	opts = append(opts, internaloption.EnableNewAuthLibrary())
   114  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  	s, err := New(client)
   119  	if err != nil {
   120  		return nil, err
   121  	}
   122  	if endpoint != "" {
   123  		s.BasePath = endpoint
   124  	}
   125  	return s, nil
   126  }
   127  
   128  // New creates a new Service. It uses the provided http.Client for requests.
   129  //
   130  // Deprecated: please use NewService instead.
   131  // To provide a custom HTTP client, use option.WithHTTPClient.
   132  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   133  func New(client *http.Client) (*Service, error) {
   134  	if client == nil {
   135  		return nil, errors.New("client is nil")
   136  	}
   137  	s := &Service{client: client, BasePath: basePath}
   138  	s.Projects = NewProjectsService(s)
   139  	return s, nil
   140  }
   141  
   142  type Service struct {
   143  	client    *http.Client
   144  	BasePath  string // API endpoint base URL
   145  	UserAgent string // optional additional User-Agent fragment
   146  
   147  	Projects *ProjectsService
   148  }
   149  
   150  func (s *Service) userAgent() string {
   151  	if s.UserAgent == "" {
   152  		return googleapi.UserAgent
   153  	}
   154  	return googleapi.UserAgent + " " + s.UserAgent
   155  }
   156  
   157  func NewProjectsService(s *Service) *ProjectsService {
   158  	rs := &ProjectsService{s: s}
   159  	rs.Locations = NewProjectsLocationsService(s)
   160  	return rs
   161  }
   162  
   163  type ProjectsService struct {
   164  	s *Service
   165  
   166  	Locations *ProjectsLocationsService
   167  }
   168  
   169  func NewProjectsLocationsService(s *Service) *ProjectsLocationsService {
   170  	rs := &ProjectsLocationsService{s: s}
   171  	rs.ActivityTypes = NewProjectsLocationsActivityTypesService(s)
   172  	return rs
   173  }
   174  
   175  type ProjectsLocationsService struct {
   176  	s *Service
   177  
   178  	ActivityTypes *ProjectsLocationsActivityTypesService
   179  }
   180  
   181  func NewProjectsLocationsActivityTypesService(s *Service) *ProjectsLocationsActivityTypesService {
   182  	rs := &ProjectsLocationsActivityTypesService{s: s}
   183  	rs.Activities = NewProjectsLocationsActivityTypesActivitiesService(s)
   184  	return rs
   185  }
   186  
   187  type ProjectsLocationsActivityTypesService struct {
   188  	s *Service
   189  
   190  	Activities *ProjectsLocationsActivityTypesActivitiesService
   191  }
   192  
   193  func NewProjectsLocationsActivityTypesActivitiesService(s *Service) *ProjectsLocationsActivityTypesActivitiesService {
   194  	rs := &ProjectsLocationsActivityTypesActivitiesService{s: s}
   195  	return rs
   196  }
   197  
   198  type ProjectsLocationsActivityTypesActivitiesService struct {
   199  	s *Service
   200  }
   201  
   202  type GoogleCloudPolicyanalyzerV1beta1Activity struct {
   203  	// Activity: A struct of custom fields to explain the activity.
   204  	Activity googleapi.RawMessage `json:"activity,omitempty"`
   205  	// ActivityType: The type of the activity.
   206  	ActivityType string `json:"activityType,omitempty"`
   207  	// FullResourceName: The full resource name that identifies the resource. For
   208  	// examples of full resource names for Google Cloud services, see
   209  	// https://cloud.google.com/iam/help/troubleshooter/full-resource-names.
   210  	FullResourceName string `json:"fullResourceName,omitempty"`
   211  	// ObservationPeriod: The data observation period to build the activity.
   212  	ObservationPeriod *GoogleCloudPolicyanalyzerV1beta1ObservationPeriod `json:"observationPeriod,omitempty"`
   213  	// ForceSendFields is a list of field names (e.g. "Activity") to
   214  	// unconditionally include in API requests. By default, fields with empty or
   215  	// default values are omitted from API requests. See
   216  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   217  	// details.
   218  	ForceSendFields []string `json:"-"`
   219  	// NullFields is a list of field names (e.g. "Activity") to include in API
   220  	// requests with the JSON null value. By default, fields with empty values are
   221  	// omitted from API requests. See
   222  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   223  	NullFields []string `json:"-"`
   224  }
   225  
   226  func (s *GoogleCloudPolicyanalyzerV1beta1Activity) MarshalJSON() ([]byte, error) {
   227  	type NoMethod GoogleCloudPolicyanalyzerV1beta1Activity
   228  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   229  }
   230  
   231  // GoogleCloudPolicyanalyzerV1beta1ObservationPeriod: Represents data
   232  // observation period.
   233  type GoogleCloudPolicyanalyzerV1beta1ObservationPeriod struct {
   234  	// EndTime: The observation end time.
   235  	EndTime string `json:"endTime,omitempty"`
   236  	// StartTime: The observation start time.
   237  	StartTime string `json:"startTime,omitempty"`
   238  	// ForceSendFields is a list of field names (e.g. "EndTime") to unconditionally
   239  	// include in API requests. By default, fields with empty or default values are
   240  	// omitted from API requests. See
   241  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   242  	// details.
   243  	ForceSendFields []string `json:"-"`
   244  	// NullFields is a list of field names (e.g. "EndTime") to include in API
   245  	// requests with the JSON null value. By default, fields with empty values are
   246  	// omitted from API requests. See
   247  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   248  	NullFields []string `json:"-"`
   249  }
   250  
   251  func (s *GoogleCloudPolicyanalyzerV1beta1ObservationPeriod) MarshalJSON() ([]byte, error) {
   252  	type NoMethod GoogleCloudPolicyanalyzerV1beta1ObservationPeriod
   253  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   254  }
   255  
   256  // GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse: Response to the
   257  // `QueryActivity` method.
   258  type GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse struct {
   259  	// Activities: The set of activities that match the filter included in the
   260  	// request.
   261  	Activities []*GoogleCloudPolicyanalyzerV1beta1Activity `json:"activities,omitempty"`
   262  	// NextPageToken: If there might be more results than those appearing in this
   263  	// response, then `nextPageToken` is included. To get the next set of results,
   264  	// call this method again using the value of `nextPageToken` as `pageToken`.
   265  	NextPageToken string `json:"nextPageToken,omitempty"`
   266  
   267  	// ServerResponse contains the HTTP response code and headers from the server.
   268  	googleapi.ServerResponse `json:"-"`
   269  	// ForceSendFields is a list of field names (e.g. "Activities") to
   270  	// unconditionally include in API requests. By default, fields with empty or
   271  	// default values are omitted from API requests. See
   272  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   273  	// details.
   274  	ForceSendFields []string `json:"-"`
   275  	// NullFields is a list of field names (e.g. "Activities") to include in API
   276  	// requests with the JSON null value. By default, fields with empty values are
   277  	// omitted from API requests. See
   278  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   279  	NullFields []string `json:"-"`
   280  }
   281  
   282  func (s *GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse) MarshalJSON() ([]byte, error) {
   283  	type NoMethod GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse
   284  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   285  }
   286  
   287  type ProjectsLocationsActivityTypesActivitiesQueryCall struct {
   288  	s            *Service
   289  	parent       string
   290  	urlParams_   gensupport.URLParams
   291  	ifNoneMatch_ string
   292  	ctx_         context.Context
   293  	header_      http.Header
   294  }
   295  
   296  // Query: Queries policy activities on GCP resources.
   297  //
   298  //   - parent: The container resource on which to execute the request. Acceptable
   299  //     formats:
   300  //     `projects/[PROJECT_ID|PROJECT_NUMBER]/locations/[LOCATION]/activityTypes/[A
   301  //     CTIVITY_TYPE]` LOCATION here refers to GCP Locations:
   302  //     https://cloud.google.com/about/locations/.
   303  func (r *ProjectsLocationsActivityTypesActivitiesService) Query(parent string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   304  	c := &ProjectsLocationsActivityTypesActivitiesQueryCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   305  	c.parent = parent
   306  	return c
   307  }
   308  
   309  // Filter sets the optional parameter "filter": Optional filter expression to
   310  // restrict the activities returned. Supported filters are: -
   311  // service_account_last_authn.full_resource_name {=} -
   312  // service_account_key_last_authn.full_resource_name {=}
   313  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Filter(filter string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   314  	c.urlParams_.Set("filter", filter)
   315  	return c
   316  }
   317  
   318  // PageSize sets the optional parameter "pageSize": The maximum number of
   319  // results to return from this request. Max limit is 1000. Non-positive values
   320  // are ignored. The presence of `nextPageToken` in the response indicates that
   321  // more results might be available.
   322  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) PageSize(pageSize int64) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   323  	c.urlParams_.Set("pageSize", fmt.Sprint(pageSize))
   324  	return c
   325  }
   326  
   327  // PageToken sets the optional parameter "pageToken": If present, then retrieve
   328  // the next batch of results from the preceding call to this method.
   329  // `pageToken` must be the value of `nextPageToken` from the previous response.
   330  // The values of other method parameters should be identical to those in the
   331  // previous call.
   332  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) PageToken(pageToken string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   333  	c.urlParams_.Set("pageToken", pageToken)
   334  	return c
   335  }
   336  
   337  // Fields allows partial responses to be retrieved. See
   338  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   339  // details.
   340  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Fields(s ...googleapi.Field) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   341  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   342  	return c
   343  }
   344  
   345  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   346  // object's ETag matches the given value. This is useful for getting updates
   347  // only after the object has changed since the last request.
   348  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) IfNoneMatch(entityTag string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   349  	c.ifNoneMatch_ = entityTag
   350  	return c
   351  }
   352  
   353  // Context sets the context to be used in this call's Do method.
   354  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Context(ctx context.Context) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   355  	c.ctx_ = ctx
   356  	return c
   357  }
   358  
   359  // Header returns a http.Header that can be modified by the caller to add
   360  // headers to the request.
   361  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Header() http.Header {
   362  	if c.header_ == nil {
   363  		c.header_ = make(http.Header)
   364  	}
   365  	return c.header_
   366  }
   367  
   368  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) doRequest(alt string) (*http.Response, error) {
   369  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   370  	if c.ifNoneMatch_ != "" {
   371  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   372  	}
   373  	var body io.Reader = nil
   374  	c.urlParams_.Set("alt", alt)
   375  	c.urlParams_.Set("prettyPrint", "false")
   376  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/{+parent}/activities:query")
   377  	urls += "?" + c.urlParams_.Encode()
   378  	req, err := http.NewRequest("GET", urls, body)
   379  	if err != nil {
   380  		return nil, err
   381  	}
   382  	req.Header = reqHeaders
   383  	googleapi.Expand(req.URL, map[string]string{
   384  		"parent": c.parent,
   385  	})
   386  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   387  }
   388  
   389  // Do executes the "policyanalyzer.projects.locations.activityTypes.activities.query" call.
   390  // Any non-2xx status code is an error. Response headers are in either
   391  // *GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse.ServerResponse.Header
   392  // or (if a response was returned at all) in error.(*googleapi.Error).Header.
   393  // Use googleapi.IsNotModified to check whether the returned error was because
   394  // http.StatusNotModified was returned.
   395  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Do(opts ...googleapi.CallOption) (*GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse, error) {
   396  	gensupport.SetOptions(c.urlParams_, opts...)
   397  	res, err := c.doRequest("json")
   398  	if res != nil && res.StatusCode == http.StatusNotModified {
   399  		if res.Body != nil {
   400  			res.Body.Close()
   401  		}
   402  		return nil, gensupport.WrapError(&googleapi.Error{
   403  			Code:   res.StatusCode,
   404  			Header: res.Header,
   405  		})
   406  	}
   407  	if err != nil {
   408  		return nil, err
   409  	}
   410  	defer googleapi.CloseBody(res)
   411  	if err := googleapi.CheckResponse(res); err != nil {
   412  		return nil, gensupport.WrapError(err)
   413  	}
   414  	ret := &GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse{
   415  		ServerResponse: googleapi.ServerResponse{
   416  			Header:         res.Header,
   417  			HTTPStatusCode: res.StatusCode,
   418  		},
   419  	}
   420  	target := &ret
   421  	if err := gensupport.DecodeResponse(target, res); err != nil {
   422  		return nil, err
   423  	}
   424  	return ret, nil
   425  }
   426  
   427  // Pages invokes f for each page of results.
   428  // A non-nil error returned from f will halt the iteration.
   429  // The provided context supersedes any context provided to the Context method.
   430  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Pages(ctx context.Context, f func(*GoogleCloudPolicyanalyzerV1beta1QueryActivityResponse) error) error {
   431  	c.ctx_ = ctx
   432  	defer c.PageToken(c.urlParams_.Get("pageToken"))
   433  	for {
   434  		x, err := c.Do()
   435  		if err != nil {
   436  			return err
   437  		}
   438  		if err := f(x); err != nil {
   439  			return err
   440  		}
   441  		if x.NextPageToken == "" {
   442  			return nil
   443  		}
   444  		c.PageToken(x.NextPageToken)
   445  	}
   446  }
   447  

View as plain text