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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | go/src/infra/libs/infraenv/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package infraenv
6
7 import (
8 "os"
9 "path/filepath"
10
11 "github.com/luci/luci-go/common/errors"
12 "google.golang.org/cloud/compute/metadata"
13 )
14
15 // ErrNotFound is returned if the requested credential is not found.
16 var ErrNotFound = errors.New("not found")
17
18 // OnGCE will return true if the current system is a Google Compute Engine
19 // system.
20 var OnGCE = metadata.OnGCE
21
22 // GetLogDogServiceAccountJSON scans the credential directories for the LogDog
23 // service account JSON file.
24 //
25 // If the credential could not be located on this system, ErrNotFound will be
26 // returned.
27 func GetLogDogServiceAccountJSON() (string, error) {
28 return findCredentialFile(systemCredentialDirs, "service-account-luci-lo gdog-publisher.json")
29 }
30
31 func findCredentialFile(dirs []string, name string) (string, error) {
32 for _, d := range dirs {
33 candidate := filepath.Join(d, name)
34 if _, err := os.Stat(candidate); err != nil {
35 if os.IsNotExist(err) {
36 continue
37 }
38
39 return "", errors.Annotate(err).Reason("failed to check [%(path)s]").D("path", candidate).Err()
40 }
41
42 return candidate, nil
43 }
44
45 return "", ErrNotFound
46 }
OLDNEW
« 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