...

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

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

     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/v1"
    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/v1"
    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:v1"
    90  const apiName = "policyanalyzer"
    91  const apiVersion = "v1"
    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 GoogleCloudPolicyanalyzerV1Activity 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 *GoogleCloudPolicyanalyzerV1ObservationPeriod `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 *GoogleCloudPolicyanalyzerV1Activity) MarshalJSON() ([]byte, error) {
   227  	type NoMethod GoogleCloudPolicyanalyzerV1Activity
   228  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   229  }
   230  
   231  // GoogleCloudPolicyanalyzerV1ObservationPeriod: Represents data observation
   232  // period.
   233  type GoogleCloudPolicyanalyzerV1ObservationPeriod struct {
   234  	// EndTime: The observation end time. The time in this timestamp is always
   235  	// `07:00:00Z`.
   236  	EndTime string `json:"endTime,omitempty"`
   237  	// StartTime: The observation start time. The time in this timestamp is always
   238  	// `07:00:00Z`.
   239  	StartTime string `json:"startTime,omitempty"`
   240  	// ForceSendFields is a list of field names (e.g. "EndTime") to unconditionally
   241  	// include in API requests. By default, fields with empty or default values are
   242  	// omitted from API requests. See
   243  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   244  	// details.
   245  	ForceSendFields []string `json:"-"`
   246  	// NullFields is a list of field names (e.g. "EndTime") to include in API
   247  	// requests with the JSON null value. By default, fields with empty values are
   248  	// omitted from API requests. See
   249  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   250  	NullFields []string `json:"-"`
   251  }
   252  
   253  func (s *GoogleCloudPolicyanalyzerV1ObservationPeriod) MarshalJSON() ([]byte, error) {
   254  	type NoMethod GoogleCloudPolicyanalyzerV1ObservationPeriod
   255  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   256  }
   257  
   258  // GoogleCloudPolicyanalyzerV1QueryActivityResponse: Response to the
   259  // `QueryActivity` method.
   260  type GoogleCloudPolicyanalyzerV1QueryActivityResponse struct {
   261  	// Activities: The set of activities that match the filter included in the
   262  	// request.
   263  	Activities []*GoogleCloudPolicyanalyzerV1Activity `json:"activities,omitempty"`
   264  	// NextPageToken: If there might be more results than those appearing in this
   265  	// response, then `nextPageToken` is included. To get the next set of results,
   266  	// call this method again using the value of `nextPageToken` as `pageToken`.
   267  	NextPageToken string `json:"nextPageToken,omitempty"`
   268  
   269  	// ServerResponse contains the HTTP response code and headers from the server.
   270  	googleapi.ServerResponse `json:"-"`
   271  	// ForceSendFields is a list of field names (e.g. "Activities") to
   272  	// unconditionally include in API requests. By default, fields with empty or
   273  	// default values are omitted from API requests. See
   274  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   275  	// details.
   276  	ForceSendFields []string `json:"-"`
   277  	// NullFields is a list of field names (e.g. "Activities") to include in API
   278  	// requests with the JSON null value. By default, fields with empty values are
   279  	// omitted from API requests. See
   280  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   281  	NullFields []string `json:"-"`
   282  }
   283  
   284  func (s *GoogleCloudPolicyanalyzerV1QueryActivityResponse) MarshalJSON() ([]byte, error) {
   285  	type NoMethod GoogleCloudPolicyanalyzerV1QueryActivityResponse
   286  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   287  }
   288  
   289  type ProjectsLocationsActivityTypesActivitiesQueryCall struct {
   290  	s            *Service
   291  	parent       string
   292  	urlParams_   gensupport.URLParams
   293  	ifNoneMatch_ string
   294  	ctx_         context.Context
   295  	header_      http.Header
   296  }
   297  
   298  // Query: Queries policy activities on Google Cloud resources.
   299  //
   300  //   - parent: The container resource on which to execute the request. Acceptable
   301  //     formats:
   302  //     `projects/[PROJECT_ID|PROJECT_NUMBER]/locations/[LOCATION]/activityTypes/[A
   303  //     CTIVITY_TYPE]` LOCATION here refers to Google Cloud Locations:
   304  //     https://cloud.google.com/about/locations/.
   305  func (r *ProjectsLocationsActivityTypesActivitiesService) Query(parent string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   306  	c := &ProjectsLocationsActivityTypesActivitiesQueryCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   307  	c.parent = parent
   308  	return c
   309  }
   310  
   311  // Filter sets the optional parameter "filter": Filter expression to restrict
   312  // the activities returned. For serviceAccountLastAuthentication activities,
   313  // supported filters are: - `activities.full_resource_name {=} [STRING]` -
   314  // `activities.fullResourceName {=} [STRING]` where `[STRING]` is the full
   315  // resource name of the service account. For
   316  // serviceAccountKeyLastAuthentication activities, supported filters are: -
   317  // `activities.full_resource_name {=} [STRING]` - `activities.fullResourceName
   318  // {=} [STRING]` where `[STRING]` is the full resource name of the service
   319  // account key.
   320  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Filter(filter string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   321  	c.urlParams_.Set("filter", filter)
   322  	return c
   323  }
   324  
   325  // PageSize sets the optional parameter "pageSize": The maximum number of
   326  // results to return from this request. Max limit is 1000. Non-positive values
   327  // are ignored. The presence of `nextPageToken` in the response indicates that
   328  // more results might be available.
   329  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) PageSize(pageSize int64) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   330  	c.urlParams_.Set("pageSize", fmt.Sprint(pageSize))
   331  	return c
   332  }
   333  
   334  // PageToken sets the optional parameter "pageToken": If present, then retrieve
   335  // the next batch of results from the preceding call to this method.
   336  // `pageToken` must be the value of `nextPageToken` from the previous response.
   337  // The values of other method parameters should be identical to those in the
   338  // previous call.
   339  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) PageToken(pageToken string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   340  	c.urlParams_.Set("pageToken", pageToken)
   341  	return c
   342  }
   343  
   344  // Fields allows partial responses to be retrieved. See
   345  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   346  // details.
   347  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Fields(s ...googleapi.Field) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   348  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   349  	return c
   350  }
   351  
   352  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   353  // object's ETag matches the given value. This is useful for getting updates
   354  // only after the object has changed since the last request.
   355  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) IfNoneMatch(entityTag string) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   356  	c.ifNoneMatch_ = entityTag
   357  	return c
   358  }
   359  
   360  // Context sets the context to be used in this call's Do method.
   361  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Context(ctx context.Context) *ProjectsLocationsActivityTypesActivitiesQueryCall {
   362  	c.ctx_ = ctx
   363  	return c
   364  }
   365  
   366  // Header returns a http.Header that can be modified by the caller to add
   367  // headers to the request.
   368  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Header() http.Header {
   369  	if c.header_ == nil {
   370  		c.header_ = make(http.Header)
   371  	}
   372  	return c.header_
   373  }
   374  
   375  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) doRequest(alt string) (*http.Response, error) {
   376  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   377  	if c.ifNoneMatch_ != "" {
   378  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   379  	}
   380  	var body io.Reader = nil
   381  	c.urlParams_.Set("alt", alt)
   382  	c.urlParams_.Set("prettyPrint", "false")
   383  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+parent}/activities:query")
   384  	urls += "?" + c.urlParams_.Encode()
   385  	req, err := http.NewRequest("GET", urls, body)
   386  	if err != nil {
   387  		return nil, err
   388  	}
   389  	req.Header = reqHeaders
   390  	googleapi.Expand(req.URL, map[string]string{
   391  		"parent": c.parent,
   392  	})
   393  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   394  }
   395  
   396  // Do executes the "policyanalyzer.projects.locations.activityTypes.activities.query" call.
   397  // Any non-2xx status code is an error. Response headers are in either
   398  // *GoogleCloudPolicyanalyzerV1QueryActivityResponse.ServerResponse.Header or
   399  // (if a response was returned at all) in error.(*googleapi.Error).Header. Use
   400  // googleapi.IsNotModified to check whether the returned error was because
   401  // http.StatusNotModified was returned.
   402  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Do(opts ...googleapi.CallOption) (*GoogleCloudPolicyanalyzerV1QueryActivityResponse, error) {
   403  	gensupport.SetOptions(c.urlParams_, opts...)
   404  	res, err := c.doRequest("json")
   405  	if res != nil && res.StatusCode == http.StatusNotModified {
   406  		if res.Body != nil {
   407  			res.Body.Close()
   408  		}
   409  		return nil, gensupport.WrapError(&googleapi.Error{
   410  			Code:   res.StatusCode,
   411  			Header: res.Header,
   412  		})
   413  	}
   414  	if err != nil {
   415  		return nil, err
   416  	}
   417  	defer googleapi.CloseBody(res)
   418  	if err := googleapi.CheckResponse(res); err != nil {
   419  		return nil, gensupport.WrapError(err)
   420  	}
   421  	ret := &GoogleCloudPolicyanalyzerV1QueryActivityResponse{
   422  		ServerResponse: googleapi.ServerResponse{
   423  			Header:         res.Header,
   424  			HTTPStatusCode: res.StatusCode,
   425  		},
   426  	}
   427  	target := &ret
   428  	if err := gensupport.DecodeResponse(target, res); err != nil {
   429  		return nil, err
   430  	}
   431  	return ret, nil
   432  }
   433  
   434  // Pages invokes f for each page of results.
   435  // A non-nil error returned from f will halt the iteration.
   436  // The provided context supersedes any context provided to the Context method.
   437  func (c *ProjectsLocationsActivityTypesActivitiesQueryCall) Pages(ctx context.Context, f func(*GoogleCloudPolicyanalyzerV1QueryActivityResponse) error) error {
   438  	c.ctx_ = ctx
   439  	defer c.PageToken(c.urlParams_.Get("pageToken"))
   440  	for {
   441  		x, err := c.Do()
   442  		if err != nil {
   443  			return err
   444  		}
   445  		if err := f(x); err != nil {
   446  			return err
   447  		}
   448  		if x.NextPageToken == "" {
   449  			return nil
   450  		}
   451  		c.PageToken(x.NextPageToken)
   452  	}
   453  }
   454  

View as plain text