Skip to content

Commit

Permalink
Merge pull request #158 from nodeset-org/daemon-auth
Browse files Browse the repository at this point in the history
Add support for daemon JWT authorization
  • Loading branch information
jclapis authored Oct 2, 2024
2 parents 5462229 + d9827e8 commit 511a16c
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 46 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ require (
github.com/goccy/go-json v0.10.3
github.com/mholt/archiver/v4 v4.0.0-alpha.8
github.com/mitchellh/go-homedir v1.1.0
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241001194414-bd5ba3c5fde2
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241001192501-b11ba9e5209f
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241001200731-88e20a15b576
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002183331-b9b94bf2218f
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002190845-1a9ed88f4627
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002183435-c4cb9515df86
github.com/nodeset-org/osha v0.3.1-0.20240927160812-d66358d4e091
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/rivo/tview v0.0.0-20230208211350-7dfff1ce7854 // DO NOT UPGRADE
github.com/rocket-pool/node-manager-core v0.5.2-0.20241001041416-40f4fb819f98
github.com/rocket-pool/node-manager-core v0.5.2-0.20241002072934-89c9cc081cf6
github.com/rocket-pool/rocketpool-go/v2 v2.0.0-b2.0.20240709170030-c27aeb5fb99b
github.com/stretchr/testify v1.9.0
github.com/tyler-smith/go-bip39 v1.1.0
Expand Down Expand Up @@ -85,6 +85,7 @@ require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOEL
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241001194414-bd5ba3c5fde2 h1:PM6k+J0uXHtWR2W55c6GrSfqNVHi02/+HDx3wQ57YEk=
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241001194414-bd5ba3c5fde2/go.mod h1:hUQX0mH9zxopcQKLE2xenk6TpG+X1ZiqAZ19x6meY/U=
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241001192501-b11ba9e5209f h1:iAxCtnQkT8UGunXIyGNdhsVcqwQve0SefNMdoja3kCc=
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241001192501-b11ba9e5209f/go.mod h1:KCZ/EptpaWrk/O2jYAUH2hDYt6Mrcjf68fVOeT8fuew=
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241001200731-88e20a15b576 h1:ZRw5ssx0ZruQJvu4UvsT+UGfTuMnSRCZy1VE2UPjeWo=
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241001200731-88e20a15b576/go.mod h1:6UypLzyI/G86ZS1jpT6J0hovHoAihqnMHEUYaXAPv5U=
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002183331-b9b94bf2218f h1:uy8P5wxv5lBEPurP3OlaCKMaq+0bw7j/lYtAnD7TM7c=
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002183331-b9b94bf2218f/go.mod h1:Qf6r3WnPqaxgZI9L/9SYQZnjEIv9+OLEF0VnjzElziU=
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002190845-1a9ed88f4627 h1:7Gj61zC4/+ZHd94QHq7pz/82PKto+5C3LPeZolEeIN0=
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002190845-1a9ed88f4627/go.mod h1:VXYiN0ZrXbeNALJLa0sin4AzlSrFuGH8gW1YSywoVoI=
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002183435-c4cb9515df86 h1:Sf/NTZN3u23+fgdMVR40Ewf8lTFEUfxBonAQ05670W4=
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002183435-c4cb9515df86/go.mod h1:ZeMwsXDZWB3U2N8H2QqtMUBO/JbCYS2VCSyptxHZeNM=
github.com/nodeset-org/nodeset-client-go v1.0.1-0.20240927160821-e348e05e2363 h1:iivCknAFZlpxPwbIDjPc9E2bnj55c2STrXT9MvuMzQM=
github.com/nodeset-org/nodeset-client-go v1.0.1-0.20240927160821-e348e05e2363/go.mod h1:slpwejkJ/vYU9SKA3SYw4hIPJLzDUeQxcx+Cm04kkIA=
github.com/nodeset-org/osha v0.3.1-0.20240927160812-d66358d4e091 h1:oAs4/Yx4jnsNdWh3vTKum1sXC8VCvsY1H2VFSRRkgjc=
Expand Down Expand Up @@ -525,8 +525,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rocket-pool/batch-query v1.0.0 h1:5HejmT1n1fIdLIqUhTNwbkG2PGOPl3IVjCpFQcQZ4I4=
github.com/rocket-pool/batch-query v1.0.0/go.mod h1:d1CmxShzk0fioJ4yX0eFGhz2an1odnW/LZ2cp3eDGIQ=
github.com/rocket-pool/node-manager-core v0.5.2-0.20241001041416-40f4fb819f98 h1:/vmzEAVs15gRK7q8lUYi1+MJd0XhxJwPe3zMdRB+3c8=
github.com/rocket-pool/node-manager-core v0.5.2-0.20241001041416-40f4fb819f98/go.mod h1:/H1wq3skacZi4zjgnKTtnm0wBLJH7H5r0CvLtWFs19Y=
github.com/rocket-pool/node-manager-core v0.5.2-0.20241002072934-89c9cc081cf6 h1:rn0t1IoOEy7ecETHRIGBQd40GDuqT4lK8MeWsfoGKPU=
github.com/rocket-pool/node-manager-core v0.5.2-0.20241002072934-89c9cc081cf6/go.mod h1:/H1wq3skacZi4zjgnKTtnm0wBLJH7H5r0CvLtWFs19Y=
github.com/rocket-pool/rocketpool-go/v2 v2.0.0-b2.0.20240709170030-c27aeb5fb99b h1:39UmJzNR71/OMIzblEY9wq+3nojGa/gQOJJpLBa6XcE=
github.com/rocket-pool/rocketpool-go/v2 v2.0.0-b2.0.20240709170030-c27aeb5fb99b/go.mod h1:pcY43H/m5pjr7zacrsKVaXnXfKKi1UV08VDPUwxbJkc=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
46 changes: 46 additions & 0 deletions hyperdrive-cli/client/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package client

import (
"fmt"
"path/filepath"

csconfig "github.com/nodeset-org/hyperdrive-constellation/shared/config"
"github.com/nodeset-org/hyperdrive-daemon/shared/auth"
hdconfig "github.com/nodeset-org/hyperdrive-daemon/shared/config"
swconfig "github.com/nodeset-org/hyperdrive-stakewise/shared/config"
)

var (
hdApiKeyRelPath string = filepath.Join(hdconfig.SecretsDir, hdconfig.DaemonKeyFilename)
swApiKeyRelPath string = filepath.Join(hdconfig.SecretsDir, hdconfig.ModulesName, swconfig.ModuleName, hdconfig.DaemonKeyFilename)
csApiKeyRelPath string = filepath.Join(hdconfig.SecretsDir, hdconfig.ModulesName, csconfig.ModuleName, hdconfig.DaemonKeyFilename)
)

// Create the metrics and modules folders, and deploy the config templates for Prometheus and Grafana
func (c *HyperdriveClient) GenerateDaemonAuthKeys(config *GlobalConfig) error {
// Create the API key for the Hyperdrive daemon
hdApiKeyPath := filepath.Join(c.Context.UserDirPath, hdApiKeyRelPath)
err := auth.GenerateAuthKeyIfNotPresent(hdApiKeyPath, auth.DefaultKeyLength)
if err != nil {
return fmt.Errorf("error generating Hyperdrive daemon API key: %w", err)
}

// Create the API key for the StakeWise module if enabled
if config.StakeWise.Enabled.Value {
swApiKeyPath := filepath.Join(c.Context.UserDirPath, swApiKeyRelPath)
err = auth.GenerateAuthKeyIfNotPresent(swApiKeyPath, auth.DefaultKeyLength)
if err != nil {
return fmt.Errorf("error generating StakeWise module API key: %w", err)
}
}

// Create the API key for the Constellation module if enabled
if config.Constellation.Enabled.Value {
csApiKeyPath := filepath.Join(c.Context.UserDirPath, csApiKeyRelPath)
err = auth.GenerateAuthKeyIfNotPresent(csApiKeyPath, auth.DefaultKeyLength)
if err != nil {
return fmt.Errorf("error generating Constellation module API key: %w", err)
}
}
return nil
}
32 changes: 26 additions & 6 deletions hyperdrive-cli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"fmt"
"log/slog"
"net/http/httptrace"
"path/filepath"

docker "github.com/docker/docker/client"
"github.com/fatih/color"
csclient "github.com/nodeset-org/hyperdrive-constellation/client"
csconfig "github.com/nodeset-org/hyperdrive-constellation/shared/config"
"github.com/nodeset-org/hyperdrive-daemon/client"
"github.com/nodeset-org/hyperdrive-daemon/shared/config"
"github.com/nodeset-org/hyperdrive-daemon/shared/auth"
hdconfig "github.com/nodeset-org/hyperdrive-daemon/shared/config"
swclient "github.com/nodeset-org/hyperdrive-stakewise/client"
swconfig "github.com/nodeset-org/hyperdrive-stakewise/shared/config"
"github.com/nodeset-org/hyperdrive/hyperdrive-cli/utils/context"
Expand All @@ -27,6 +29,8 @@ const (
BackupSettingsFile string = "user-settings-backup.yml"

terminalLogColor color.Attribute = color.FgHiYellow

cliIssuer string = "hd-cli"
)

// Hyperdrive client
Expand Down Expand Up @@ -61,7 +65,7 @@ func NewHyperdriveClientFromCtx(c *cli.Context) (*HyperdriveClient, error) {

// Create new Hyperdrive client from a custom context
func NewHyperdriveClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext) (*HyperdriveClient, error) {
logger := log.NewTerminalLogger(hdCtx.DebugEnabled, terminalLogColor).With(slog.String(log.OriginKey, config.HyperdriveDaemonRoute))
logger := log.NewTerminalLogger(hdCtx.DebugEnabled, terminalLogColor).With(slog.String(log.OriginKey, hdconfig.HyperdriveDaemonRoute))

// Create the tracer if required
var tracer *httptrace.ClientTrace
Expand Down Expand Up @@ -94,12 +98,18 @@ func NewHyperdriveClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext) (*Hy
return nil, fmt.Errorf("error loading config: %w", err)
}

url, err = url.Parse(fmt.Sprintf("http://localhost:%d/%s", cfg.Hyperdrive.ApiPort.Value, config.HyperdriveApiClientRoute))
url, err = url.Parse(fmt.Sprintf("http://localhost:%d/%s", cfg.Hyperdrive.ApiPort.Value, hdconfig.HyperdriveApiClientRoute))
if err != nil {
return nil, fmt.Errorf("error parsing Hyperdrive API URL: %w", err)
}
}
hdClient.Api = client.NewApiClient(url, logger, tracer)

