github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/images/targets/contract.go (about) 1 package targets 2 3 import ( 4 "github.com/Sirupsen/logrus" 5 "github.com/daticahealth/cli/commands/environments" 6 "github.com/daticahealth/cli/config" 7 "github.com/daticahealth/cli/lib/auth" 8 "github.com/daticahealth/cli/lib/images" 9 "github.com/daticahealth/cli/lib/prompts" 10 "github.com/daticahealth/cli/models" 11 "github.com/jault3/mow.cli" 12 ) 13 14 // Cmd is the contract between the user and the CLI. This specifies the command 15 // name, arguments, and required/optional arguments and flags for the command. 16 var Cmd = models.Command{ 17 Name: "targets", 18 ShortHelp: "Operations for working with signed targets", 19 LongHelp: "<code>targets</code> allows interactions with content verified targets in a repository. " + 20 "This command cannot be run directly, but has subcommands.", 21 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 22 return func(cmd *cli.Cmd) { 23 cmd.CommandLong(listCmd.Name, listCmd.ShortHelp, listCmd.LongHelp, listCmd.CmdFunc(settings)) 24 cmd.CommandLong(deleteCmd.Name, deleteCmd.ShortHelp, deleteCmd.LongHelp, deleteCmd.CmdFunc(settings)) 25 cmd.CommandLong(statusCmd.Name, statusCmd.ShortHelp, statusCmd.LongHelp, statusCmd.CmdFunc(settings)) 26 cmd.CommandLong(resetCmd.Name, resetCmd.ShortHelp, resetCmd.LongHelp, resetCmd.CmdFunc(settings)) 27 } 28 }, 29 } 30 31 var listCmd = models.Command{ 32 Name: "list", 33 ShortHelp: "List signed targets for an image", 34 LongHelp: "<code>images targets list</code> lists signed targets for an image. " + 35 "To search for a specific target, specify a tag with the image name in the format \"image:tag\" Here is a sample command:\n\n" + 36 "<pre>\ndatica -E \"<your_env_name>\" images targets list <image>\n</pre>", 37 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 38 return func(cmd *cli.Cmd) { 39 image := cmd.StringArg("IMAGE_NAME", "", "The name of the image to list targets for. (e.g. 'my-image')") 40 cmd.Action = func() { 41 user, err := auth.New(settings, prompts.New()).Signin() 42 if err != nil { 43 logrus.Fatal(err.Error()) 44 } 45 if err = config.CheckRequiredAssociation(settings); err != nil { 46 logrus.Fatal(err.Error()) 47 } 48 if err = cmdTargetsList(settings.EnvironmentID, *image, user, environments.New(settings), images.New(settings)); err != nil { 49 logrus.Fatalln(err.Error()) 50 } 51 } 52 } 53 }, 54 } 55 56 var deleteCmd = models.Command{ 57 Name: "rm", 58 ShortHelp: "Delete a signed target for a given image", 59 LongHelp: "<code>images targets rm</code> deletes a signed target for a given image. " + 60 "You environment namespace will be filled in for you if not provided. Here is a sample command:\n\n" + 61 "<pre>\ndatica -E \"<your_env_name>\" images targets rm <image>:<tag>\n</pre>", 62 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 63 return func(cmd *cli.Cmd) { 64 image := cmd.StringArg("TAGGED_IMAGE", "", "The name and tag of the image to delete targets from. (e.g. 'my-image:tag')") 65 cmd.Action = func() { 66 user, err := auth.New(settings, prompts.New()).Signin() 67 if err != nil { 68 logrus.Fatal(err.Error()) 69 } 70 if err := config.CheckRequiredAssociation(settings); err != nil { 71 logrus.Fatal(err.Error()) 72 } 73 if err := cmdTargetsDelete(settings.EnvironmentID, *image, user, environments.New(settings), images.New(settings), prompts.New()); err != nil { 74 logrus.Fatalln(err.Error()) 75 } 76 } 77 } 78 }, 79 } 80 81 var statusCmd = models.Command{ 82 Name: "status", 83 ShortHelp: "List local unpublished changes to the trust repository for an image", 84 LongHelp: "<code>images targets status</code> lists unpublished changes to a local trust repository. " + 85 "To search for changes to a specific target, specify a tag with the image name in the format \"image:tag\". Here is a sample command:\n\n" + 86 "<pre>\ndatica -E \"<your_env_name>\" images targets status <image>\n</pre>", 87 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 88 return func(cmd *cli.Cmd) { 89 image := cmd.StringArg("IMAGE_NAME", "", "The name of the image to list unpublished changes for. (e.g. 'my-image')") 90 cmd.Action = func() { 91 user, err := auth.New(settings, prompts.New()).Signin() 92 if err != nil { 93 logrus.Fatal(err.Error()) 94 } 95 if err = config.CheckRequiredAssociation(settings); err != nil { 96 logrus.Fatal(err.Error()) 97 } 98 if err = cmdTargetsStatus(settings.EnvironmentID, *image, user, environments.New(settings), images.New(settings)); err != nil { 99 logrus.Fatalln(err.Error()) 100 } 101 } 102 } 103 }, 104 } 105 106 var resetCmd = models.Command{ 107 Name: "reset", 108 ShortHelp: "Clear unpublished changes in the local trust repository for an image", 109 LongHelp: "<code>images targets reset</code> clears unpublished changes in a local trust repository. This does not affect your remote trust repository. " + 110 "To reset changes for a specific target, specify a tag with the image name in the format \"image:tag\". Here is a sample command:\n\n" + 111 "<pre>\ndatica -E \"<your_env_name>\" images targets reset <image>\n</pre>", 112 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 113 return func(cmd *cli.Cmd) { 114 image := cmd.StringArg("IMAGE_NAME", "", "The name of the image to reset unpublished changes for. (e.g. 'my-image')") 115 cmd.Action = func() { 116 user, err := auth.New(settings, prompts.New()).Signin() 117 if err != nil { 118 logrus.Fatal(err.Error()) 119 } 120 if err = config.CheckRequiredAssociation(settings); err != nil { 121 logrus.Fatal(err.Error()) 122 } 123 if err = cmdTargetsReset(settings.EnvironmentID, *image, user, environments.New(settings), images.New(settings)); err != nil { 124 logrus.Fatalln(err.Error()) 125 } 126 } 127 } 128 }, 129 }