Skip to content

Commit

Permalink
Updated Oink to accept environment variables to override global API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
RLado committed Sep 10, 2024
1 parent a9d387d commit 2914e90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ systemctl start oink_ddns
```
- You are done! Your domain DNS record should update automatically

---
### CLI options
**Oink!** also provides a CLI interface for manual DNS updates and debugging. The CLI options are the following:

> Type `oink -h` to display this help message
```
Usage of oink:
-c string
Path to oink_ddns configuration file (default "/etc/oink_ddns/config.json")
-u Update the DNS records immediately and exit
-v Enable verbose output
```

---
### Overriding API keys
For certain specific use cases, you might want to override the global API keys of your configuration file using environment variables. To do so, **both** `OINK_OVERRIDE_SECRETAPIKEY` and `OINK_OVERRIDE_APIKEY` must be set. These environment variables will take precedence over the global API keys set in the configuration file.
9 changes: 9 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ func main() {
cfg.Global.Interval = 60
}

// If environment variables for the API keys are set, override the global API keys of the config file
if os.Getenv("OINK_OVERRIDE_SECRETAPIKEY") != "" && os.Getenv("OINK_OVERRIDE_APIKEY") != "" {
if *verbose {
log.Printf("Overriding secretapikey and apikey with environment variables")
}
cfg.Global.Secretapikey = os.Getenv("OINK_OVERRIDE_SECRETAPIKEY")
cfg.Global.Apikey = os.Getenv("OINK_OVERRIDE_APIKEY")
}

// Run the update loop
for {
// Update domains
Expand Down

0 comments on commit 2914e90

Please sign in to comment.