| OLD | NEW |
| (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 } |
| OLD | NEW |