// Create the auth manager
authPath := filepath.Join(hdCtx.UserDirPath, hdApiKeyRelPath)
authMgr := auth.NewAuthorizationManager(authPath, cliIssuer, auth.DefaultRequestLifespan)

// Create the API client
hdClient.Api = client.NewApiClient(url, logger, tracer, authMgr)
return hdClient, nil
}

Expand Down Expand Up @@ -148,7 +158,12 @@ func NewStakewiseClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext, hdCli
}
}

swClient.Api = swclient.NewApiClient(url, logger, tracer)
// Create the auth manager
authPath := filepath.Join(hdCtx.UserDirPath, swApiKeyRelPath)
authMgr := auth.NewAuthorizationManager(authPath, cliIssuer, auth.DefaultRequestLifespan)

// Create the API client
swClient.Api = swclient.NewApiClient(url, logger, tracer, authMgr)
return swClient, nil
}

Expand Down Expand Up @@ -191,7 +206,12 @@ func NewConstellationClientFromCtx(c *cli.Context, hdClient *HyperdriveClient) (
}
}

csClient.Api = csclient.NewApiClient(url, logger, tracer)
// Create the auth manager
authPath := filepath.Join(hdCtx.UserDirPath, csApiKeyRelPath)
authMgr := auth.NewAuthorizationManager(authPath, cliIssuer, auth.DefaultRequestLifespan)

