Skip to content

Commit

Permalink
feat: use env variable for setting a default tailnet id when using a …
Browse files Browse the repository at this point in the history
…system admin key
  • Loading branch information
jsiebens committed Mar 15, 2024
1 parent 4270268 commit a1debdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions internal/config/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ func GetString(key, defaultValue string) string {
return defaultValue
}

func GetUint64(key string, defaultValue uint64) uint64 {
v := os.Getenv(key)
if v != "" {
vi, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return defaultValue
}
return vi
}
return defaultValue
}

func validatePublicAddr(addr string) (*url.URL, string, int, error) {
scheme := "https"

Expand Down
7 changes: 5 additions & 2 deletions pkg/client/ionscale/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"github.com/99designs/keyring"
"github.com/jsiebens/ionscale/internal/config"
"github.com/jsiebens/ionscale/internal/key"
"github.com/jsiebens/ionscale/internal/token"
)
Expand All @@ -21,7 +22,8 @@ func LoadClientAuth(addr string, systemAdminKey string) (ClientAuth, error) {
if err != nil {
return nil, fmt.Errorf("invalid system admin key")
}
return systemAdminTokenSession{key: *k}, nil
tid := config.GetUint64("IONSCALE_SYSTEM_ADMIN_DEFAULT_TAILNET_ID", 0)
return systemAdminTokenSession{key: *k, tid: tid}, nil
}

ring, err := openKeyring()
Expand Down Expand Up @@ -88,14 +90,15 @@ func (m defaultSession) TailnetID() uint64 {

type systemAdminTokenSession struct {
key key.ServerPrivate
tid uint64
}

func (m systemAdminTokenSession) GetToken() (string, error) {
return token.GenerateSystemAdminToken(m.key)
}

func (m systemAdminTokenSession) TailnetID() uint64 {
return 0
return m.tid
}

type Anonymous struct {
Expand Down

0 comments on commit a1debdf

Please sign in to comment.