@@ -2,10 +2,12 @@ package machine
22
33import (
44 "context"
5+ "encoding/base64"
56 "encoding/binary"
67 "encoding/json"
78 "fmt"
89 "net"
10+ "sort"
911 "strings"
1012 "time"
1113
@@ -132,9 +134,7 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) {
132134
133135 if len (out .Machine .Metadata ) > 0 {
134136 fmt .Printf ("Metadata:\n " )
135- for key , value := range out .Machine .Metadata {
136- fmt .Printf (" %s: %s\n " , key , value )
137- }
137+ prettyPrintMachineMetadata (out .Machine .Metadata , " " , " " )
138138 }
139139
140140 fmt .Printf ("Resources:\n " )
@@ -169,9 +169,7 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) {
169169
170170 if len (out .Machine .Deployment .Metadata ) > 0 {
171171 fmt .Printf (" Metadata:\n " )
172- for key , value := range out .Machine .Deployment .Metadata {
173- fmt .Printf (" %s: %s\n " , key , value )
174- }
172+ prettyPrintMachineMetadata (out .Machine .Deployment .Metadata , " " , " " )
175173 }
176174 case nil :
177175 fmt .Printf ("Deployment: <no current deployment>\n " )
@@ -239,6 +237,45 @@ func prettyPrintMachinePorts(extraCfg *roflCmdBuild.AppExtraConfig, appID rofl.A
239237 }
240238}
241239
240+ func prettyPrintMachineMetadata (metadata map [string ]string , prefix , indent string ) {
241+ fallBackPrint := func (key , value , prefix string ) {
242+ fmt .Printf ("%s%s: %s\n " , prefix , key , value )
243+ }
244+
245+ // Sort metadata keys for consistent output.
246+ keys := make ([]string , 0 , len (metadata ))
247+ for key := range metadata {
248+ keys = append (keys , key )
249+ }
250+ sort .Strings (keys )
251+
252+ for _ , key := range keys {
253+ value := metadata [key ]
254+ switch key {
255+ case scheduler .MetadataKeyPermissions :
256+ cborValue , err := base64 .StdEncoding .DecodeString (value )
257+ if err != nil {
258+ fallBackPrint (key , value , prefix )
259+ continue
260+ }
261+ var permissions map [string ][]types.Address
262+ if err = cbor .Unmarshal (cborValue , & permissions ); err != nil {
263+ fallBackPrint (key , value , prefix )
264+ continue
265+ }
266+ fmt .Printf ("%s%s:\n " , prefix , key )
267+ for p , addresses := range permissions {
268+ fmt .Printf ("%s%s:\n " , prefix + indent , p )
269+ for _ , a := range addresses {
270+ fmt .Printf ("%s- %s\n " , prefix + indent + indent , common .PrettyAddress (a .String ()))
271+ }
272+ }
273+ default :
274+ fallBackPrint (key , value , prefix )
275+ }
276+ }
277+ }
278+
242279func init () {
243280 common .AddSelectorFlags (showCmd )
244281 showCmd .Flags ().AddFlagSet (common .FormatFlag )
0 commit comments