Skip to content

Commit

Permalink
feat(connect): add CONNECT_TOKEN env var
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Dec 10, 2024
1 parent 0fa5ca2 commit 72f0e70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion .web/docs/guide/install/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,27 @@ This command will pull and run the latest Gate image.

### Mounting a config file and Minekube Connect token

#### Using an environment variable for the token

```sh{3} console
docker run -it --rm \
-v PATH-TO-CONFIG/config.yml:/config.yml \
-e CONNECT_TOKEN=YOUR-TOKEN \
ghcr.io/minekube/gate:latest
```

**Note:** The `CONNECT_TOKEN` environment variable takes precedence over the `connect.json` file, so if both are provided, the token from the environment variable will be used instead.

#### Using a volume for the token

```sh{3} console
docker run -it --rm \
-v PATH-TO-CONFIG/config.yml:/config.yml \
-v PATH-TO-CONFIG/connect.json:/connect.json \
ghcr.io/minekube/gate:latest
```

A [Minekube Connect](https://connect.minekube.com/) token json file can be automatically generated by running Gate with `connect.enable: true` in the config.
A [Minekube Connect](https://connect.minekube.com/) token json file can be automatically generated by running Gate with `connect.enable: true` in the config.

```json connect.json
{"token":"YOUR-TOKEN"}
Expand Down
7 changes: 6 additions & 1 deletion pkg/util/connectutil/config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import (

const tokenFilename = "connect.json"

// load auth token from file or generates it
// load auth token from env, file or generates it
func loadToken(filename string) (string, error) {
// env always takes precedence
if token := os.Getenv("CONNECT_TOKEN"); token != "" {
return token, nil
}

// If the file doesn't exist, create it, or append to the file
f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
Expand Down

0 comments on commit 72f0e70

Please sign in to comment.