1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17// Package privateca is an auto-generated package for the
18// Certificate Authority API.
19//
20// The Certificate Authority Service API is a highly-available, scalable
21// service that enables you to simplify and automate the management of
22// private certificate authorities (CAs) while staying in control of your
23// private keys."
24//
25// Example usage
26//
27// To get started with this package, create a client.
28//  ctx := context.Background()
29//  c, err := privateca.NewCertificateAuthorityClient(ctx)
30//  if err != nil {
31//  	// TODO: Handle error.
32//  }
33//  defer c.Close()
34//
35// The client will use your default application credentials. Clients should be reused instead of created as needed.
36// The methods of Client are safe for concurrent use by multiple goroutines.
37// The returned client must be Closed when it is done being used.
38//
39// Using the Client
40//
41// The following is an example of making an API call with the newly created client.
42//
43//  ctx := context.Background()
44//  c, err := privateca.NewCertificateAuthorityClient(ctx)
45//  if err != nil {
46//  	// TODO: Handle error.
47//  }
48//  defer c.Close()
49//
50//  req := &privatecapb.CreateCertificateRequest{
51//  	// TODO: Fill request struct fields.
52//  	// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/security/privateca/v1#CreateCertificateRequest.
53//  }
54//  resp, err := c.CreateCertificate(ctx, req)
55//  if err != nil {
56//  	// TODO: Handle error.
57//  }
58//  // TODO: Use resp.
59//  _ = resp
60//
61// Use of Context
62//
63// The ctx passed to NewClient is used for authentication requests and
64// for creating the underlying connection, but is not used for subsequent calls.
65// Individual methods on the client use the ctx given to them.
66//
67// To close the open connection, use the Close() method.
68//
69// For information about setting deadlines, reusing contexts, and more
70// please visit https://pkg.go.dev/cloud.google.com/go.
71package privateca // import "cloud.google.com/go/security/privateca/apiv1"
72
73import (
74	"context"
75	"os"
76	"runtime"
77	"strconv"
78	"strings"
79	"unicode"
80
81	"google.golang.org/api/option"
82	"google.golang.org/grpc/metadata"
83)
84
85// For more information on implementing a client constructor hook, see
86// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
87type clientHookParams struct{}
88type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
89
90const versionClient = "20210821"
91
92func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
93	out, _ := metadata.FromOutgoingContext(ctx)
94	out = out.Copy()
95	for _, md := range mds {
96		for k, v := range md {
97			out[k] = append(out[k], v...)
98		}
99	}
100	return metadata.NewOutgoingContext(ctx, out)
101}
102
103func checkDisableDeadlines() (bool, error) {
104	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
105	if !ok {
106		return false, nil
107	}
108
109	b, err := strconv.ParseBool(raw)
110	return b, err
111}
112
113// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
114func DefaultAuthScopes() []string {
115	return []string{
116		"https://www.googleapis.com/auth/cloud-platform",
117	}
118}
119
120// versionGo returns the Go runtime version. The returned string
121// has no whitespace, suitable for reporting in header.
122func versionGo() string {
123	const develPrefix = "devel +"
124
125	s := runtime.Version()
126	if strings.HasPrefix(s, develPrefix) {
127		s = s[len(develPrefix):]
128		if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
129			s = s[:p]
130		}
131		return s
132	}
133
134	notSemverRune := func(r rune) bool {
135		return !strings.ContainsRune("0123456789.", r)
136	}
137
138	if strings.HasPrefix(s, "go1") {
139		s = s[2:]
140		var prerelease string
141		if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
142			s, prerelease = s[:p], s[p:]
143		}
144		if strings.HasSuffix(s, ".") {
145			s += "0"
146		} else if strings.Count(s, ".") < 2 {
147			s += ".0"
148		}
149		if prerelease != "" {
150			s += "-" + prerelease
151		}
152		return s
153	}
154	return "UNKNOWN"
155}
156