MCPcopy Create free account
hub / github.com/cloudfoundry/credhub-cli / ReadConfig

Function ReadConfig

config/config.go:30–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28}
29
30func ReadConfig() Config {
31 c := Config{}
32
33 data, err := os.ReadFile(ConfigPath())
34 if err != nil {
35 if !os.IsNotExist(err) {
36 return c
37 }
38 }
39
40 json.Unmarshal(data, &c)
41
42 if server, ok := os.LookupEnv("CREDHUB_SERVER"); ok {
43 if util.TokenIsPresent(c.AccessToken) {
44 util.Warning(
45 `WARNING: Two different login methods were detected:
461. A previously run "credhub login" command created a logged-in state
472. CREDHUB_* envrionment variables containing credentials and log-in information are present
48
49This command will now proceed after attempting to log you in using the CREDHUB_* environment variables from method 2, hence ignoring the current logged-in state from method 1.
50
51If you want to get rid of this warning message, you have two options:
52a. Run "credhub logout". This will remove the logged-in state created by the "credhub login" command. Subsequent commands will use the environment variables to log you in.
53b. Unset the "CREDHUB_SERVER" environment variable. Subsequent commands will use your logged-in state.
54
55`)
56
57 }
58 c.ApiURL = util.AddDefaultSchemeIfNecessary(server)
59 c.AuthURL = ""
60 c.AccessToken = ""
61 c.RefreshToken = ""
62 }
63 if client, ok := os.LookupEnv("CREDHUB_CLIENT"); ok {
64 c.ClientID = client
65 }
66 if clientSecret, ok := os.LookupEnv("CREDHUB_SECRET"); ok {
67 c.ClientSecret = clientSecret
68 }
69 if caCert, ok := os.LookupEnv("CREDHUB_CA_CERT"); ok {
70 certs, err := ReadOrGetCaCerts([]string{caCert})
71 if err != nil {
72 fmt.Fprintf(os.Stderr, "error parsing CA certificates: %+v", err)
73 return c
74 }
75 c.CaCerts = certs
76 }
77 if timeoutString, ok := os.LookupEnv("CREDHUB_HTTP_TIMEOUT"); ok {
78 timeout, err := time.ParseDuration(timeoutString)
79 if err != nil {
80 fmt.Fprintf(os.Stderr, "error parsing HttpTimeout: %+v", err)
81 return c
82 }
83 c.HttpTimeout = &timeout
84 }
85
86 return c
87}

Callers 15

mainFunction · 0.92
token_test.goFile · 0.92
getAllCredentialsForPathFunction · 0.92
login_test.goFile · 0.92
setConfigAuthUrlFunction · 0.92
version_test.goFile · 0.92
export_test.goFile · 0.92
delete_test.goFile · 0.92
api_test.goFile · 0.92
setCachedServerVersionFunction · 0.92
ItRequiresAnAPIToBeSetFunction · 0.92
runLogoutCommandFunction · 0.92

Calls 6

TokenIsPresentFunction · 0.92
WarningFunction · 0.92
ConfigPathFunction · 0.85
ReadFileMethod · 0.80
ReadOrGetCaCertsFunction · 0.70

Tested by 4

setConfigAuthUrlFunction · 0.74
setCachedServerVersionFunction · 0.74
ItRequiresAnAPIToBeSetFunction · 0.74
runLogoutCommandFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…