Skip to content

Commit

Permalink
Minor key updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jclapis committed Oct 2, 2024
1 parent ba2553b commit cf33d09
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 39 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ 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.20241002073727-0d956e28557d
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002073218-07357eb81ca4
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002074720-5fa69604ea9f
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
Expand Down
12 changes: 6 additions & 6 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.20241002073727-0d956e28557d h1:dCoRAdCOw7Ow/mnPupF+/klClG097TFfF9913AQG+dw=
github.com/nodeset-org/hyperdrive-constellation v1.0.0-b1.0.20241002073727-0d956e28557d/go.mod h1:0LcBrdrHkkAs3m7bFRIg9Fb5HbBJazJE3lvgy+QbST8=
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002073218-07357eb81ca4 h1:sBdg5zBUwDtjNYfmx8PxvvFWiSKsQSiBKN9ZsJZWib0=
github.com/nodeset-org/hyperdrive-daemon v1.1.0-b1.0.20241002073218-07357eb81ca4/go.mod h1:VXYiN0ZrXbeNALJLa0sin4AzlSrFuGH8gW1YSywoVoI=
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002074720-5fa69604ea9f h1:OCJ9aniDFD5vR1Y6kcZZo4HzORNbISfjPF5QslyRY3Y=
github.com/nodeset-org/hyperdrive-stakewise v1.1.0-b1.0.20241002074720-5fa69604ea9f/go.mod h1:hGpWV7iJwpJg/8pbQnv3t6oGWoMZBHyeY24btNDP324=
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
20 changes: 1 addition & 19 deletions hyperdrive-cli/client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,15 @@ var (

// Create the metrics and modules folders, and deploy the config templates for Prometheus and Grafana
func (c *HyperdriveClient) GenerateDaemonAuthKeys(config *GlobalConfig) error {
// Make sure the secrets path exists
secretsDirPath := filepath.Join(c.Context.UserDirPath, hdconfig.SecretsDir)
modulesDirPath := filepath.Join(secretsDirPath, hdconfig.ModulesName)
err := os.MkdirAll(modulesDirPath, authDirMode)
if err != nil {
return fmt.Errorf("error creating secrets and modules directories [%s]: %w", modulesDirPath, err)
}

// Create the API key for the Hyperdrive daemon
hdApiKeyPath := filepath.Join(c.Context.UserDirPath, hdApiKeyRelPath)
err = auth.GenerateAuthKeyIfNotPresent(hdApiKeyPath, auth.DefaultKeyLength)
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 {
swDirPath := filepath.Join(modulesDirPath, swconfig.ModuleName)
err := os.MkdirAll(swDirPath, authDirMode)
if err != nil {
return fmt.Errorf("error creating StakeWise API key module directory [%s]: %w", swDirPath, err)
}
swApiKeyPath := filepath.Join(c.Context.UserDirPath, swApiKeyRelPath)
err = auth.GenerateAuthKeyIfNotPresent(swApiKeyPath, auth.DefaultKeyLength)
if err != nil {
Expand All @@ -54,11 +41,6 @@ func (c *HyperdriveClient) GenerateDaemonAuthKeys(config *GlobalConfig) error {

// Create the API key for the Constellation module if enabled
if config.Constellation.Enabled.Value {
csDirPath := filepath.Join(modulesDirPath, csconfig.ModuleName)
err := os.MkdirAll(csDirPath, authDirMode)
if err != nil {
return fmt.Errorf("error creating Constellation API key module directory [%s]: %w", csDirPath, err)
}
csApiKeyPath := filepath.Join(c.Context.UserDirPath, csApiKeyRelPath)
err = auth.GenerateAuthKeyIfNotPresent(csApiKeyPath, auth.DefaultKeyLength)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions hyperdrive-cli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,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 @@ -104,7 +106,7 @@ func NewHyperdriveClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext) (*Hy

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

// Create the API client
hdClient.Api = client.NewApiClient(url, logger, tracer, authMgr)
Expand Down Expand Up @@ -158,7 +160,7 @@ func NewStakewiseClientFromHyperdriveCtx(hdCtx *context.HyperdriveContext, hdCli

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

// Create the API client
swClient.Api = swclient.NewApiClient(url, logger, tracer, authMgr)
Expand Down Expand Up @@ -206,7 +208,7 @@ func NewConstellationClientFromCtx(c *cli.Context, hdClient *HyperdriveClient) (

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

// Create the API client
csClient.Api = csclient.NewApiClient(url, logger, tracer, authMgr)
Expand Down
4 changes: 2 additions & 2 deletions install/deploy/templates/modules/constellation/cs_daemon.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ services:
- --port
- "{{.Constellation.ApiPort}}"
- --api-key
- "{{.Hyperdrive.GetUserDirectory}}//{{.ConstellationApiKeyPath}}"
- "{{.Hyperdrive.GetUserDirectory}}/{{.ConstellationApiKeyPath}}"
- --hd-api-key
- "{{.Hyperdrive.GetUserDirectory}}//{{.HyperdriveApiKeyPath}}"
- "{{.Hyperdrive.GetUserDirectory}}/{{.HyperdriveApiKeyPath}}"
networks:
- net
{{- range $network := .Hyperdrive.GetAdditionalDockerNetworks}}
Expand Down
4 changes: 2 additions & 2 deletions install/deploy/templates/modules/stakewise/sw_daemon.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ services:
- --port
- "{{.StakeWise.ApiPort}}"
- --api-key
- "{{.Hyperdrive.GetUserDirectory}}//{{.StakeWiseApiKeyPath}}"
- "{{.Hyperdrive.GetUserDirectory}}/{{.StakeWiseApiKeyPath}}"
- --hd-api-key
- "{{.Hyperdrive.GetUserDirectory}}//{{.HyperdriveApiKeyPath}}"
- "{{.Hyperdrive.GetUserDirectory}}/{{.HyperdriveApiKeyPath}}"
networks:
- net
{{- range $network := .Hyperdrive.GetAdditionalDockerNetworks}}
Expand Down
11 changes: 7 additions & 4 deletions internal/tests/cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func TestNewConfig_Holesky(t *testing.T) {
hdSp, err := hdcommon.NewHyperdriveServiceProvider(hdCtx.UserDirPath, hdCtx.NetworksDir)
require.NoError(t, err)
hdWg := &sync.WaitGroup{}
authMgr := auth.NewAuthorizationManager("")
authMgr.SetKey([]byte(hdTestApiKey))
hdServer, err := hdserver.NewServerManager(hdSp, "localhost", 0, hdWg, authMgr)
serverAuthMgr := auth.NewAuthorizationManager("", "server", auth.DefaultRequestLifespan)
serverAuthMgr.SetKey([]byte(hdTestApiKey))
hdServer, err := hdserver.NewServerManager(hdSp, "localhost", 0, hdWg, serverAuthMgr)
require.NoError(t, err)
hdServerPort := hdServer.GetPort()
defer hdServer.Stop()
Expand All @@ -105,9 +105,12 @@ func TestNewConfig_Holesky(t *testing.T) {
require.NoError(t, err)
swSettings, err := hdclient.LoadStakeWiseSettings(hdCtx.NetworksDir)
require.NoError(t, err)

clientAuthMgr := auth.NewAuthorizationManager("", "client", auth.DefaultRequestLifespan)
clientAuthMgr.SetKey([]byte(hdTestApiKey))
modSp, err := modservices.NewModuleServiceProvider(hdApiUrl, swModDir, swconfig.ModuleName, swconfig.ClientLogName, func(hdCfg *hdconfig.HyperdriveConfig) (*swconfig.StakeWiseConfig, error) {
return swconfig.NewStakeWiseConfig(hdCfg, swSettings)
}, authMgr)
}, clientAuthMgr)
require.NoError(t, err)
swSp, err := swcommon.NewStakeWiseServiceProvider(modSp, swSettings)
require.NoError(t, err)
Expand Down

0 comments on commit cf33d09

Please sign in to comment.