Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWTsecret to relative path #484

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Support Mainnet for Lido CSM setup.

### Changed
- JWT secret path set as relative path when not provided.

## [v1.6.0] - 2024-10-18


Expand Down
16 changes: 14 additions & 2 deletions cli/actions/jwt_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *sedgeActions) CreateJWTSecrets(options CreateJWTSecretOptions) (string,
jwtPath := options.JWTPath
if jwtPath == "" && !configs.NetworksConfigs()[options.Network].NoJWT {
return handleJWTSecret(options.GenerationPath)
} else if filepath.IsAbs(jwtPath) { // Ensure jwtPath is absolute
} else if filepath.IsAbs(jwtPath) { // ensure the path is absolute if provided
if jwtPath, err = filepath.Abs(jwtPath); err != nil {
return jwtPath, err
}
Expand Down Expand Up @@ -71,5 +71,17 @@ func handleJWTSecret(generationPath string) (string, error) {
}

log.Info(configs.JWTSecretGenerated)
return jwtPath, nil

// Convert the absolute path to a relative path
relativeJWTPath, err := filepath.Rel(generationPath, jwtPath)
if err != nil {
return "", fmt.Errorf(configs.GenerateJWTSecretError, err)
}

// Prepend "./" to ensure compatibility with relative paths
if !filepath.IsAbs(relativeJWTPath) && !filepath.HasPrefix(relativeJWTPath, ".") {
relativeJWTPath = "." + string(filepath.Separator) + relativeJWTPath
}

return relativeJWTPath, nil
}
6 changes: 5 additions & 1 deletion cli/actions/jwt_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func TestCreateJwtSecrets(t *testing.T) {
if jwtPath == "" {
return
}
assert.FileExists(t, jwtPath)
if tc.options.JWTPath == "" {
assert.FileExists(t, filepath.Join(tempDir, "jwtsecret"))
} else {
assert.FileExists(t, jwtPath)
}
})
}
}
40 changes: 32 additions & 8 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func TestCli(t *testing.T) {
name: "full node with validator mainnet",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"execution", "consensus", "validator", "mev-boost"},
ExecutionClient: &clients.Client{
Expand Down Expand Up @@ -95,7 +98,7 @@ func TestCli(t *testing.T) {
MevImage: "flashbots/mev-boost:latest",
RelayURLs: configs.NetworksConfigs()[NetworkMainnet].RelayURLs,
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}
sedgeActions.EXPECT().GetCommandRunner().Return(&test.SimpleCMDRunner{})
gomock.InOrder(
Expand Down Expand Up @@ -151,6 +154,9 @@ func TestCli(t *testing.T) {
name: "full node without validator mainnet",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"execution", "consensus"},
ExecutionClient: &clients.Client{
Expand All @@ -168,7 +174,7 @@ func TestCli(t *testing.T) {
FeeRecipient: "0x2d07a21ebadde0c13e6b91022a7e5722eb6bf5d5",
MapAllPorts: true,
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}
gomock.InOrder(
prompter.EXPECT().Select("Select node setup", "", []string{sedgeOpts.EthereumNode, sedgeOpts.LidoNode}).Return(0, nil),
Expand Down Expand Up @@ -196,6 +202,9 @@ func TestCli(t *testing.T) {
name: "full node without validator holesky",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"execution", "consensus"},
ExecutionClient: &clients.Client{
Expand All @@ -213,7 +222,7 @@ func TestCli(t *testing.T) {
FeeRecipient: "0x2d07a21ebadde0c13e6b91022a7e5722eb6bf5d5",
MapAllPorts: true,
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}
gomock.InOrder(
prompter.EXPECT().Select("Select node setup", "", []string{sedgeOpts.EthereumNode, sedgeOpts.LidoNode}).Return(0, nil),
Expand Down Expand Up @@ -331,6 +340,9 @@ func TestCli(t *testing.T) {
name: "consensus node",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"consensus"},
ConsensusClient: &clients.Client{
Expand All @@ -346,7 +358,7 @@ func TestCli(t *testing.T) {
ExecutionAuthUrl: "http://execution:5051",
MevBoostEndpoint: "http://mev-boost:3030",
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}

gomock.InOrder(
Expand Down Expand Up @@ -376,6 +388,9 @@ func TestCli(t *testing.T) {
name: "consensus node holesky",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"consensus"},
ConsensusClient: &clients.Client{
Expand All @@ -391,7 +406,7 @@ func TestCli(t *testing.T) {
ExecutionAuthUrl: "http://execution:5051",
MevBoostEndpoint: "http://mev-boost:3030",
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}

gomock.InOrder(
Expand Down Expand Up @@ -485,6 +500,9 @@ func TestCli(t *testing.T) {
name: "consensus node",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"consensus"},
ConsensusClient: &clients.Client{
Expand All @@ -500,7 +518,7 @@ func TestCli(t *testing.T) {
ExecutionAuthUrl: "http://execution:5051",
MevBoostEndpoint: "http://mev-boost:3030",
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}

gomock.InOrder(
Expand Down Expand Up @@ -530,6 +548,9 @@ func TestCli(t *testing.T) {
name: "full node with Lido, mainnet",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"execution", "consensus", "validator", "mev-boost"},
ExecutionClient: &clients.Client{
Expand Down Expand Up @@ -557,7 +578,7 @@ func TestCli(t *testing.T) {
MevImage: "flashbots/mev-boost:latest",
RelayURLs: mainnetMevboostRelayListUris,
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}
sedgeActions.EXPECT().GetCommandRunner().Return(&test.SimpleCMDRunner{})
gomock.InOrder(
Expand Down Expand Up @@ -609,6 +630,9 @@ func TestCli(t *testing.T) {
name: "full node with Lido, holesky",
setup: func(t *testing.T, sedgeActions *sedge_mocks.MockSedgeActions, prompter *sedge_mocks.MockPrompter, depsMgr *sedge_mocks.MockDependenciesManager) {
generationPath := t.TempDir()
jwtPathAbs, _ := filepath.Abs(filepath.Join(generationPath, "jwtsecret"))
jwtPath, _ := filepath.Rel(generationPath, jwtPathAbs)
relativeJWTPath := "." + string(filepath.Separator) + jwtPath
genData := generate.GenData{
Services: []string{"execution", "consensus", "validator", "mev-boost"},
ExecutionClient: &clients.Client{
Expand Down Expand Up @@ -636,7 +660,7 @@ func TestCli(t *testing.T) {
MevImage: "flashbots/mev-boost:latest",
RelayURLs: holeskyMevboostRelayListUris,
ContainerTag: "tag",
JWTSecretPath: filepath.Join(generationPath, "jwtsecret"),
JWTSecretPath: relativeJWTPath,
}
sedgeActions.EXPECT().GetCommandRunner().Return(&test.SimpleCMDRunner{})
gomock.InOrder(
Expand Down
14 changes: 13 additions & 1 deletion cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,19 @@ func handleJWTSecret(generationPath, name string) (string, error) {
}

log.Info(configs.JWTSecretGenerated)
return jwtPath, nil

// Convert the absolute path to a relative path
relativeJWTPath, err := filepath.Rel(generationPath, jwtPath)
if err != nil {
return "", fmt.Errorf(configs.GenerateJWTSecretError, err)
}

// Prepend "./" to ensure compatibility with relative paths
if !filepath.IsAbs(relativeJWTPath) && !filepath.HasPrefix(relativeJWTPath, ".") {
relativeJWTPath = "." + string(filepath.Separator) + relativeJWTPath
}

return relativeJWTPath, nil
}

// TODO: Add unit tests
Expand Down