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 osconfig is an auto-generated package for the
18// OS Config API.
19//
20// OS management tools that can be used for patch management, patch
21// compliance, and configuration management on VM instances.
22//
23// Use of Context
24//
25// The ctx passed to NewClient is used for authentication requests and
26// for creating the underlying connection, but is not used for subsequent calls.
27// Individual methods on the client use the ctx given to them.
28//
29// To close the open connection, use the Close() method.
30//
31// For information about setting deadlines, reusing contexts, and more
32// please visit pkg.go.dev/cloud.google.com/go.
33package osconfig // import "cloud.google.com/go/osconfig/apiv1"
34
35import (
36	"context"
37	"os"
38	"runtime"
39	"strconv"
40	"strings"
41	"unicode"
42
43	"google.golang.org/api/option"
44	"google.golang.org/grpc/metadata"
45)
46
47// For more information on implementing a client constructor hook, see
48// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
49type clientHookParams struct{}
50type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
51
52const versionClient = "20210420"
53
54func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
55	out, _ := metadata.FromOutgoingContext(ctx)
56	out = out.Copy()
57	for _, md := range mds {
58		for k, v := range md {
59			out[k] = append(out[k], v...)
60		}
61	}
62	return metadata.NewOutgoingContext(ctx, out)
63}
64
65func checkDisableDeadlines() (bool, error) {
66	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
67	if !ok {
68		return false, nil
69	}
70
71	b, err := strconv.ParseBool(raw)
72	return b, err
73}
74
75// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
76func DefaultAuthScopes() []string {
77	return []string{
78		"https://www.googleapis.com/auth/cloud-platform",
79	}
80}
81
82// versionGo returns the Go runtime version. The returned string
83// has no whitespace, suitable for reporting in header.
84func versionGo() string {
85	const develPrefix = "devel +"
86
87	s := runtime.Version()
88	if strings.HasPrefix(s, develPrefix) {
89		s = s[len(develPrefix):]
90		if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
91			s = s[:p]
92		}
93		return s
94	}
95
96	notSemverRune := func(r rune) bool {
97		return !strings.ContainsRune("0123456789.", r)
98	}
99
100	if strings.HasPrefix(s, "go1") {
101		s = s[2:]
102		var prerelease string
103		if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
104			s, prerelease = s[:p], s[p:]
105		}
106		if strings.HasSuffix(s, ".") {
107			s += "0"
108		} else if strings.Count(s, ".") < 2 {
109			s += ".0"
110		}
111		if prerelease != "" {
112			s += "-" + prerelease
113		}
114		return s
115	}
116	return "UNKNOWN"
117}
118