feat: use env variable for setting a default tailnet id when using a system admin key

This commit is contained in:
Johan Siebens
2024-03-14 08:04:26 +01:00
parent 42702682c9
commit a1debdffb8
2 changed files with 17 additions and 2 deletions
+12
View File
@@ -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"
+5 -2
View File
@@ -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"
)
@@ -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()
@@ -88,6 +90,7 @@ func (m defaultSession) TailnetID() uint64 {
type systemAdminTokenSession struct {
key key.ServerPrivate
tid uint64
}
func (m systemAdminTokenSession) GetToken() (string, error) {
@@ -95,7 +98,7 @@ func (m systemAdminTokenSession) GetToken() (string, error) {
}
func (m systemAdminTokenSession) TailnetID() uint64 {
return 0
return m.tid
}
type Anonymous struct {