Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read api key from file #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Shell example
CONFIG_PATH=<PATH_TO_CONFIG> ./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
Expand Down
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down