-
Notifications
You must be signed in to change notification settings - Fork 70
/
helpers.go
40 lines (31 loc) · 920 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package credentials
import (
log "github.com/sirupsen/logrus"
"github.com/newrelic/newrelic-cli/internal/config"
)
var defaultProfile *Profile
// WithCredentials loads and returns the CLI credentials.
func WithCredentials(f func(c *Credentials)) {
WithCredentialsFrom(config.DefaultConfigDirectory, f)
}
// WithCredentialsFrom loads and returns the CLI credentials from a specified location.
func WithCredentialsFrom(configDir string, f func(c *Credentials)) {
c, err := LoadCredentials(configDir)
if err != nil {
log.Fatal(err)
}
f(c)
}
// DefaultProfile retrieves the current default profile.
func DefaultProfile() *Profile {
if defaultProfile == nil {
WithCredentials(func(c *Credentials) {
defaultProfile = c.Default()
})
}
return defaultProfile
}
// SetDefaultProfile allows mocking of the default profile for testing purposes.
func SetDefaultProfile(p Profile) {
defaultProfile = &p
}