From 848b85ef8168cfc4dcf433ce7b3e6690e15cedd3 Mon Sep 17 00:00:00 2001 From: Leandro Poroli Date: Fri, 10 Nov 2023 16:38:37 -0300 Subject: [PATCH 1/2] implementation --- cli/cli/commands/enclave/inspect/inspect.go | 48 +++++++++++++++------ cli/cli/commands/import/import.go | 2 +- cli/cli/commands/run/run.go | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/cli/cli/commands/enclave/inspect/inspect.go b/cli/cli/commands/enclave/inspect/inspect.go index a3416556c2..4d0587f1e2 100644 --- a/cli/cli/commands/enclave/inspect/inspect.go +++ b/cli/cli/commands/enclave/inspect/inspect.go @@ -37,6 +37,7 @@ const ( enclaveNameTitleName = "Name" enclaveStatusTitleName = "Status" enclaveCreationTimeTitleName = "Creation Time" + flagsTitleName = "Flags" fullUuidsFlagKey = "full-uuids" fullUuidFlagKeyDefault = "false" @@ -49,6 +50,8 @@ const ( userServicesArtifactsHeader = "User Services" filesArtifactsHeader = "Files Artifacts" + + productionEnclaveFlagStr = "production" ) var enclaveObjectPrintingFuncs = map[string]func(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext, enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo, showFullUuid bool, isAPIContainerRunning bool) error{ @@ -104,47 +107,52 @@ func run( return stacktrace.Propagate(err, "An error occurred creating Kurtosis Context from local engine") } - if err = PrintEnclaveInspect(ctx, kurtosisBackend, kurtosisCtx, enclaveIdentifier, showFullUuids); err != nil { + if err = PrintEnclaveInspect(ctx, kurtosisCtx, enclaveIdentifier, showFullUuids); err != nil { // this is already wrapped up return err } return nil } -func PrintEnclaveInspect(ctx context.Context, kurtosisBackend backend_interface.KurtosisBackend, kurtosisCtx *kurtosis_context.KurtosisContext, enclaveIdentifier string, showFullUuids bool) error { +func PrintEnclaveInspect(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext, enclaveIdentifier string, showFullUuids bool) error { enclaveInfo, err := kurtosisCtx.GetEnclave(ctx, enclaveIdentifier) if err != nil { return stacktrace.Propagate(err, "An error occurred getting the enclave for identifier '%v'", enclaveIdentifier) } - enclaveContainersStatus := enclaveInfo.ContainersStatus - enclaveApiContainerStatus := enclaveInfo.ApiContainerStatus - keyValuePrinter := output_printers.NewKeyValuePrinter() + + // Add title row keyValuePrinter.AddPair(enclaveNameTitleName, enclaveInfo.GetName()) + // Add UUID row if showFullUuids { keyValuePrinter.AddPair(enclaveUUIDTitleName, enclaveInfo.GetEnclaveUuid()) } else { keyValuePrinter.AddPair(enclaveUUIDTitleName, enclaveInfo.GetShortenedUuid()) } - enclaveContainersStatusStr, err := enclave_status_stringifier.EnclaveContainersStatusStringifier(enclaveContainersStatus) + // Add status row + enclaveContainersStatusStr, err := enclave_status_stringifier.EnclaveContainersStatusStringifier(enclaveInfo.GetContainersStatus()) if err != nil { return stacktrace.Propagate(err, "An error occurred when stringify enclave containers status") } keyValuePrinter.AddPair(enclaveStatusTitleName, enclaveContainersStatusStr) + // Add creation time row enclaveCreationTime := enclaveInfo.GetCreationTime() - //TODO remove this condition after 2023-01-01 when we are sure that there is not any old enclave created without the creation time label - //TODO and add a fail loudly check - if enclaveCreationTime != nil { - enclaveCreationTimeStr := enclaveCreationTime.AsTime().Local().Format(time.RFC1123) - - keyValuePrinter.AddPair(enclaveCreationTimeTitleName, enclaveCreationTimeStr) + if enclaveCreationTime == nil { + return stacktrace.Propagate(err, "Expected to get the enclave creation time from the enclave info received but it was not received, this is a bug in Kurtosis") } + enclaveCreationTimeStr := enclaveCreationTime.AsTime().Local().Format(time.RFC1123) + keyValuePrinter.AddPair(enclaveCreationTimeTitleName, enclaveCreationTimeStr) + + // Add flags row + allEnclaveFlagsStr := getAllEnclaveFlagsStr(enclaveInfo) + + keyValuePrinter.AddPair(flagsTitleName, allEnclaveFlagsStr) - isApiContainerRunning := enclaveApiContainerStatus == kurtosis_engine_rpc_api_bindings.EnclaveAPIContainerStatus_EnclaveAPIContainerStatus_RUNNING + isApiContainerRunning := enclaveInfo.GetApiContainerStatus() == kurtosis_engine_rpc_api_bindings.EnclaveAPIContainerStatus_EnclaveAPIContainerStatus_RUNNING keyValuePrinter.Print() out.PrintOutLn("") @@ -188,3 +196,17 @@ func PrintEnclaveInspect(ctx context.Context, kurtosisBackend backend_interface. return nil } + +func getAllEnclaveFlagsStr(enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo) string { + allEnclaveFragsStr := "" + + // we only one enclave flag added so far, but we could have more in the future, so we should add them here + // and return all of them together in just one string + currentModeStr := strings.ToLower(enclaveInfo.GetMode().String()) + + if currentModeStr == productionEnclaveFlagStr { + allEnclaveFragsStr = currentModeStr + } + + return allEnclaveFragsStr +} diff --git a/cli/cli/commands/import/import.go b/cli/cli/commands/import/import.go index 5a10422ce6..42add2faff 100644 --- a/cli/cli/commands/import/import.go +++ b/cli/cli/commands/import/import.go @@ -167,7 +167,7 @@ func run( if err != nil { return stacktrace.Propagate(err, "Failed to run generated starlark from compose") } - if err = inspect.PrintEnclaveInspect(ctx, kurtosisBackend, kurtosisCtx, enclaveCtx.GetEnclaveName(), doNotShowFullUuids); err != nil { + if err = inspect.PrintEnclaveInspect(ctx, kurtosisCtx, enclaveCtx.GetEnclaveName(), doNotShowFullUuids); err != nil { logrus.Errorf("An error occurred while printing enclave status and contents:\n%s", err) } return nil diff --git a/cli/cli/commands/run/run.go b/cli/cli/commands/run/run.go index 370777a2c0..023d20082f 100644 --- a/cli/cli/commands/run/run.go +++ b/cli/cli/commands/run/run.go @@ -341,7 +341,7 @@ func run( if showEnclaveInspect { defer func() { - if err = inspect.PrintEnclaveInspect(ctx, kurtosisBackend, kurtosisCtx, enclaveCtx.GetEnclaveName(), showFullUuids); err != nil { + if err = inspect.PrintEnclaveInspect(ctx, kurtosisCtx, enclaveCtx.GetEnclaveName(), showFullUuids); err != nil { logrus.Errorf("An error occurred while printing enclave status and contents:\n%s", err) } }() From 738b3219b4326fe6882a896a5072c9ce523eca49 Mon Sep 17 00:00:00 2001 From: Leandro Poroli Date: Fri, 10 Nov 2023 17:44:12 -0300 Subject: [PATCH 2/2] docs added --- docs/docs/cli-reference/enclave-inspect.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/cli-reference/enclave-inspect.md b/docs/docs/cli-reference/enclave-inspect.md index 1ed55d3465..f14931f13d 100644 --- a/docs/docs/cli-reference/enclave-inspect.md +++ b/docs/docs/cli-reference/enclave-inspect.md @@ -14,7 +14,11 @@ where `$THE_ENCLAVE_IDENTIFIER` is the [resource identifier](../advanced-concept Running the above command will print detailed information about: +- The enclave's name +- The enclave's UUID (you can see the full UUID by using the --full-uuids flag in this command) - The enclave's status (running or stopped) +- The enclave's creation time +- The enclave's flags used (e.g: the production flag) - The services inside the enclave (if any), their status, and the information for accessing those services' ports from your local machine - Any files artifacts registered within the specified enclave