Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Add bundle actions command
Browse files Browse the repository at this point in the history
Rebase from master and add all action fields

Remove unused home field from actions cmd

Remove unused skipValidation field in actions cmd
  • Loading branch information
radu-matei committed Mar 15, 2019
1 parent adcaa3a commit c8cd03e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/duffle/bundle.go
Expand Up @@ -23,6 +23,7 @@ func newBundleCmd(w io.Writer) *cobra.Command {
newBundleSignCmd(w),
newBundleVerifyCmd(w),
newBundleRemoveCmd(w),
newBundleActionsCmd(w),
)
return cmd
}
70 changes: 70 additions & 0 deletions cmd/duffle/bundle_actions.go
@@ -0,0 +1,70 @@
package main

import (
"errors"
"fmt"
"io"
"os"

"github.com/gosuri/uitable"
"github.com/spf13/cobra"
)

const bundleActionsDesc = ` Lists all actions available in a bundle`

type bundleActionsCmd struct {
out io.Writer
bundleFile string
insecure bool
}

func newBundleActionsCmd(w io.Writer) *cobra.Command {
a := &bundleActionsCmd{out: w}

cmd := &cobra.Command{
Use: "actions BUNDLE",
Short: bundleActionsDesc,
Long: bundleActionsDesc,
RunE: func(cmd *cobra.Command, args []string) error {

bundle, err := bundleFileOrArg1(args, a.bundleFile)
if err != nil {
return err
}
return a.run(bundle)
},
}

cmd.Flags().StringVarP(&a.bundleFile, "file", "f", "", "path to the bundle file to show actions for")
cmd.Flags().BoolVarP(&a.insecure, "insecure", "k", false, "Do not verify the bundle (INSECURE)")

return cmd
}

func (a *bundleActionsCmd) run(bundleFile string) error {

// Verify that file exists
if fi, err := os.Stat(bundleFile); err != nil {
return fmt.Errorf("cannot find bundle file to sign: %v", err)
} else if fi.IsDir() {
return errors.New("cannot sign a directory")
}

bun, err := loadBundle(bundleFile, a.insecure)
if err != nil {
return err
}

table := uitable.New()
table.MaxColWidth = 100
table.Wrap = true

table.AddRow("ACTION", "STATELESS", "MODIFIES", "DESCRIPTION")
for name, act := range bun.Actions {
table.AddRow(name, act.Stateless, act.Modifies, act.Description)
}

fmt.Fprintln(a.out, table)

return nil
}

0 comments on commit c8cd03e

Please sign in to comment.