@@ -2,6 +2,7 @@ package machine
22
33import (
44 "context"
5+ "encoding/base64"
56 "encoding/binary"
67 "encoding/json"
78 "fmt"
@@ -132,9 +133,7 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) {
132133
133134 if len (out .Machine .Metadata ) > 0 {
134135 fmt .Printf ("Metadata:\n " )
135- for key , value := range out .Machine .Metadata {
136- fmt .Printf (" %s: %s\n " , key , value )
137- }
136+ prettyPrintMachineMetadata (out .Machine .Metadata , " " , " " )
138137 }
139138
140139 fmt .Printf ("Resources:\n " )
@@ -169,9 +168,7 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) {
169168
170169 if len (out .Machine .Deployment .Metadata ) > 0 {
171170 fmt .Printf (" Metadata:\n " )
172- for key , value := range out .Machine .Deployment .Metadata {
173- fmt .Printf (" %s: %s\n " , key , value )
174- }
171+ prettyPrintMachineMetadata (out .Machine .Deployment .Metadata , " " , " " )
175172 }
176173 case nil :
177174 fmt .Printf ("Deployment: <no current deployment>\n " )
@@ -239,6 +236,37 @@ func prettyPrintMachinePorts(extraCfg *roflCmdBuild.AppExtraConfig, appID rofl.A
239236 }
240237}
241238
239+ func prettyPrintMachineMetadata (metadata map [string ]string , prefix , indent string ) {
240+ fallBackPrint := func (key , value , prefix string ) {
241+ fmt .Printf ("%s%s: %s\n " , prefix , key , value )
242+ }
243+
244+ for key , value := range metadata {
245+ switch key {
246+ case scheduler .MetadataKeyPermissions :
247+ // Try to decode value as base64 CBOR value.
248+ cborValue , err := base64 .StdEncoding .DecodeString (value )
249+ if err != nil {
250+ fallBackPrint (key , value , prefix )
251+ }
252+
253+ var permissions map [string ][]types.Address
254+ if err = cbor .Unmarshal (cborValue , & permissions ); err != nil {
255+ fallBackPrint (key , value , prefix )
256+ }
257+ fmt .Printf ("%s%s:\n " , prefix , key )
258+ for p , addresses := range permissions {
259+ fmt .Printf ("%s%s:\n " , prefix + indent , p )
260+ for _ , a := range addresses {
261+ fmt .Printf ("%s- %s\n " , prefix + indent + indent , a )
262+ }
263+ }
264+ default :
265+ fallBackPrint (key , value , prefix )
266+ }
267+ }
268+ }
269+
242270func init () {
243271 common .AddSelectorFlags (showCmd )
244272 showCmd .Flags ().AddFlagSet (common .FormatFlag )
0 commit comments