-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
google/internal/externalaccount: adding BYOID Metrics
Adds framework for sending BYOID metrics via the x-goog-api-client header on outgoing sts requests. Also adds a header file for getting the current version of GoLang Change-Id: Id5431def96f4cfc03e4ada01d5fb8cac8cfa56a9 GitHub-Last-Rev: c93cd47 GitHub-Pull-Request: #661 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/523595 Reviewed-by: Leo Siracusa <leosiracusa@google.com> Run-TryBot: Cody Oss <codyoss@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cody Oss <codyoss@google.com>
- Loading branch information
Showing
13 changed files
with
202 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package externalaccount | ||
|
||
import ( | ||
"runtime" | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
var ( | ||
// version is a package internal global variable for testing purposes. | ||
version = runtime.Version | ||
) | ||
|
||
// versionUnknown is only used when the runtime version cannot be determined. | ||
const versionUnknown = "UNKNOWN" | ||
|
||
// goVersion returns a Go runtime version derived from the runtime environment | ||
// that is modified to be suitable for reporting in a header, meaning it has no | ||
// whitespace. If it is unable to determine the Go runtime version, it returns | ||
// versionUnknown. | ||
func goVersion() string { | ||
const develPrefix = "devel +" | ||
|
||
s := version() | ||
if strings.HasPrefix(s, develPrefix) { | ||
s = s[len(develPrefix):] | ||
if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { | ||
s = s[:p] | ||
} | ||
return s | ||
} else if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { | ||
s = s[:p] | ||
} | ||
|
||
notSemverRune := func(r rune) bool { | ||
return !strings.ContainsRune("0123456789.", r) | ||
} | ||
|
||
if strings.HasPrefix(s, "go1") { | ||
s = s[2:] | ||
var prerelease string | ||
if p := strings.IndexFunc(s, notSemverRune); p >= 0 { | ||
s, prerelease = s[:p], s[p:] | ||
} | ||
if strings.HasSuffix(s, ".") { | ||
s += "0" | ||
} else if strings.Count(s, ".") < 2 { | ||
s += ".0" | ||
} | ||
if prerelease != "" { | ||
// Some release candidates already have a dash in them. | ||
if !strings.HasPrefix(prerelease, "-") { | ||
prerelease = "-" + prerelease | ||
} | ||
s += prerelease | ||
} | ||
return s | ||
} | ||
return "UNKNOWN" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package externalaccount | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestGoVersion(t *testing.T) { | ||
testVersion := func(v string) func() string { | ||
return func() string { | ||
return v | ||
} | ||
} | ||
for _, tst := range []struct { | ||
v func() string | ||
want string | ||
}{ | ||
{ | ||
testVersion("go1.19"), | ||
"1.19.0", | ||
}, | ||
{ | ||
testVersion("go1.21-20230317-RC01"), | ||
"1.21.0-20230317-RC01", | ||
}, | ||
{ | ||
testVersion("devel +abc1234"), | ||
"abc1234", | ||
}, | ||
{ | ||
testVersion("this should be unknown"), | ||
versionUnknown, | ||
}, | ||
} { | ||
version = tst.v | ||
got := goVersion() | ||
if diff := cmp.Diff(got, tst.want); diff != "" { | ||
t.Errorf("got(-),want(+):\n%s", diff) | ||
} | ||
} | ||
version = runtime.Version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters