diff --git a/cli/cmd/chains/kusama/run.go b/cli/cmd/chains/kusama/run.go index f9927374..c9187a49 100644 --- a/cli/cmd/chains/kusama/run.go +++ b/cli/cmd/chains/kusama/run.go @@ -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 diff --git a/cli/cmd/chains/polkadot/run.go b/cli/cmd/chains/polkadot/run.go index 46316c32..7846a691 100644 --- a/cli/cmd/chains/polkadot/run.go +++ b/cli/cmd/chains/polkadot/run.go @@ -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.") @@ -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 diff --git a/cli/common/context.go b/cli/common/context.go index fabba94f..aab38529 100644 --- a/cli/common/context.go +++ b/cli/common/context.go @@ -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 { @@ -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() @@ -336,7 +372,7 @@ func (dc *diveContext) GetShortUuid(enclaveName string) (string, error) { shortUuid = enclave.ShortUuid } } - + return shortUuid, nil } diff --git a/cli/common/interfaces.go b/cli/common/interfaces.go index 3350bfdc..2d784768 100644 --- a/cli/common/interfaces.go +++ b/cli/common/interfaces.go @@ -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)