...

Source file src/google.golang.org/api/cloudprofiler/v2/cloudprofiler-gen.go

Documentation: google.golang.org/api/cloudprofiler/v2

     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 cloudprofiler provides access to the Cloud Profiler API.
     8  //
     9  // For product documentation, see: https://cloud.google.com/profiler/
    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/cloudprofiler/v2"
    27  //	...
    28  //	ctx := context.Background()
    29  //	cloudprofilerService, err := cloudprofiler.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  // By default, all available scopes (see "Constants") are used to authenticate.
    38  // To restrict scopes, use [google.golang.org/api/option.WithScopes]:
    39  //
    40  //	cloudprofilerService, err := cloudprofiler.NewService(ctx, option.WithScopes(cloudprofiler.MonitoringWriteScope))
    41  //
    42  // To use an API key for authentication (note: some APIs do not support API
    43  // keys), use [google.golang.org/api/option.WithAPIKey]:
    44  //
    45  //	cloudprofilerService, err := cloudprofiler.NewService(ctx, option.WithAPIKey("AIza..."))
    46  //
    47  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    48  // flow, use [google.golang.org/api/option.WithTokenSource]:
    49  //
    50  //	config := &oauth2.Config{...}
    51  //	// ...
    52  //	token, err := config.Exchange(ctx, ...)
    53  //	cloudprofilerService, err := cloudprofiler.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    54  //
    55  // See [google.golang.org/api/option.ClientOption] for details on options.
    56  package cloudprofiler // import "google.golang.org/api/cloudprofiler/v2"
    57  
    58  import (
    59  	"bytes"
    60  	"context"
    61  	"encoding/json"
    62  	"errors"
    63  	"fmt"
    64  	"io"
    65  	"net/http"
    66  	"net/url"
    67  	"strconv"
    68  	"strings"
    69  
    70  	googleapi "google.golang.org/api/googleapi"
    71  	internal "google.golang.org/api/internal"
    72  	gensupport "google.golang.org/api/internal/gensupport"
    73  	option "google.golang.org/api/option"
    74  	internaloption "google.golang.org/api/option/internaloption"
    75  	htransport "google.golang.org/api/transport/http"
    76  )
    77  
    78  // Always reference these packages, just in case the auto-generated code
    79  // below doesn't.
    80  var _ = bytes.NewBuffer
    81  var _ = strconv.Itoa
    82  var _ = fmt.Sprintf
    83  var _ = json.NewDecoder
    84  var _ = io.Copy
    85  var _ = url.Parse
    86  var _ = gensupport.MarshalJSON
    87  var _ = googleapi.Version
    88  var _ = errors.New
    89  var _ = strings.Replace
    90  var _ = context.Canceled
    91  var _ = internaloption.WithDefaultEndpoint
    92  var _ = internal.Version
    93  
    94  const apiId = "cloudprofiler:v2"
    95  const apiName = "cloudprofiler"
    96  const apiVersion = "v2"
    97  const basePath = "https://cloudprofiler.googleapis.com/"
    98  const basePathTemplate = "https://cloudprofiler.UNIVERSE_DOMAIN/"
    99  const mtlsBasePath = "https://cloudprofiler.mtls.googleapis.com/"
   100  
   101  // OAuth2 scopes used by this API.
   102  const (
   103  	// See, edit, configure, and delete your Google Cloud data and see the email
   104  	// address for your Google Account.
   105  	CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
   106  
   107  	// View and write monitoring data for all of your Google and third-party Cloud
   108  	// and API projects
   109  	MonitoringScope = "https://www.googleapis.com/auth/monitoring"
   110  
   111  	// Publish metric data to your Google Cloud projects
   112  	MonitoringWriteScope = "https://www.googleapis.com/auth/monitoring.write"
   113  )
   114  
   115  // NewService creates a new Service.
   116  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   117  	scopesOption := internaloption.WithDefaultScopes(
   118  		"https://www.googleapis.com/auth/cloud-platform",
   119  		"https://www.googleapis.com/auth/monitoring",
   120  		"https://www.googleapis.com/auth/monitoring.write",
   121  	)
   122  	// NOTE: prepend, so we don't override user-specified scopes.
   123  	opts = append([]option.ClientOption{scopesOption}, opts...)
   124  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   125  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   126  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   127  	opts = append(opts, internaloption.EnableNewAuthLibrary())
   128  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   129  	if err != nil {
   130  		return nil, err
   131  	}
   132  	s, err := New(client)
   133  	if err != nil {
   134  		return nil, err
   135  	}
   136  	if endpoint != "" {
   137  		s.BasePath = endpoint
   138  	}
   139  	return s, nil
   140  }
   141  
   142  // New creates a new Service. It uses the provided http.Client for requests.
   143  //
   144  // Deprecated: please use NewService instead.
   145  // To provide a custom HTTP client, use option.WithHTTPClient.
   146  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   147  func New(client *http.Client) (*Service, error) {
   148  	if client == nil {
   149  		return nil, errors.New("client is nil")
   150  	}
   151  	s := &Service{client: client, BasePath: basePath}
   152  	s.Projects = NewProjectsService(s)
   153  	return s, nil
   154  }
   155  
   156  type Service struct {
   157  	client    *http.Client
   158  	BasePath  string // API endpoint base URL
   159  	UserAgent string // optional additional User-Agent fragment
   160  
   161  	Projects *ProjectsService
   162  }
   163  
   164  func (s *Service) userAgent() string {
   165  	if s.UserAgent == "" {
   166  		return googleapi.UserAgent
   167  	}
   168  	return googleapi.UserAgent + " " + s.UserAgent
   169  }
   170  
   171  func NewProjectsService(s *Service) *ProjectsService {
   172  	rs := &ProjectsService{s: s}
   173  	rs.Profiles = NewProjectsProfilesService(s)
   174  	return rs
   175  }
   176  
   177  type ProjectsService struct {
   178  	s *Service
   179  
   180  	Profiles *ProjectsProfilesService
   181  }
   182  
   183  func NewProjectsProfilesService(s *Service) *ProjectsProfilesService {
   184  	rs := &ProjectsProfilesService{s: s}
   185  	return rs
   186  }
   187  
   188  type ProjectsProfilesService struct {
   189  	s *Service
   190  }
   191  
   192  // CreateProfileRequest: CreateProfileRequest describes a profile resource
   193  // online creation request. The deployment field must be populated. The
   194  // profile_type specifies the list of profile types supported by the agent. The
   195  // creation call will hang until a profile of one of these types needs to be
   196  // collected.
   197  type CreateProfileRequest struct {
   198  	// Deployment: Deployment details.
   199  	Deployment *Deployment `json:"deployment,omitempty"`
   200  	// ProfileType: One or more profile types that the agent is capable of
   201  	// providing.
   202  	//
   203  	// Possible values:
   204  	//   "PROFILE_TYPE_UNSPECIFIED" - Unspecified profile type.
   205  	//   "CPU" - Thread CPU time sampling.
   206  	//   "WALL" - Wallclock time sampling. More expensive as stops all threads.
   207  	//   "HEAP" - In-use heap profile. Represents a snapshot of the allocations
   208  	// that are live at the time of the profiling.
   209  	//   "THREADS" - Single-shot collection of all thread stacks.
   210  	//   "CONTENTION" - Synchronization contention profile.
   211  	//   "PEAK_HEAP" - Peak heap profile.
   212  	//   "HEAP_ALLOC" - Heap allocation profile. It represents the aggregation of
   213  	// all allocations made over the duration of the profile. All allocations are
   214  	// included, including those that might have been freed by the end of the
   215  	// profiling interval. The profile is in particular useful for garbage
   216  	// collecting languages to understand which parts of the code create most of
   217  	// the garbage collection pressure to see if those can be optimized.
   218  	ProfileType []string `json:"profileType,omitempty"`
   219  	// ForceSendFields is a list of field names (e.g. "Deployment") to
   220  	// unconditionally include in API requests. By default, fields with empty or
   221  	// default values are omitted from API requests. See
   222  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   223  	// details.
   224  	ForceSendFields []string `json:"-"`
   225  	// NullFields is a list of field names (e.g. "Deployment") to include in API
   226  	// requests with the JSON null value. By default, fields with empty values are
   227  	// omitted from API requests. See
   228  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   229  	NullFields []string `json:"-"`
   230  }
   231  
   232  func (s *CreateProfileRequest) MarshalJSON() ([]byte, error) {
   233  	type NoMethod CreateProfileRequest
   234  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   235  }
   236  
   237  // Deployment: Deployment contains the deployment identification information.
   238  type Deployment struct {
   239  	// Labels: Labels identify the deployment within the user universe and same
   240  	// target. Validation regex for label names: `^a-z0-9
   241  	// ([a-z0-9-]{0,61}[a-z0-9])?$`. Value for an individual label must be <= 512
   242  	// bytes, the total size of all label names and values must be <= 1024 bytes.
   243  	// Label named "language" can be used to record the programming language of the
   244  	// profiled deployment. The standard choices for the value include "java",
   245  	// "go", "python", "ruby", "nodejs", "php", "dotnet". For deployments running
   246  	// on Google Cloud Platform, "zone" or "region" label should be present
   247  	// describing the deployment location. An example of a zone is "us-central1-a",
   248  	// an example of a region is "us-central1" or "us-central".
   249  	Labels map[string]string `json:"labels,omitempty"`
   250  	// ProjectId: Project ID is the ID of a cloud project. Validation regex:
   251  	// `^a-z{4,61}[a-z0-9]$`.
   252  	ProjectId string `json:"projectId,omitempty"`
   253  	// Target: Target is the service name used to group related deployments: *
   254  	// Service name for App Engine Flex / Standard. * Cluster and container name
   255  	// for GKE. * User-specified string for direct Compute Engine profiling (e.g.
   256  	// Java). * Job name for Dataflow. Validation regex: `^a-z0-9
   257  	// ([-a-z0-9_.]{0,253}[a-z0-9])?$`.
   258  	Target string `json:"target,omitempty"`
   259  	// ForceSendFields is a list of field names (e.g. "Labels") to unconditionally
   260  	// include in API requests. By default, fields with empty or default values are
   261  	// omitted from API requests. See
   262  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   263  	// details.
   264  	ForceSendFields []string `json:"-"`
   265  	// NullFields is a list of field names (e.g. "Labels") to include in API
   266  	// requests with the JSON null value. By default, fields with empty values are
   267  	// omitted from API requests. See
   268  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   269  	NullFields []string `json:"-"`
   270  }
   271  
   272  func (s *Deployment) MarshalJSON() ([]byte, error) {
   273  	type NoMethod Deployment
   274  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   275  }
   276  
   277  // ListProfilesResponse: ListProfileResponse contains the list of collected
   278  // profiles for deployments in projects which the user has permissions to view.
   279  type ListProfilesResponse struct {
   280  	// NextPageToken: Token to receive the next page of results. This field maybe
   281  	// empty if there are no more profiles to fetch.
   282  	NextPageToken string `json:"nextPageToken,omitempty"`
   283  	// Profiles: List of profiles fetched.
   284  	Profiles []*Profile `json:"profiles,omitempty"`
   285  	// SkippedProfiles: Number of profiles that were skipped in the current page
   286  	// since they were not able to be fetched successfully. This should typically
   287  	// be zero. A non-zero value may indicate a transient failure, in which case if
   288  	// the number is too high for your use case, the call may be retried.
   289  	SkippedProfiles int64 `json:"skippedProfiles,omitempty"`
   290  
   291  	// ServerResponse contains the HTTP response code and headers from the server.
   292  	googleapi.ServerResponse `json:"-"`
   293  	// ForceSendFields is a list of field names (e.g. "NextPageToken") to
   294  	// unconditionally include in API requests. By default, fields with empty or
   295  	// default values are omitted from API requests. See
   296  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   297  	// details.
   298  	ForceSendFields []string `json:"-"`
   299  	// NullFields is a list of field names (e.g. "NextPageToken") to include in API
   300  	// requests with the JSON null value. By default, fields with empty values are
   301  	// omitted from API requests. See
   302  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   303  	NullFields []string `json:"-"`
   304  }
   305  
   306  func (s *ListProfilesResponse) MarshalJSON() ([]byte, error) {
   307  	type NoMethod ListProfilesResponse
   308  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   309  }
   310  
   311  // Profile: Profile resource.
   312  type Profile struct {
   313  	// Deployment: Deployment this profile corresponds to.
   314  	Deployment *Deployment `json:"deployment,omitempty"`
   315  	// Duration: Duration of the profiling session. Input (for the offline mode) or
   316  	// output (for the online mode). The field represents requested profiling
   317  	// duration. It may slightly differ from the effective profiling duration,
   318  	// which is recorded in the profile data, in case the profiling can't be
   319  	// stopped immediately (e.g. in case stopping the profiling is handled
   320  	// asynchronously).
   321  	Duration string `json:"duration,omitempty"`
   322  	// Labels: Input only. Labels associated to this specific profile. These labels
   323  	// will get merged with the deployment labels for the final data set. See
   324  	// documentation on deployment labels for validation rules and limits.
   325  	Labels map[string]string `json:"labels,omitempty"`
   326  	// Name: Output only. Opaque, server-assigned, unique ID for this profile.
   327  	Name string `json:"name,omitempty"`
   328  	// ProfileBytes: Input only. Profile bytes, as a gzip compressed serialized
   329  	// proto, the format is
   330  	// https://github.com/google/pprof/blob/master/proto/profile.proto.
   331  	ProfileBytes string `json:"profileBytes,omitempty"`
   332  	// ProfileType: Type of profile. For offline mode, this must be specified when
   333  	// creating the profile. For online mode it is assigned and returned by the
   334  	// server.
   335  	//
   336  	// Possible values:
   337  	//   "PROFILE_TYPE_UNSPECIFIED" - Unspecified profile type.
   338  	//   "CPU" - Thread CPU time sampling.
   339  	//   "WALL" - Wallclock time sampling. More expensive as stops all threads.
   340  	//   "HEAP" - In-use heap profile. Represents a snapshot of the allocations
   341  	// that are live at the time of the profiling.
   342  	//   "THREADS" - Single-shot collection of all thread stacks.
   343  	//   "CONTENTION" - Synchronization contention profile.
   344  	//   "PEAK_HEAP" - Peak heap profile.
   345  	//   "HEAP_ALLOC" - Heap allocation profile. It represents the aggregation of
   346  	// all allocations made over the duration of the profile. All allocations are
   347  	// included, including those that might have been freed by the end of the
   348  	// profiling interval. The profile is in particular useful for garbage
   349  	// collecting languages to understand which parts of the code create most of
   350  	// the garbage collection pressure to see if those can be optimized.
   351  	ProfileType string `json:"profileType,omitempty"`
   352  	// StartTime: Output only. Start time for the profile. This output is only
   353  	// present in response from the ListProfiles method.
   354  	StartTime string `json:"startTime,omitempty"`
   355  
   356  	// ServerResponse contains the HTTP response code and headers from the server.
   357  	googleapi.ServerResponse `json:"-"`
   358  	// ForceSendFields is a list of field names (e.g. "Deployment") to
   359  	// unconditionally include in API requests. By default, fields with empty or
   360  	// default values are omitted from API requests. See
   361  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   362  	// details.
   363  	ForceSendFields []string `json:"-"`
   364  	// NullFields is a list of field names (e.g. "Deployment") to include in API
   365  	// requests with the JSON null value. By default, fields with empty values are
   366  	// omitted from API requests. See
   367  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   368  	NullFields []string `json:"-"`
   369  }
   370  
   371  func (s *Profile) MarshalJSON() ([]byte, error) {
   372  	type NoMethod Profile
   373  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   374  }
   375  
   376  type ProjectsProfilesCreateCall struct {
   377  	s                    *Service
   378  	parent               string
   379  	createprofilerequest *CreateProfileRequest
   380  	urlParams_           gensupport.URLParams
   381  	ctx_                 context.Context
   382  	header_              http.Header
   383  }
   384  
   385  // Create: CreateProfile creates a new profile resource in the online mode.
   386  // _Direct use of this API is discouraged, please use a supported profiler
   387  // agent
   388  // (https://cloud.google.com/profiler/docs/about-profiler#profiling_agent)
   389  // instead for profile collection._ The server ensures that the new profiles
   390  // are created at a constant rate per deployment, so the creation request may
   391  // hang for some time until the next profile session is available. The request
   392  // may fail with ABORTED error if the creation is not available within ~1m, the
   393  // response will indicate the duration of the backoff the client should take
   394  // before attempting creating a profile again. The backoff duration is returned
   395  // in google.rpc.RetryInfo extension on the response status. To a gRPC client,
   396  // the extension will be return as a binary-serialized proto in the trailing
   397  // metadata item named "google.rpc.retryinfo-bin".
   398  //
   399  // - parent: Parent project to create the profile in.
   400  func (r *ProjectsProfilesService) Create(parent string, createprofilerequest *CreateProfileRequest) *ProjectsProfilesCreateCall {
   401  	c := &ProjectsProfilesCreateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   402  	c.parent = parent
   403  	c.createprofilerequest = createprofilerequest
   404  	return c
   405  }
   406  
   407  // Fields allows partial responses to be retrieved. See
   408  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   409  // details.
   410  func (c *ProjectsProfilesCreateCall) Fields(s ...googleapi.Field) *ProjectsProfilesCreateCall {
   411  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   412  	return c
   413  }
   414  
   415  // Context sets the context to be used in this call's Do method.
   416  func (c *ProjectsProfilesCreateCall) Context(ctx context.Context) *ProjectsProfilesCreateCall {
   417  	c.ctx_ = ctx
   418  	return c
   419  }
   420  
   421  // Header returns a http.Header that can be modified by the caller to add
   422  // headers to the request.
   423  func (c *ProjectsProfilesCreateCall) Header() http.Header {
   424  	if c.header_ == nil {
   425  		c.header_ = make(http.Header)
   426  	}
   427  	return c.header_
   428  }
   429  
   430  func (c *ProjectsProfilesCreateCall) doRequest(alt string) (*http.Response, error) {
   431  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   432  	var body io.Reader = nil
   433  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.createprofilerequest)
   434  	if err != nil {
   435  		return nil, err
   436  	}
   437  	c.urlParams_.Set("alt", alt)
   438  	c.urlParams_.Set("prettyPrint", "false")
   439  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/{+parent}/profiles")
   440  	urls += "?" + c.urlParams_.Encode()
   441  	req, err := http.NewRequest("POST", urls, body)
   442  	if err != nil {
   443  		return nil, err
   444  	}
   445  	req.Header = reqHeaders
   446  	googleapi.Expand(req.URL, map[string]string{
   447  		"parent": c.parent,
   448  	})
   449  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   450  }
   451  
   452  // Do executes the "cloudprofiler.projects.profiles.create" call.
   453  // Any non-2xx status code is an error. Response headers are in either
   454  // *Profile.ServerResponse.Header or (if a response was returned at all) in
   455  // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
   456  // whether the returned error was because http.StatusNotModified was returned.
   457  func (c *ProjectsProfilesCreateCall) Do(opts ...googleapi.CallOption) (*Profile, error) {
   458  	gensupport.SetOptions(c.urlParams_, opts...)
   459  	res, err := c.doRequest("json")
   460  	if res != nil && res.StatusCode == http.StatusNotModified {
   461  		if res.Body != nil {
   462  			res.Body.Close()
   463  		}
   464  		return nil, gensupport.WrapError(&googleapi.Error{
   465  			Code:   res.StatusCode,
   466  			Header: res.Header,
   467  		})
   468  	}
   469  	if err != nil {
   470  		return nil, err
   471  	}
   472  	defer googleapi.CloseBody(res)
   473  	if err := googleapi.CheckResponse(res); err != nil {
   474  		return nil, gensupport.WrapError(err)
   475  	}
   476  	ret := &Profile{
   477  		ServerResponse: googleapi.ServerResponse{
   478  			Header:         res.Header,
   479  			HTTPStatusCode: res.StatusCode,
   480  		},
   481  	}
   482  	target := &ret
   483  	if err := gensupport.DecodeResponse(target, res); err != nil {
   484  		return nil, err
   485  	}
   486  	return ret, nil
   487  }
   488  
   489  type ProjectsProfilesCreateOfflineCall struct {
   490  	s          *Service
   491  	parent     string
   492  	profile    *Profile
   493  	urlParams_ gensupport.URLParams
   494  	ctx_       context.Context
   495  	header_    http.Header
   496  }
   497  
   498  // CreateOffline: CreateOfflineProfile creates a new profile resource in the
   499  // offline mode. The client provides the profile to create along with the
   500  // profile bytes, the server records it. _Direct use of this API is
   501  // discouraged, please use a supported profiler agent
   502  // (https://cloud.google.com/profiler/docs/about-profiler#profiling_agent)
   503  // instead for profile collection._
   504  //
   505  // - parent: Parent project to create the profile in.
   506  func (r *ProjectsProfilesService) CreateOffline(parent string, profile *Profile) *ProjectsProfilesCreateOfflineCall {
   507  	c := &ProjectsProfilesCreateOfflineCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   508  	c.parent = parent
   509  	c.profile = profile
   510  	return c
   511  }
   512  
   513  // Fields allows partial responses to be retrieved. See
   514  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   515  // details.
   516  func (c *ProjectsProfilesCreateOfflineCall) Fields(s ...googleapi.Field) *ProjectsProfilesCreateOfflineCall {
   517  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   518  	return c
   519  }
   520  
   521  // Context sets the context to be used in this call's Do method.
   522  func (c *ProjectsProfilesCreateOfflineCall) Context(ctx context.Context) *ProjectsProfilesCreateOfflineCall {
   523  	c.ctx_ = ctx
   524  	return c
   525  }
   526  
   527  // Header returns a http.Header that can be modified by the caller to add
   528  // headers to the request.
   529  func (c *ProjectsProfilesCreateOfflineCall) Header() http.Header {
   530  	if c.header_ == nil {
   531  		c.header_ = make(http.Header)
   532  	}
   533  	return c.header_
   534  }
   535  
   536  func (c *ProjectsProfilesCreateOfflineCall) doRequest(alt string) (*http.Response, error) {
   537  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   538  	var body io.Reader = nil
   539  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.profile)
   540  	if err != nil {
   541  		return nil, err
   542  	}
   543  	c.urlParams_.Set("alt", alt)
   544  	c.urlParams_.Set("prettyPrint", "false")
   545  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/{+parent}/profiles:createOffline")
   546  	urls += "?" + c.urlParams_.Encode()
   547  	req, err := http.NewRequest("POST", urls, body)
   548  	if err != nil {
   549  		return nil, err
   550  	}
   551  	req.Header = reqHeaders
   552  	googleapi.Expand(req.URL, map[string]string{
   553  		"parent": c.parent,
   554  	})
   555  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   556  }
   557  
   558  // Do executes the "cloudprofiler.projects.profiles.createOffline" call.
   559  // Any non-2xx status code is an error. Response headers are in either
   560  // *Profile.ServerResponse.Header or (if a response was returned at all) in
   561  // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
   562  // whether the returned error was because http.StatusNotModified was returned.
   563  func (c *ProjectsProfilesCreateOfflineCall) Do(opts ...googleapi.CallOption) (*Profile, error) {
   564  	gensupport.SetOptions(c.urlParams_, opts...)
   565  	res, err := c.doRequest("json")
   566  	if res != nil && res.StatusCode == http.StatusNotModified {
   567  		if res.Body != nil {
   568  			res.Body.Close()
   569  		}
   570  		return nil, gensupport.WrapError(&googleapi.Error{
   571  			Code:   res.StatusCode,
   572  			Header: res.Header,
   573  		})
   574  	}
   575  	if err != nil {
   576  		return nil, err
   577  	}
   578  	defer googleapi.CloseBody(res)
   579  	if err := googleapi.CheckResponse(res); err != nil {
   580  		return nil, gensupport.WrapError(err)
   581  	}
   582  	ret := &Profile{
   583  		ServerResponse: googleapi.ServerResponse{
   584  			Header:         res.Header,
   585  			HTTPStatusCode: res.StatusCode,
   586  		},
   587  	}
   588  	target := &ret
   589  	if err := gensupport.DecodeResponse(target, res); err != nil {
   590  		return nil, err
   591  	}
   592  	return ret, nil
   593  }
   594  
   595  type ProjectsProfilesListCall struct {
   596  	s            *Service
   597  	parent       string
   598  	urlParams_   gensupport.URLParams
   599  	ifNoneMatch_ string
   600  	ctx_         context.Context
   601  	header_      http.Header
   602  }
   603  
   604  // List: Lists profiles which have been collected so far and for which the
   605  // caller has permission to view.
   606  //
   607  //   - parent: The parent, which owns this collection of profiles. Format:
   608  //     projects/{user_project_id}.
   609  func (r *ProjectsProfilesService) List(parent string) *ProjectsProfilesListCall {
   610  	c := &ProjectsProfilesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   611  	c.parent = parent
   612  	return c
   613  }
   614  
   615  // PageSize sets the optional parameter "pageSize": The maximum number of items
   616  // to return. Default page_size is 1000. Max limit is 1000.
   617  func (c *ProjectsProfilesListCall) PageSize(pageSize int64) *ProjectsProfilesListCall {
   618  	c.urlParams_.Set("pageSize", fmt.Sprint(pageSize))
   619  	return c
   620  }
   621  
   622  // PageToken sets the optional parameter "pageToken": The token to continue
   623  // pagination and get profiles from a particular page. When paginating, all
   624  // other parameters provided to `ListProfiles` must match the call that
   625  // provided the page token.
   626  func (c *ProjectsProfilesListCall) PageToken(pageToken string) *ProjectsProfilesListCall {
   627  	c.urlParams_.Set("pageToken", pageToken)
   628  	return c
   629  }
   630  
   631  // Fields allows partial responses to be retrieved. See
   632  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   633  // details.
   634  func (c *ProjectsProfilesListCall) Fields(s ...googleapi.Field) *ProjectsProfilesListCall {
   635  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   636  	return c
   637  }
   638  
   639  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   640  // object's ETag matches the given value. This is useful for getting updates
   641  // only after the object has changed since the last request.
   642  func (c *ProjectsProfilesListCall) IfNoneMatch(entityTag string) *ProjectsProfilesListCall {
   643  	c.ifNoneMatch_ = entityTag
   644  	return c
   645  }
   646  
   647  // Context sets the context to be used in this call's Do method.
   648  func (c *ProjectsProfilesListCall) Context(ctx context.Context) *ProjectsProfilesListCall {
   649  	c.ctx_ = ctx
   650  	return c
   651  }
   652  
   653  // Header returns a http.Header that can be modified by the caller to add
   654  // headers to the request.
   655  func (c *ProjectsProfilesListCall) Header() http.Header {
   656  	if c.header_ == nil {
   657  		c.header_ = make(http.Header)
   658  	}
   659  	return c.header_
   660  }
   661  
   662  func (c *ProjectsProfilesListCall) doRequest(alt string) (*http.Response, error) {
   663  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   664  	if c.ifNoneMatch_ != "" {
   665  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   666  	}
   667  	var body io.Reader = nil
   668  	c.urlParams_.Set("alt", alt)
   669  	c.urlParams_.Set("prettyPrint", "false")
   670  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/{+parent}/profiles")
   671  	urls += "?" + c.urlParams_.Encode()
   672  	req, err := http.NewRequest("GET", urls, body)
   673  	if err != nil {
   674  		return nil, err
   675  	}
   676  	req.Header = reqHeaders
   677  	googleapi.Expand(req.URL, map[string]string{
   678  		"parent": c.parent,
   679  	})
   680  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   681  }
   682  
   683  // Do executes the "cloudprofiler.projects.profiles.list" call.
   684  // Any non-2xx status code is an error. Response headers are in either
   685  // *ListProfilesResponse.ServerResponse.Header or (if a response was returned
   686  // at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   687  // check whether the returned error was because http.StatusNotModified was
   688  // returned.
   689  func (c *ProjectsProfilesListCall) Do(opts ...googleapi.CallOption) (*ListProfilesResponse, error) {
   690  	gensupport.SetOptions(c.urlParams_, opts...)
   691  	res, err := c.doRequest("json")
   692  	if res != nil && res.StatusCode == http.StatusNotModified {
   693  		if res.Body != nil {
   694  			res.Body.Close()
   695  		}
   696  		return nil, gensupport.WrapError(&googleapi.Error{
   697  			Code:   res.StatusCode,
   698  			Header: res.Header,
   699  		})
   700  	}
   701  	if err != nil {
   702  		return nil, err
   703  	}
   704  	defer googleapi.CloseBody(res)
   705  	if err := googleapi.CheckResponse(res); err != nil {
   706  		return nil, gensupport.WrapError(err)
   707  	}
   708  	ret := &ListProfilesResponse{
   709  		ServerResponse: googleapi.ServerResponse{
   710  			Header:         res.Header,
   711  			HTTPStatusCode: res.StatusCode,
   712  		},
   713  	}
   714  	target := &ret
   715  	if err := gensupport.DecodeResponse(target, res); err != nil {
   716  		return nil, err
   717  	}
   718  	return ret, nil
   719  }
   720  
   721  // Pages invokes f for each page of results.
   722  // A non-nil error returned from f will halt the iteration.
   723  // The provided context supersedes any context provided to the Context method.
   724  func (c *ProjectsProfilesListCall) Pages(ctx context.Context, f func(*ListProfilesResponse) error) error {
   725  	c.ctx_ = ctx
   726  	defer c.PageToken(c.urlParams_.Get("pageToken"))
   727  	for {
   728  		x, err := c.Do()
   729  		if err != nil {
   730  			return err
   731  		}
   732  		if err := f(x); err != nil {
   733  			return err
   734  		}
   735  		if x.NextPageToken == "" {
   736  			return nil
   737  		}
   738  		c.PageToken(x.NextPageToken)
   739  	}
   740  }
   741  
   742  type ProjectsProfilesPatchCall struct {
   743  	s          *Service
   744  	name       string
   745  	profile    *Profile
   746  	urlParams_ gensupport.URLParams
   747  	ctx_       context.Context
   748  	header_    http.Header
   749  }
   750  
   751  // Patch: UpdateProfile updates the profile bytes and labels on the profile
   752  // resource created in the online mode. Updating the bytes for profiles created
   753  // in the offline mode is currently not supported: the profile content must be
   754  // provided at the time of the profile creation. _Direct use of this API is
   755  // discouraged, please use a supported profiler agent
   756  // (https://cloud.google.com/profiler/docs/about-profiler#profiling_agent)
   757  // instead for profile collection._
   758  //
   759  // - name: Output only. Opaque, server-assigned, unique ID for this profile.
   760  func (r *ProjectsProfilesService) Patch(name string, profile *Profile) *ProjectsProfilesPatchCall {
   761  	c := &ProjectsProfilesPatchCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   762  	c.name = name
   763  	c.profile = profile
   764  	return c
   765  }
   766  
   767  // UpdateMask sets the optional parameter "updateMask": Field mask used to
   768  // specify the fields to be overwritten. Currently only profile_bytes and
   769  // labels fields are supported by UpdateProfile, so only those fields can be
   770  // specified in the mask. When no mask is provided, all fields are overwritten.
   771  func (c *ProjectsProfilesPatchCall) UpdateMask(updateMask string) *ProjectsProfilesPatchCall {
   772  	c.urlParams_.Set("updateMask", updateMask)
   773  	return c
   774  }
   775  
   776  // Fields allows partial responses to be retrieved. See
   777  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   778  // details.
   779  func (c *ProjectsProfilesPatchCall) Fields(s ...googleapi.Field) *ProjectsProfilesPatchCall {
   780  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   781  	return c
   782  }
   783  
   784  // Context sets the context to be used in this call's Do method.
   785  func (c *ProjectsProfilesPatchCall) Context(ctx context.Context) *ProjectsProfilesPatchCall {
   786  	c.ctx_ = ctx
   787  	return c
   788  }
   789  
   790  // Header returns a http.Header that can be modified by the caller to add
   791  // headers to the request.
   792  func (c *ProjectsProfilesPatchCall) Header() http.Header {
   793  	if c.header_ == nil {
   794  		c.header_ = make(http.Header)
   795  	}
   796  	return c.header_
   797  }
   798  
   799  func (c *ProjectsProfilesPatchCall) doRequest(alt string) (*http.Response, error) {
   800  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   801  	var body io.Reader = nil
   802  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.profile)
   803  	if err != nil {
   804  		return nil, err
   805  	}
   806  	c.urlParams_.Set("alt", alt)
   807  	c.urlParams_.Set("prettyPrint", "false")
   808  	urls := googleapi.ResolveRelative(c.s.BasePath, "v2/{+name}")
   809  	urls += "?" + c.urlParams_.Encode()
   810  	req, err := http.NewRequest("PATCH", urls, body)
   811  	if err != nil {
   812  		return nil, err
   813  	}
   814  	req.Header = reqHeaders
   815  	googleapi.Expand(req.URL, map[string]string{
   816  		"name": c.name,
   817  	})
   818  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   819  }
   820  
   821  // Do executes the "cloudprofiler.projects.profiles.patch" call.
   822  // Any non-2xx status code is an error. Response headers are in either
   823  // *Profile.ServerResponse.Header or (if a response was returned at all) in
   824  // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
   825  // whether the returned error was because http.StatusNotModified was returned.
   826  func (c *ProjectsProfilesPatchCall) Do(opts ...googleapi.CallOption) (*Profile, error) {
   827  	gensupport.SetOptions(c.urlParams_, opts...)
   828  	res, err := c.doRequest("json")
   829  	if res != nil && res.StatusCode == http.StatusNotModified {
   830  		if res.Body != nil {
   831  			res.Body.Close()
   832  		}
   833  		return nil, gensupport.WrapError(&googleapi.Error{
   834  			Code:   res.StatusCode,
   835  			Header: res.Header,
   836  		})
   837  	}
   838  	if err != nil {
   839  		return nil, err
   840  	}
   841  	defer googleapi.CloseBody(res)
   842  	if err := googleapi.CheckResponse(res); err != nil {
   843  		return nil, gensupport.WrapError(err)
   844  	}
   845  	ret := &Profile{
   846  		ServerResponse: googleapi.ServerResponse{
   847  			Header:         res.Header,
   848  			HTTPStatusCode: res.StatusCode,
   849  		},
   850  	}
   851  	target := &ret
   852  	if err := gensupport.DecodeResponse(target, res); err != nil {
   853  		return nil, err
   854  	}
   855  	return ret, nil
   856  }
   857  

View as plain text