|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/deislabs/duffle/pkg/action" |
| 5 | + "github.com/deislabs/duffle/pkg/claim" |
| 6 | + "github.com/deislabs/duffle/pkg/credentials" |
| 7 | + "github.com/deislabs/duffle/pkg/utils/crud" |
| 8 | + "github.com/docker/cli/cli" |
| 9 | + "github.com/docker/cli/cli/command" |
| 10 | + "github.com/spf13/cobra" |
| 11 | +) |
| 12 | + |
| 13 | +func statusCmd(dockerCli command.Cli) *cobra.Command { |
| 14 | + var opts uninstallOptions |
| 15 | + |
| 16 | + cmd := &cobra.Command{ |
| 17 | + Use: "status <installation-name>", |
| 18 | + Short: "Get an application status", |
| 19 | + Args: cli.ExactArgs(1), |
| 20 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 21 | + return runStatus(dockerCli, args[0], opts) |
| 22 | + }, |
| 23 | + } |
| 24 | + |
| 25 | + cmd.Flags().StringVar(&opts.targetContext, "target-context", "", "Context on which to request the application status") |
| 26 | + cmd.Flags().StringArrayVarP(&opts.credentialsets, "credential-set", "c", []string{}, "Use a duffle credentialset (either a YAML file, or a credential set present in the duffle credential store)") |
| 27 | + |
| 28 | + return cmd |
| 29 | +} |
| 30 | + |
| 31 | +func runStatus(dockerCli command.Cli, claimName string, opts uninstallOptions) error { |
| 32 | + muteDockerCli(dockerCli) |
| 33 | + h := duffleHome() |
| 34 | + |
| 35 | + claimStore := claim.NewClaimStore(crud.NewFileSystemStore(h.Claims(), "json")) |
| 36 | + c, err := claimStore.Read(claimName) |
| 37 | + if err != nil { |
| 38 | + return err |
| 39 | + } |
| 40 | + targetContext := getTargetContext(opts.targetContext) |
| 41 | + |
| 42 | + driverImpl, err := prepareDriver(dockerCli) |
| 43 | + if err != nil { |
| 44 | + return err |
| 45 | + } |
| 46 | + creds, err := prepareCredentialSet(targetContext, dockerCli.ContextStore(), c.Bundle, opts.credentialsets) |
| 47 | + if err != nil { |
| 48 | + return err |
| 49 | + } |
| 50 | + if err := credentials.Validate(creds, c.Bundle.Credentials); err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + status := &action.Status{ |
| 54 | + Driver: driverImpl, |
| 55 | + } |
| 56 | + return status.Run(&c, creds, dockerCli.Out()) |
| 57 | +} |
0 commit comments