github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/application/unexpose.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package application 5 6 import ( 7 "github.com/juju/cmd" 8 "github.com/juju/errors" 9 10 "github.com/juju/juju/api/application" 11 jujucmd "github.com/juju/juju/cmd" 12 "github.com/juju/juju/cmd/juju/block" 13 "github.com/juju/juju/cmd/modelcmd" 14 ) 15 16 var usageUnexposeSummary = ` 17 Removes public availability over the network for an application.`[1:] 18 19 var usageUnexposeDetails = ` 20 Adjusts the firewall rules and any relevant security mechanisms of the 21 cloud to deny public access to the application. 22 An application is unexposed by default when it gets created. 23 24 Examples: 25 juju unexpose wordpress 26 27 See also: 28 expose`[1:] 29 30 // NewUnexposeCommand returns a command to unexpose applications. 31 func NewUnexposeCommand() modelcmd.ModelCommand { 32 return modelcmd.Wrap(&unexposeCommand{}) 33 } 34 35 // unexposeCommand is responsible exposing applications. 36 type unexposeCommand struct { 37 modelcmd.ModelCommandBase 38 ApplicationName string 39 } 40 41 func (c *unexposeCommand) Info() *cmd.Info { 42 return jujucmd.Info(&cmd.Info{ 43 Name: "unexpose", 44 Args: "<application name>", 45 Purpose: usageUnexposeSummary, 46 Doc: usageUnexposeDetails, 47 }) 48 } 49 50 func (c *unexposeCommand) Init(args []string) error { 51 if len(args) == 0 { 52 return errors.New("no application name specified") 53 } 54 c.ApplicationName = args[0] 55 return cmd.CheckEmpty(args[1:]) 56 } 57 58 func (c *unexposeCommand) getAPI() (applicationExposeAPI, error) { 59 root, err := c.NewAPIRoot() 60 if err != nil { 61 return nil, errors.Trace(err) 62 } 63 return application.NewClient(root), nil 64 } 65 66 // Run changes the juju-managed firewall to hide any 67 // ports that were also explicitly marked by units as closed. 68 func (c *unexposeCommand) Run(_ *cmd.Context) error { 69 client, err := c.getAPI() 70 if err != nil { 71 return err 72 } 73 defer client.Close() 74 return block.ProcessBlockedError(client.Unexpose(c.ApplicationName), block.BlockChange) 75 }