Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: go/src/infra/libs/infraenv/creds.go

Issue 2154953002: Add infraenv, setup creds and tee for Kitchen. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Add coverage file, restrict platforms to actual Infra platforms. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | go/src/infra/libs/infraenv/doc.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/libs/infraenv/creds.go
diff --git a/go/src/infra/libs/infraenv/creds.go b/go/src/infra/libs/infraenv/creds.go
new file mode 100644
index 0000000000000000000000000000000000000000..a60874ade20acbd33f9267ca8198dade99bf54ae
--- /dev/null
+++ b/go/src/infra/libs/infraenv/creds.go
@@ -0,0 +1,46 @@
+// Copyright 2016 The Chromium 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 infraenv
+
+import (
+ "os"
+ "path/filepath"
+
+ "github.com/luci/luci-go/common/errors"
+ "google.golang.org/cloud/compute/metadata"
+)
+
+// ErrNotFound is returned if the requested credential is not found.
+var ErrNotFound = errors.New("not found")
+
+// OnGCE will return true if the current system is a Google Compute Engine
+// system.
+var OnGCE = metadata.OnGCE
+
+// GetLogDogServiceAccountJSON scans the credential directories for the LogDog
+// service account JSON file.
+//
+// If the credential could not be located on this system, ErrNotFound will be
+// returned.
+func GetLogDogServiceAccountJSON() (string, error) {
+ return findCredentialFile(systemCredentialDirs, "service-account-luci-logdog-publisher.json")
+}
+
+func findCredentialFile(dirs []string, name string) (string, error) {
+ for _, d := range dirs {
+ candidate := filepath.Join(d, name)
+ if _, err := os.Stat(candidate); err != nil {
+ if os.IsNotExist(err) {
+ continue
+ }
+
+ return "", errors.Annotate(err).Reason("failed to check [%(path)s]").D("path", candidate).Err()
+ }
+
+ return candidate, nil
+ }
+
+ return "", ErrNotFound
+}
« no previous file with comments | « no previous file | go/src/infra/libs/infraenv/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698