github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/commands/expose.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package commands 5 6 import ( 7 "errors" 8 9 "github.com/juju/cmd" 10 11 "github.com/juju/juju/cmd/envcmd" 12 "github.com/juju/juju/cmd/juju/block" 13 ) 14 15 // ExposeCommand is responsible exposing services. 16 type ExposeCommand struct { 17 envcmd.EnvCommandBase 18 ServiceName string 19 } 20 21 var jujuExposeHelp = ` 22 Adjusts firewall rules and similar security mechanisms of the provider, to 23 allow the service to be accessed on its public address. 24 25 ` 26 27 func (c *ExposeCommand) Info() *cmd.Info { 28 return &cmd.Info{ 29 Name: "expose", 30 Args: "<service>", 31 Purpose: "expose a service", 32 Doc: jujuExposeHelp, 33 } 34 } 35 36 func (c *ExposeCommand) Init(args []string) error { 37 if len(args) == 0 { 38 return errors.New("no service name specified") 39 } 40 c.ServiceName = args[0] 41 return cmd.CheckEmpty(args[1:]) 42 } 43 44 // Run changes the juju-managed firewall to expose any 45 // ports that were also explicitly marked by units as open. 46 func (c *ExposeCommand) Run(_ *cmd.Context) error { 47 client, err := c.NewAPIClient() 48 if err != nil { 49 return err 50 } 51 defer client.Close() 52 return block.ProcessBlockedError(client.ServiceExpose(c.ServiceName), block.BlockChange) 53 }