Skip to content

Commit

Permalink
feat: add enclave's flags info in the kurtosis enclave inspect CLI …
Browse files Browse the repository at this point in the history
…command (#1751)

## Description:
add enclave's flags info in the `kurtosis enclave inspect` CLI command

## Is this change user facing?
YES

## References (if applicable):
Fix #1363
  • Loading branch information
leoporoli committed Nov 13, 2023
1 parent 2a26416 commit 35bad59
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
48 changes: 35 additions & 13 deletions cli/cli/commands/enclave/inspect/inspect.go
Expand Up @@ -37,6 +37,7 @@ const (
enclaveNameTitleName = "Name"
enclaveStatusTitleName = "Status"
enclaveCreationTimeTitleName = "Creation Time"
flagsTitleName = "Flags"

fullUuidsFlagKey = "full-uuids"
fullUuidFlagKeyDefault = "false"
Expand All @@ -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{
Expand Down Expand Up @@ -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("")
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion cli/cli/commands/import/import.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/cli/commands/run/run.go
Expand Up @@ -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)
}
}()
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/cli-reference/enclave-inspect.md
Expand Up @@ -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

Expand Down

0 comments on commit 35bad59

Please sign in to comment.