-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add machine inspect command. redacts sensitive and hidden …
…fields and then dumps the machine config as json
- Loading branch information
1 parent
b2ae08d
commit 098a4b6
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package machine | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/loft-sh/devpod/cmd/flags" | ||
"github.com/loft-sh/devpod/pkg/config" | ||
"github.com/loft-sh/devpod/pkg/provider" | ||
"github.com/loft-sh/devpod/pkg/workspace" | ||
"github.com/loft-sh/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type InspectCmd struct { | ||
*flags.GlobalFlags | ||
} | ||
|
||
func NewInspectCmd(flags *flags.GlobalFlags) *cobra.Command { | ||
cmd := &InspectCmd{ | ||
GlobalFlags: flags, | ||
} | ||
stopCmd := &cobra.Command{ | ||
Use: "inspect", | ||
Short: "Inspects an existing machine", | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
return cmd.Run(context.Background(), args) | ||
}, | ||
} | ||
|
||
return stopCmd | ||
} | ||
|
||
func (cmd *InspectCmd) Run(ctx context.Context, args []string) error { | ||
devPodConfig, err := config.LoadConfig(cmd.Context, cmd.Provider) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
machineClient, err := workspace.GetMachine(devPodConfig, args, log.Default) | ||
if err != nil { | ||
return err | ||
} | ||
p, err := provider.LoadProviderConfig(devPodConfig.DefaultContext, machineClient.Provider()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
machineConfig := machineClient.MachineConfig() | ||
for k := range machineConfig.Provider.Options { | ||
optConfig := p.Options[k] | ||
if optConfig.Hidden { | ||
delete(machineConfig.Provider.Options, k) | ||
continue | ||
} | ||
|
||
if optConfig.Password { | ||
opt := machineConfig.Provider.Options[k] | ||
opt.Value = "********" | ||
} | ||
} | ||
|
||
out, err := json.MarshalIndent(machineConfig, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(out)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters