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