github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/cmd/juju/expose.go (about)

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