// Create the API client
csClient.Api = csclient.NewApiClient(url, logger, tracer, authMgr)
return csClient, nil
}

Expand Down
2 changes: 1 addition & 1 deletion hyperdrive-cli/client/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Build a docker compose command
func (c *HyperdriveClient) compose(composeFiles []string, args string) (string, error) {
// Get the expanded config path
expandedConfigPath, err := homedir.Expand(c.Context.ConfigPath)
expandedConfigPath, err := homedir.Expand(c.Context.UserDirPath)
if err != nil {
return "", err
}
Expand Down
10 changes: 5 additions & 5 deletions hyperdrive-cli/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *HyperdriveClient) LoadConfig() (*GlobalConfig, bool, error) {
return c.cfg, c.isNewCfg, nil
}

settingsFilePath := filepath.Join(c.Context.ConfigPath, SettingsFile)
settingsFilePath := filepath.Join(c.Context.UserDirPath, SettingsFile)
expandedPath, err := homedir.Expand(settingsFilePath)
if err != nil {
return nil, false, fmt.Errorf("error expanding settings file path: %w", err)
Expand All @@ -46,7 +46,7 @@ func (c *HyperdriveClient) LoadConfig() (*GlobalConfig, bool, error) {
}

// Config wasn't loaded, but there was no error - we should create one.
hdCfg, err := hdconfig.NewHyperdriveConfig(c.Context.ConfigPath, c.Context.HyperdriveNetworkSettings)
hdCfg, err := hdconfig.NewHyperdriveConfig(c.Context.UserDirPath, c.Context.HyperdriveNetworkSettings)
if err != nil {
return nil, false, fmt.Errorf("error creating Hyperdrive config: %w", err)
}
Expand All @@ -68,7 +68,7 @@ func (c *HyperdriveClient) LoadConfig() (*GlobalConfig, bool, error) {

// Load the backup config
func (c *HyperdriveClient) LoadBackupConfig() (*GlobalConfig, error) {
settingsFilePath := filepath.Join(c.Context.ConfigPath, BackupSettingsFile)
settingsFilePath := filepath.Join(c.Context.UserDirPath, BackupSettingsFile)
expandedPath, err := homedir.Expand(settingsFilePath)
if err != nil {
return nil, fmt.Errorf("error expanding backup settings file path: %w", err)
Expand All @@ -79,7 +79,7 @@ func (c *HyperdriveClient) LoadBackupConfig() (*GlobalConfig, error) {

// Save the config
func (c *HyperdriveClient) SaveConfig(cfg *GlobalConfig) error {
settingsFileDirectoryPath, err := homedir.Expand(c.Context.ConfigPath)
settingsFileDirectoryPath, err := homedir.Expand(c.Context.UserDirPath)
if err != nil {
return err
}
Expand All @@ -97,7 +97,7 @@ func (c *HyperdriveClient) SaveConfig(cfg *GlobalConfig) error {
// Create the metrics and modules folders, and deploy the config templates for Prometheus and Grafana
func (c *HyperdriveClient) DeployMetricsConfigurations(config *GlobalConfig) error {
// Make sure the metrics path exists
metricsDirPath := filepath.Join(c.Context.ConfigPath, metricsDir)
metricsDirPath := filepath.Join(c.Context.UserDirPath, metricsDir)
modulesDirPath := filepath.Join(metricsDirPath, hdconfig.ModulesName)
err := os.MkdirAll(modulesDirPath, metricsDirMode)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions hyperdrive-cli/client/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ func (c *GlobalConfig) ModulesDirectory() string {
func (c *GlobalConfig) ValidatorsDirectory() string {
return config.ValidatorsDirectory
}

func (c *GlobalConfig) HyperdriveApiKeyPath() string {
return hdApiKeyRelPath
}

func (c *GlobalConfig) StakeWiseApiKeyPath() string {
return swApiKeyRelPath
}

func (c *GlobalConfig) ConstellationApiKeyPath() string {
return csApiKeyRelPath
}
1 change: 1 addition & 0 deletions hyperdrive-cli/commands/constellation/node/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func RegisterCommands(cmd *cli.Command, name string, aliases []string) {
Aliases: []string{"r"},
Flags: []cli.Flag{
utils.YesFlag,
registerForceFlag,
},
Usage: "Registers your node with Constellation so you can create and run minipools.",
Action: func(c *cli.Context) error {
Expand Down
23 changes: 16 additions & 7 deletions hyperdrive-cli/commands/constellation/node/register-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
"github.com/urfave/cli/v2"
)

var (
registerForceFlag *cli.BoolFlag = &cli.BoolFlag{
Name: "force",
Usage: "Force registration on nodeset.io, even if the node is already registered with the Constellation contracts",
}
)

func registerNode(c *cli.Context) error {
// Get the client
hd, err := client.NewHyperdriveClientFromCtx(c)
Expand All @@ -23,13 +30,15 @@ func registerNode(c *cli.Context) error {
}

// Check if the node's already registered
csRegResponse, err := cs.Api.Node.GetRegistrationStatus()
if err != nil {
return err
}
if csRegResponse.Data.Registered {
fmt.Println("Your node is already registered with Constellation.")
return nil
if !c.Bool(registerForceFlag.Name) {
csRegResponse, err := cs.Api.Node.GetRegistrationStatus()
if err != nil {
return err
}
if csRegResponse.Data.Registered {
fmt.Println("Your node is already registered with Constellation.")
return nil
}
}

// Check if the node's registered with NodeSet
Expand Down
4 changes: 2 additions & 2 deletions hyperdrive-cli/commands/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func configureService(c *cli.Context) error {
}

// Make sure the config directory exists first
err = os.MkdirAll(hd.Context.ConfigPath, 0700)
err = os.MkdirAll(hd.Context.UserDirPath, 0700)
if err != nil {
fmt.Printf("%sYour Hyperdrive user configuration directory of [%s] could not be created:%s.%s\n", terminal.ColorYellow, hd.Context.ConfigPath, err.Error(), terminal.ColorReset)
fmt.Printf("%sYour Hyperdrive user configuration directory of [%s] could not be created:%s.%s\n", terminal.ColorYellow, hd.Context.UserDirPath, err.Error(), terminal.ColorReset)
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions hyperdrive-cli/commands/service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func startService(c *cli.Context, ignoreConfigSuggestion bool) error {
}
}

// Generate the daemon API keys
err = hd.GenerateDaemonAuthKeys(cfg)
if err != nil {
return fmt.Errorf("error generating daemon API keys: %w", err)
}

// Validate the config
errors := cfg.Validate()
if len(errors) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion hyperdrive-cli/commands/service/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ func terminateService(c *cli.Context) error {
}

// Stop service
return hd.TerminateService(getComposeFiles(c), hd.Context.ConfigPath)
return hd.TerminateService(getComposeFiles(c), hd.Context.UserDirPath)
}
10 changes: 5 additions & 5 deletions hyperdrive-cli/hyperdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
Aliases: []string{"r"},
Usage: "Allow hyperdrive to be run as the root user",
}
configPathFlag *cli.StringFlag = &cli.StringFlag{
userDirPathFlag *cli.StringFlag = &cli.StringFlag{
Name: "config-path",
Aliases: []string{"c"},
Usage: "Directory to install and save all of Hyperdrive's configuration and data to",
Expand Down Expand Up @@ -114,7 +114,7 @@ func main() {
// Set application flags
app.Flags = []cli.Flag{
allowRootFlag,
configPathFlag,
userDirPathFlag,
apiAddressFlag,
maxFeeFlag,
maxPriorityFeeFlag,
Expand Down Expand Up @@ -179,14 +179,14 @@ func setDefaultPaths() {
}

// Default config folder path
defaultConfigPath := filepath.Join(homeDir, defaultConfigFolder)
configPathFlag.Value = defaultConfigPath
defaultUserDirPath := filepath.Join(homeDir, defaultConfigFolder)
userDirPathFlag.Value = defaultUserDirPath
}

// Validate the global flags
func validateFlags(c *cli.Context) (*context.HyperdriveContext, error) {
// Make sure the config directory exists
configPath := c.String(configPathFlag.Name)
configPath := c.String(userDirPathFlag.Name)
path, err := homedir.Expand(strings.TrimSpace(configPath))
if err != nil {
return nil, fmt.Errorf("error expanding config path [%s]: %w", configPath, err)
Expand Down
8 changes: 4 additions & 4 deletions hyperdrive-cli/utils/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const (
type HyperdriveContext struct {
*InstallationInfo

// The path to the configuration file
ConfigPath string
// The path to the Hyperdrive user directory
UserDirPath string

// The max fee for transactions
MaxFee float64
Expand Down Expand Up @@ -56,12 +56,12 @@ type HyperdriveContext struct {
}

// Creates a new Hyperdrive context. If installationInfo is nil, a new one will be created using the system configuration.
func NewHyperdriveContext(cfgPath string, installationInfo *InstallationInfo) *HyperdriveContext {
func NewHyperdriveContext(userDirPath string, installationInfo *InstallationInfo) *HyperdriveContext {
if installationInfo == nil {
installationInfo = NewInstallationInfo()
}
return &HyperdriveContext{
ConfigPath: cfgPath,
UserDirPath: userDirPath,
InstallationInfo: installationInfo,
}
}
Expand Down
Loading

0 comments on commit 511a16c

Please sign in to comment.