Skip to content
Open
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
47 changes: 41 additions & 6 deletions cmd/rofl/machine/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package machine

import (
"context"
"encoding/base64"
"encoding/binary"
"encoding/json"
"fmt"
"net"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -132,9 +134,7 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) {

if len(out.Machine.Metadata) > 0 {
fmt.Printf("Metadata:\n")
for key, value := range out.Machine.Metadata {
fmt.Printf(" %s: %s\n", key, value)
}
prettyPrintMachineMetadata(out.Machine.Metadata, " ", " ")
}

fmt.Printf("Resources:\n")
Expand Down Expand Up @@ -169,9 +169,7 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) {

if len(out.Machine.Deployment.Metadata) > 0 {
fmt.Printf(" Metadata:\n")
for key, value := range out.Machine.Deployment.Metadata {
fmt.Printf(" %s: %s\n", key, value)
}
prettyPrintMachineMetadata(out.Machine.Deployment.Metadata, " ", " ")
}
case nil:
fmt.Printf("Deployment: <no current deployment>\n")
Expand Down Expand Up @@ -239,6 +237,43 @@ func prettyPrintMachinePorts(extraCfg *roflCmdBuild.AppExtraConfig, appID rofl.A
}
}

func prettyPrintMachineMetadata(metadata map[string]string, prefix, indent string) {
fallBackPrint := func(key, value, prefix string) {
fmt.Printf("%s%s: %s\n", prefix, key, value)
}

// Sort metadata keys for consistent output.
keys := make([]string, 0, len(metadata))
for key := range metadata {
keys = append(keys, key)
}
sort.Strings(keys)

for _, key := range keys {
value := metadata[key]
switch key {
case scheduler.MetadataKeyPermissions:
cborValue, err := base64.StdEncoding.DecodeString(value)
if err != nil {
fallBackPrint(key, value, prefix)
}
var permissions map[string][]types.Address
if err = cbor.Unmarshal(cborValue, &permissions); err != nil {
fallBackPrint(key, value, prefix)
}
fmt.Printf("%s%s:\n", prefix, key)
for p, addresses := range permissions {
fmt.Printf("%s%s:\n", prefix+indent, p)
for _, a := range addresses {
fmt.Printf("%s- %s\n", prefix+indent+indent, common.PrettyAddress(a.String()))
}
}
default:
fallBackPrint(key, value, prefix)
}
}
}

func init() {
common.AddSelectorFlags(showCmd)
showCmd.Flags().AddFlagSet(common.FormatFlag)
Expand Down
2 changes: 2 additions & 0 deletions docs/rofl.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ offer:
- `--term <hour|month|year>` specifies the base rent period. It takes the first
available provider term by default.
- `--term-count <number>` specifies the multiplier. Default is `1`.
- `--replace-machine` if the existing machine in the manifest file expired,
rent a new machine and replace the existing machine ID.

![code shell](../examples/rofl/deploy.in.static)

Expand Down
Loading