Skip to content

Commit

Permalink
Merge pull request #43 from bueti/use-env-vars
Browse files Browse the repository at this point in the history
optional use of env vars for use on servers
  • Loading branch information
bueti authored Jun 20, 2023
2 parents cb92b5c + 9252364 commit 1ca6557
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ To configure your username and password run:
bocker config set
```

If you want to run bocker on server where there's no keyring tool installed, set the following environment variables:

```sh
export DOCKER_USERNAME=<your docker username>
export DOCKER_PASSWORD=<your docker password>
```

`bocker` will prefer environment variables over the keyring.

![bocker config](https://vhs.charm.sh/vhs-6w65TVtSWeJqk5oGv5N9cp.gif)

### List existing backups
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func SetKey(service, secret string) error {

// GetKey retrieves a key from the OS keyring
func GetKey(service string) (string, error) {
if os.Getenv("DOCKER_PASSWORD") != "" {
return os.Getenv("DOCKER_PASSWORD"), nil
}

// get password
secret, err := keyring.Get(service, AppName)
if err != nil {
Expand All @@ -110,6 +114,10 @@ func GetKey(service string) (string, error) {
func GetUsername() (*Username, error) {
var username Username

if os.Getenv("DOCKER_USERNAME") != "" {
return &Username{Username: os.Getenv("DOCKER_USERNAME")}, nil
}

dir, err := xdg.ConfigFile(AppName)
if err != nil {
return nil, err
Expand Down

0 comments on commit 1ca6557

Please sign in to comment.