Skip to content

Commit 9f60766

Browse files
authored
feat: enabled loading http-api-token from file (#1728)
1 parent 139f672 commit 9f60766

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

docs/arguments.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ In the example above, watchtower will execute an upgrade attempt on the containe
2727

2828
When no arguments are specified, watchtower will monitor all running containers.
2929

30+
## Secrets/Files
31+
32+
Some arguments can also reference a file, in which case the contents of the file are used as the value.
33+
This can be used to avoid putting secrets in the configuration file or command line.
34+
35+
The following arguments are currently supported (including their corresponding `WATCHTOWER_` environment variables):
36+
- `notification-url`
37+
- `notification-email-server-password`
38+
- `notification-slack-hook-url`
39+
- `notification-msteams-hook`
40+
- `notification-gotify-token`
41+
- `http-api-token`
42+
43+
### Example docker-compose usage
44+
```yaml
45+
secrets:
46+
access_token:
47+
file: access_token
48+
49+
services:
50+
watchtower:
51+
secrets:
52+
- access_token
53+
environment:
54+
- WATCHTOWER_HTTP_API_TOKEN=/run/secrets/access_token
55+
```
56+
3057
## Help
3158
Shows documentation about the supported flags.
3259
@@ -270,6 +297,7 @@ Environment Variable: WATCHTOWER_HTTP_API_UPDATE
270297

271298
## HTTP API Token
272299
Sets an authentication token to HTTP API requests.
300+
Can also reference a file, in which case the contents of the file are used.
273301

274302
```text
275303
Argument: --http-api-token
@@ -363,4 +391,4 @@ requests and may rate limit pull requests (mainly docker.io).
363391
Environment Variable: WATCHTOWER_WARN_ON_HEAD_FAILURE
364392
Possible values: always, auto, never
365393
Default: auto
366-
```
394+
```

internal/flags/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ func GetSecretsFromFiles(rootCmd *cobra.Command) {
466466
"notification-msteams-hook",
467467
"notification-gotify-token",
468468
"notification-url",
469+
"http-api-token",
469470
}
470471
for _, secret := range secrets {
471472
if err := getSecretFromFile(flags, secret); err != nil {

internal/flags/flags_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func TestGetSliceSecretsFromFiles(t *testing.T) {
9090
func testGetSecretsFromFiles(t *testing.T, flagName string, expected string, args ...string) {
9191
cmd := new(cobra.Command)
9292
SetDefaults()
93+
RegisterSystemFlags(cmd)
9394
RegisterNotificationFlags(cmd)
9495
require.NoError(t, cmd.ParseFlags(args))
9596
GetSecretsFromFiles(cmd)

0 commit comments

Comments
 (0)