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

fix: fix issue invalid explorer url open when run dive on kurtosis cloud #353

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 12 additions & 4 deletions cli/cmd/chains/kusama/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,18 @@ func startExplorer(cli *common.Cli, enclaveCtx *enclaves.EnclaveContext, finalRe
cli.Logger().Info("Explorer service is already running.")
}

url := updatePort(polkadotJUrl, "127.0.0.1", extractPort(publicEndpoint))
cli.Logger().Info("Redirecting to Polkadote explorer UI...")
if err := common.OpenFile(url); err != nil {
cli.Logger().Fatalf(common.CodeOf(err), "Failed to open HugoByte Polkadot explorer UI with error %v", err)
isLocalContext, err := cli.Context().IsLocalKurtosisContext()

if err != nil {
return nil, err
}

if isLocalContext {
url := updatePort(polkadotJUrl, "127.0.0.1", extractPort(publicEndpoint))
cli.Logger().Info("Redirecting to Polkadote explorer UI...")
if err := common.OpenFile(url); err != nil {
cli.Logger().Fatalf(common.CodeOf(err), "Failed to open HugoByte Polkadot explorer UI with error %v", err)
}
}

return explorerResponseData, nil
Expand Down
17 changes: 12 additions & 5 deletions cli/cmd/chains/polkadot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
)

func RunPolkadot(cli *common.Cli) (*common.DiveMultipleServiceResponse, error) {

enclaveContext, err := cli.Context().GetEnclaveContext(common.EnclaveName)
if err != nil {
return nil, common.WrapMessageToError(err, "Failed to retrieve the enclave context for Polkadot.")
Expand Down Expand Up @@ -386,10 +385,18 @@ func startExplorer(cli *common.Cli, enclaveCtx *enclaves.EnclaveContext, finalRe
cli.Logger().Info("Explorer service is already running.")
}

url := updatePort(polkadotJUrl, "127.0.0.1", extractPort(publicEndpoint))
cli.Logger().Info("Redirecting to Polkadote explorer UI...")
if err := common.OpenFile(url); err != nil {
cli.Logger().Fatalf(common.CodeOf(err), "Failed to open HugoByte Polkadot explorer UI with error %v", err)
isLocalContext, err := cli.Context().IsLocalKurtosisContext()

if err != nil {
return nil, err
}

if isLocalContext {
url := updatePort(polkadotJUrl, "127.0.0.1", extractPort(publicEndpoint))
cli.Logger().Info("Redirecting to Polkadote explorer UI...")
if err := common.OpenFile(url); err != nil {
cli.Logger().Fatalf(common.CodeOf(err), "Failed to open HugoByte Polkadot explorer UI with error %v", err)
}
}

return explorerResponseData, nil
Expand Down
40 changes: 38 additions & 2 deletions cli/common/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"sync"

"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
"github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/services"
"github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context"
contexts_config_api "github.com/kurtosis-tech/kurtosis/contexts-config-store/api/golang"
contexts_config_generated_api "github.com/kurtosis-tech/kurtosis/contexts-config-store/api/golang/generated"
"github.com/kurtosis-tech/kurtosis/contexts-config-store/store"
)

type diveContext struct {
Expand Down Expand Up @@ -86,6 +89,39 @@ func (dc *diveContext) GetEnclaveContext(enclaveName string) (*enclaves.EnclaveC

}

func (dc *diveContext) IsLocalKurtosisContext() (bool, error) {
var isLocalContext bool
contextsConfigStore := store.GetContextsConfigStore()
currentContextsConfig, err := contextsConfigStore.GetKurtosisContextsConfig()

if err != nil {
return false, WrapMessageToError(err, "Failed to get kurtosis context config.")
}

currentContextUuid := currentContextsConfig.GetCurrentContextUuid()
for _, kurtosisContext := range currentContextsConfig.GetContexts() {
if kurtosisContext.GetUuid().GetValue() == currentContextUuid.GetValue() {
contextVisitorForRemoteString := contexts_config_api.KurtosisContextVisitor[struct{}]{
VisitLocalOnlyContextV0: func(localContext *contexts_config_generated_api.LocalOnlyContextV0) (*struct{}, error) {
isLocalContext = true
return nil, nil
},
VisitRemoteContextV0: func(remoteContext *contexts_config_generated_api.RemoteContextV0) (*struct{}, error) {
isLocalContext = false
return nil, nil
},
}

_, err := contexts_config_api.Visit[struct{}](kurtosisContext, contextVisitorForRemoteString)
if err != nil {
return false, WrapMessageToError(err, "Failed to run visitor, The visitor function could not be executed.")
}
}
}

return isLocalContext, nil
}

func (dc *diveContext) GetAllEnlavesServices() (map[string]map[services.ServiceName]services.ServiceUUID, error) {
enclaves, err := dc.GetEnclaves()

Expand Down Expand Up @@ -336,7 +372,7 @@ func (dc *diveContext) GetShortUuid(enclaveName string) (string, error) {
shortUuid = enclave.ShortUuid
}
}

return shortUuid, nil
}

3 changes: 3 additions & 0 deletions cli/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type Context interface {
// GetEnclaveContext retrieves the context of a specific enclave by its name.
GetEnclaveContext(enclaveName string) (*enclaves.EnclaveContext, error)

// IsLocalKurtosisContext checks whether current running kurtosis context is local.
IsLocalKurtosisContext() (bool, error)

// CleanEnclaves stops and cleans up all running enclaves.
CleanEnclaves() ([]*EnclaveInfo, error)

Expand Down
Loading