github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/block/enablecommand.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package block 5 6 import ( 7 "github.com/juju/cmd" 8 "github.com/juju/errors" 9 10 jujucmd "github.com/juju/juju/cmd" 11 "github.com/juju/juju/cmd/modelcmd" 12 ) 13 14 // NewEnableCommand returns a new command that eanbles previously disabled 15 // command sets. 16 func NewEnableCommand() cmd.Command { 17 return modelcmd.Wrap(&enableCommand{ 18 apiFunc: func(c newAPIRoot) (unblockClientAPI, error) { 19 return getBlockAPI(c) 20 }, 21 }) 22 } 23 24 // enableCommand removes the block from desired operation. 25 type enableCommand struct { 26 modelcmd.ModelCommandBase 27 apiFunc func(newAPIRoot) (unblockClientAPI, error) 28 target string 29 } 30 31 // Init implements Command. 32 func (c *enableCommand) Init(args []string) error { 33 if len(args) < 1 { 34 return errors.Errorf("missing command set (%s)", validTargets) 35 } 36 c.target, args = args[0], args[1:] 37 target, ok := toAPIValue[c.target] 38 if !ok { 39 return errors.Errorf("bad command set, valid options: %s", validTargets) 40 } 41 c.target = target 42 return cmd.CheckEmpty(args) 43 } 44 45 // Info implementsCommand. 46 func (c *enableCommand) Info() *cmd.Info { 47 return jujucmd.Info(&cmd.Info{ 48 Name: "enable-command", 49 Args: "<command set>", 50 Purpose: "Enable commands that had been previously disabled.", 51 Doc: enableDoc, 52 }) 53 } 54 55 // unblockClientAPI defines the client API methods that unblock command uses. 56 type unblockClientAPI interface { 57 Close() error 58 SwitchBlockOff(blockType string) error 59 } 60 61 // Run implements Command. 62 func (c *enableCommand) Run(_ *cmd.Context) error { 63 api, err := c.apiFunc(c) 64 if err != nil { 65 return errors.Annotate(err, "cannot connect to the API") 66 } 67 defer api.Close() 68 69 return api.SwitchBlockOff(c.target) 70 } 71 72 const enableDoc = ` 73 Juju allows to safeguard deployed models from unintentional damage by preventing 74 execution of operations that could alter model. 75 76 This is done by disabling certain sets of commands from successful execution. 77 Disabled commands must be manually enabled to proceed. 78 79 Some commands offer a --force option that can be used to bypass a block. 80 ` + commandSets + ` 81 Examples: 82 # To allow the model to be destroyed: 83 juju enable-command destroy-model 84 85 # To allow the machines, applications, units and relations to be removed: 86 juju enable-command remove-object 87 88 # To allow changes to the model: 89 juju enable-command all 90 91 See also: 92 disable-command 93 disabled-commands 94 `