|
5 | 5 | "context" |
6 | 6 | "errors" |
7 | 7 | "fmt" |
| 8 | + "io" |
8 | 9 | "io/ioutil" |
9 | 10 | "log" |
10 | 11 | "net/http" |
@@ -39,6 +40,12 @@ var OneShot bool |
39 | 40 | // VenafiCloudMode flag determines which format to load for config and credential type |
40 | 41 | var VenafiCloudMode bool |
41 | 42 |
|
| 43 | +// ClientID is the clientID in case of Venafi Cloud mode |
| 44 | +var ClientID string |
| 45 | + |
| 46 | +// PrivateKeyPath is the path for the service account private key in case of Venafi Cloud mode |
| 47 | +var PrivateKeyPath string |
| 48 | + |
42 | 49 | // CredentialsPath is where the agent will try to loads the credentials. (Experimental) |
43 | 50 | var CredentialsPath string |
44 | 51 |
|
@@ -198,6 +205,11 @@ func getConfiguration() (Config, client.Client) { |
198 | 205 | log.Fatalf("Failed to read config file: %s", err) |
199 | 206 | } |
200 | 207 |
|
| 208 | + // If the ClientID of the service account is specified, then assume we are in Venafi Cloud mode. |
| 209 | + if ClientID != "" { |
| 210 | + VenafiCloudMode = true |
| 211 | + } |
| 212 | + |
201 | 213 | config, err := ParseConfig(b, VenafiCloudMode) |
202 | 214 | if err != nil { |
203 | 215 | log.Fatalf("Failed to parse config file: %s", err) |
@@ -225,14 +237,19 @@ func getConfiguration() (Config, client.Client) { |
225 | 237 | log.Printf("Loaded config: \n%s", dump) |
226 | 238 |
|
227 | 239 | var credentials client.Credentials |
228 | | - if CredentialsPath != "" { |
| 240 | + if ClientID != "" { |
| 241 | + credentials = &client.VenafiSvcAccountCredentials{ |
| 242 | + ClientID: ClientID, |
| 243 | + PrivateKeyFile: PrivateKeyPath, |
| 244 | + } |
| 245 | + } else if CredentialsPath != "" { |
229 | 246 | file, err = os.Open(CredentialsPath) |
230 | 247 | if err != nil { |
231 | 248 | log.Fatalf("Failed to load credentials from file %s", CredentialsPath) |
232 | 249 | } |
233 | 250 | defer file.Close() |
234 | 251 |
|
235 | | - b, err = ioutil.ReadAll(file) |
| 252 | + b, err = io.ReadAll(file) |
236 | 253 | if err != nil { |
237 | 254 | log.Fatalf("Failed to read credentials file: %v", err) |
238 | 255 | } |
|
0 commit comments