forked from juju/juju
/
firewall.go
62 lines (49 loc) · 1.93 KB
/
firewall.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
54
55
56
57
58
59
60
61
62
// Copyright 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package params
import "github.com/juju/errors"
// FirewallRuleArgs holds the parameters for updating
// one or more firewall rules.
type FirewallRuleArgs struct {
// Args holds the parameters for updating a firewall rule.
Args []FirewallRule `json:"args"`
}
// ListFirewallRulesResults holds the results of listing firewall rules.
type ListFirewallRulesResults struct {
// Rules is a list of firewall rules.
Rules []FirewallRule
}
// FirewallRule is a rule for ingress through a firewall.
type FirewallRule struct {
// KnownService is the well known service for a firewall rule.
KnownService KnownServiceValue `json:"known-service"`
// WhitelistCIDRS is the ist of subnets allowed access.
WhitelistCIDRS []string `json:"whitelist-cidrs,omitempty"`
}
// KnownServiceArgs holds the parameters for retrieving firewall rules.
type KnownServiceArgs struct {
// KnownServices are the well known services for a firewall rule.
KnownServices []KnownServiceValue `json:"known-services"`
}
// KnownServiceValue describes a well known service for which a
// firewall rule can be set up.
type KnownServiceValue string
const (
// The supported services for firewall rules.
// If a new service is added here, remember to update the
// set-firewall-rule command help text.
// SSHRule is a rule for SSH connections.
SSHRule KnownServiceValue = "ssh"
// JujuControllerRule is a rule for connections to the Juju controller.
JujuControllerRule KnownServiceValue = "juju-controller"
// JujuApplicationOfferRule is a rule for connections to a Juju offer.
JujuApplicationOfferRule KnownServiceValue = "juju-application-offer"
)
// Validate returns an error if the service value is not valid.
func (v KnownServiceValue) Validate() error {
switch v {
case SSHRule, JujuControllerRule, JujuApplicationOfferRule:
return nil
}
return errors.NotValidf("known service %q", v)
}