github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/params/firewall.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package params
     5  
     6  import "github.com/juju/errors"
     7  
     8  // FirewallRuleArgs holds the parameters for updating
     9  // one or more firewall rules.
    10  type FirewallRuleArgs struct {
    11  	// Args holds the parameters for updating a firewall rule.
    12  	Args []FirewallRule `json:"args"`
    13  }
    14  
    15  // ListFirewallRulesResults holds the results of listing firewall rules.
    16  type ListFirewallRulesResults struct {
    17  	// Rules is a list of firewall rules.
    18  	Rules []FirewallRule
    19  }
    20  
    21  // FirewallRule is a rule for ingress through a firewall.
    22  type FirewallRule struct {
    23  	// KnownService is the well known service for a firewall rule.
    24  	KnownService KnownServiceValue `json:"known-service"`
    25  
    26  	// WhitelistCIDRS is the ist of subnets allowed access.
    27  	WhitelistCIDRS []string `json:"whitelist-cidrs,omitempty"`
    28  }
    29  
    30  // KnownServiceArgs holds the parameters for retrieving firewall rules.
    31  type KnownServiceArgs struct {
    32  	// KnownServices are the well known services for a firewall rule.
    33  	KnownServices []KnownServiceValue `json:"known-services"`
    34  }
    35  
    36  // KnownServiceValue describes a well known service for which a
    37  // firewall rule can be set up.
    38  type KnownServiceValue string
    39  
    40  const (
    41  	// The supported services for firewall rules.
    42  	// If a new service is added here, remember to update the
    43  	// set-firewall-rule command help text.
    44  
    45  	// SSHRule is a rule for SSH connections.
    46  	SSHRule KnownServiceValue = "ssh"
    47  
    48  	// JujuControllerRule is a rule for connections to the Juju controller.
    49  	JujuControllerRule KnownServiceValue = "juju-controller"
    50  
    51  	// JujuApplicationOfferRule is a rule for connections to a Juju offer.
    52  	JujuApplicationOfferRule KnownServiceValue = "juju-application-offer"
    53  )
    54  
    55  // Validate returns an error if the service value is not valid.
    56  func (v KnownServiceValue) Validate() error {
    57  	switch v {
    58  	case SSHRule, JujuControllerRule, JujuApplicationOfferRule:
    59  		return nil
    60  	}
    61  	return errors.NotValidf("known service %q", v)
    62  }