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