...

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

Documentation: google.golang.org/api/publicca/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 publicca provides access to the Public Certificate Authority API.
     8  //
     9  // For product documentation, see: https://cloud.google.com/public-certificate-authority/docs
    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/publicca/v1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	publiccaService, err := publicca.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  //	publiccaService, err := publicca.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  //	publiccaService, err := publicca.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package publicca // import "google.golang.org/api/publicca/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 = "publicca:v1"
    90  const apiName = "publicca"
    91  const apiVersion = "v1"
    92  const basePath = "https://publicca.googleapis.com/"
    93  const basePathTemplate = "https://publicca.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://publicca.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.ExternalAccountKeys = NewProjectsLocationsExternalAccountKeysService(s)
   172  	return rs
   173  }
   174  
   175  type ProjectsLocationsService struct {
   176  	s *Service
   177  
   178  	ExternalAccountKeys *ProjectsLocationsExternalAccountKeysService
   179  }
   180  
   181  func NewProjectsLocationsExternalAccountKeysService(s *Service) *ProjectsLocationsExternalAccountKeysService {
   182  	rs := &ProjectsLocationsExternalAccountKeysService{s: s}
   183  	return rs
   184  }
   185  
   186  type ProjectsLocationsExternalAccountKeysService struct {
   187  	s *Service
   188  }
   189  
   190  // ExternalAccountKey: A representation of an ExternalAccountKey used for
   191  // external account binding (https://tools.ietf.org/html/rfc8555#section-7.3.4)
   192  // within ACME.
   193  type ExternalAccountKey struct {
   194  	// B64MacKey: Output only. Base64-URL-encoded HS256 key. It is generated by the
   195  	// PublicCertificateAuthorityService when the ExternalAccountKey is created
   196  	B64MacKey string `json:"b64MacKey,omitempty"`
   197  	// KeyId: Output only. Key ID. It is generated by the
   198  	// PublicCertificateAuthorityService when the ExternalAccountKey is created
   199  	KeyId string `json:"keyId,omitempty"`
   200  	// Name: Output only. Resource name.
   201  	// projects/{project}/locations/{location}/externalAccountKeys/{key_id}
   202  	Name string `json:"name,omitempty"`
   203  
   204  	// ServerResponse contains the HTTP response code and headers from the server.
   205  	googleapi.ServerResponse `json:"-"`
   206  	// ForceSendFields is a list of field names (e.g. "B64MacKey") to
   207  	// unconditionally include in API requests. By default, fields with empty or
   208  	// default values are omitted from API requests. See
   209  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   210  	// details.
   211  	ForceSendFields []string `json:"-"`
   212  	// NullFields is a list of field names (e.g. "B64MacKey") to include in API
   213  	// requests with the JSON null value. By default, fields with empty values are
   214  	// omitted from API requests. See
   215  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   216  	NullFields []string `json:"-"`
   217  }
   218  
   219  func (s *ExternalAccountKey) MarshalJSON() ([]byte, error) {
   220  	type NoMethod ExternalAccountKey
   221  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   222  }
   223  
   224  type ProjectsLocationsExternalAccountKeysCreateCall struct {
   225  	s                  *Service
   226  	parent             string
   227  	externalaccountkey *ExternalAccountKey
   228  	urlParams_         gensupport.URLParams
   229  	ctx_               context.Context
   230  	header_            http.Header
   231  }
   232  
   233  // Create: Creates a new ExternalAccountKey bound to the project.
   234  //
   235  //   - parent: The parent resource where this external_account_key will be
   236  //     created. Format: projects/[project_id]/locations/[location]. At present
   237  //     only the "global" location is supported.
   238  func (r *ProjectsLocationsExternalAccountKeysService) Create(parent string, externalaccountkey *ExternalAccountKey) *ProjectsLocationsExternalAccountKeysCreateCall {
   239  	c := &ProjectsLocationsExternalAccountKeysCreateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   240  	c.parent = parent
   241  	c.externalaccountkey = externalaccountkey
   242  	return c
   243  }
   244  
   245  // Fields allows partial responses to be retrieved. See
   246  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   247  // details.
   248  func (c *ProjectsLocationsExternalAccountKeysCreateCall) Fields(s ...googleapi.Field) *ProjectsLocationsExternalAccountKeysCreateCall {
   249  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   250  	return c
   251  }
   252  
   253  // Context sets the context to be used in this call's Do method.
   254  func (c *ProjectsLocationsExternalAccountKeysCreateCall) Context(ctx context.Context) *ProjectsLocationsExternalAccountKeysCreateCall {
   255  	c.ctx_ = ctx
   256  	return c
   257  }
   258  
   259  // Header returns a http.Header that can be modified by the caller to add
   260  // headers to the request.
   261  func (c *ProjectsLocationsExternalAccountKeysCreateCall) Header() http.Header {
   262  	if c.header_ == nil {
   263  		c.header_ = make(http.Header)
   264  	}
   265  	return c.header_
   266  }
   267  
   268  func (c *ProjectsLocationsExternalAccountKeysCreateCall) doRequest(alt string) (*http.Response, error) {
   269  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   270  	var body io.Reader = nil
   271  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.externalaccountkey)
   272  	if err != nil {
   273  		return nil, err
   274  	}
   275  	c.urlParams_.Set("alt", alt)
   276  	c.urlParams_.Set("prettyPrint", "false")
   277  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+parent}/externalAccountKeys")
   278  	urls += "?" + c.urlParams_.Encode()
   279  	req, err := http.NewRequest("POST", urls, body)
   280  	if err != nil {
   281  		return nil, err
   282  	}
   283  	req.Header = reqHeaders
   284  	googleapi.Expand(req.URL, map[string]string{
   285  		"parent": c.parent,
   286  	})
   287  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   288  }
   289  
   290  // Do executes the "publicca.projects.locations.externalAccountKeys.create" call.
   291  // Any non-2xx status code is an error. Response headers are in either
   292  // *ExternalAccountKey.ServerResponse.Header or (if a response was returned at
   293  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   294  // check whether the returned error was because http.StatusNotModified was
   295  // returned.
   296  func (c *ProjectsLocationsExternalAccountKeysCreateCall) Do(opts ...googleapi.CallOption) (*ExternalAccountKey, error) {
   297  	gensupport.SetOptions(c.urlParams_, opts...)
   298  	res, err := c.doRequest("json")
   299  	if res != nil && res.StatusCode == http.StatusNotModified {
   300  		if res.Body != nil {
   301  			res.Body.Close()
   302  		}
   303  		return nil, gensupport.WrapError(&googleapi.Error{
   304  			Code:   res.StatusCode,
   305  			Header: res.Header,
   306  		})
   307  	}
   308  	if err != nil {
   309  		return nil, err
   310  	}
   311  	defer googleapi.CloseBody(res)
   312  	if err := googleapi.CheckResponse(res); err != nil {
   313  		return nil, gensupport.WrapError(err)
   314  	}
   315  	ret := &ExternalAccountKey{
   316  		ServerResponse: googleapi.ServerResponse{
   317  			Header:         res.Header,
   318  			HTTPStatusCode: res.StatusCode,
   319  		},
   320  	}
   321  	target := &ret
   322  	if err := gensupport.DecodeResponse(target, res); err != nil {
   323  		return nil, err
   324  	}
   325  	return ret, nil
   326  }
   327  

View as plain text