diff --git a/README.md b/README.md index 317a84cd..5829edba 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,12 @@ Shell example CONFIG_PATH= ./castai-agent ``` +## API_KEY from file + +There is a possibility to read API_KEY from file instead of env variable it can be done by using `API_KEY_FILE` env variable. +This variable points to file that contains API_KEY value. + + ## Contributing ### Run the agent in your IDE diff --git a/internal/config/config.go b/internal/config/config.go index 9c845b9b..8426f70d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -161,6 +161,14 @@ func Get() Config { } } + if apiKeyFile := os.Getenv("API_KEY_FILE"); apiKeyFile != "" { + buf, err := os.ReadFile(apiKeyFile) + if err != nil { + panic(fmt.Errorf("unable to read api key file: %v", err)) + } + cfg.API.Key = string(buf) + } + if err := viper.Unmarshal(&cfg); err != nil { panic(fmt.Errorf("parsing configuration: %v", err)) }