()
| 28 | } |
| 29 | |
| 30 | func 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: |
| 46 | 1. A previously run "credhub login" command created a logged-in state |
| 47 | 2. CREDHUB_* envrionment variables containing credentials and log-in information are present |
| 48 | |
| 49 | This 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 | |
| 51 | If you want to get rid of this warning message, you have two options: |
| 52 | a. 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. |
| 53 | b. 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 | } |
searching dependent graphs…