github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3.0/acl/requests.go (about)

     1  package acl
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  // ConsoleACLPolicyBuilder allows extensions to add additional parameters to
     8  // the modify request.
     9  type ConsoleACLPolicyBuilder interface {
    10  	ToConsoleACLPolicyMap() (map[string]interface{}, error)
    11  }
    12  
    13  // APIACLPolicyBuilder allows extensions to add additional parameters to
    14  // the modify request.
    15  type APIACLPolicyBuilder interface {
    16  	ToAPIACLPolicyMap() (map[string]interface{}, error)
    17  }
    18  
    19  // ACLPolicy provides options used to create, update or get a identity acl.
    20  type ACLPolicy struct {
    21  	AllowAddressNetmasks []AllowAddressNetmasks `json:"allow_address_netmasks,omitempty"`
    22  	AllowIPRanges        []AllowIPRanges        `json:"allow_ip_ranges,omitempty"`
    23  }
    24  
    25  // AllowAddressNetmasks provides options for creating, updating or getting a IPv4 CIDR blocks.
    26  type AllowAddressNetmasks struct {
    27  	AddressNetmask string `json:"address_netmask" required:"true"`
    28  	Description    string `json:"description,omitempty"`
    29  }
    30  
    31  // AllowIPRanges provides options for creating, updating or getting a IP address ranges.
    32  type AllowIPRanges struct {
    33  	IPRange     string `json:"ip_range" required:"true"`
    34  	Description string `json:"description,omitempty"`
    35  }
    36  
    37  // ToConsoleACLPolicyMap formats a create or update opts into a modify request for console access.
    38  func (aclPolicy ACLPolicy) ToConsoleACLPolicyMap() (map[string]interface{}, error) {
    39  	b, err := golangsdk.BuildRequestBody(aclPolicy, "console_acl_policy")
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  	return b, nil
    44  }
    45  
    46  // ToAPIACLPolicyMap formats a create or update opts into a modify request for api access.
    47  func (aclPolicy ACLPolicy) ToAPIACLPolicyMap() (map[string]interface{}, error) {
    48  	b, err := golangsdk.BuildRequestBody(aclPolicy, "api_acl_policy")
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  	return b, nil
    53  }
    54  
    55  // ConsoleACLPolicyUpdate can creates a new acl or updates a exist acl for console access.
    56  func ConsoleACLPolicyUpdate(client *golangsdk.ServiceClient, opts ConsoleACLPolicyBuilder, domainID string) (r ACLResult) {
    57  	b, err := opts.ToConsoleACLPolicyMap()
    58  	if err != nil {
    59  		r.Err = err
    60  		return
    61  	}
    62  	_, r.Err = client.Put(consoleACLPolicyURL(client, domainID), &b, &r.Body, &golangsdk.RequestOpts{
    63  		OkCodes: []int{200},
    64  	})
    65  	return
    66  }
    67  
    68  // APIACLPolicyUpdate can creates a new acl or updates a exist acl for api access.
    69  func APIACLPolicyUpdate(client *golangsdk.ServiceClient, opts APIACLPolicyBuilder, domainID string) (r ACLResult) {
    70  	b, err := opts.ToAPIACLPolicyMap()
    71  	if err != nil {
    72  		r.Err = err
    73  		return
    74  	}
    75  	_, r.Err = client.Put(apiACLPolicyURL(client, domainID), &b, &r.Body, &golangsdk.RequestOpts{
    76  		OkCodes: []int{200},
    77  	})
    78  	return
    79  }
    80  
    81  // ConsoleACLPolicyGet retrieves details on iam identity acl for console access, by domain ID.
    82  func ConsoleACLPolicyGet(client *golangsdk.ServiceClient, domainID string) (r ACLResult) {
    83  	_, r.Err = client.Get(consoleACLPolicyURL(client, domainID), &r.Body, nil)
    84  	return
    85  }
    86  
    87  // APIACLPolicyGet retrieves details on iam identity acl for api access, by domain ID.
    88  func APIACLPolicyGet(client *golangsdk.ServiceClient, domainID string) (r ACLResult) {
    89  	_, r.Err = client.Get(apiACLPolicyURL(client, domainID), &r.Body, nil)
    90  	return
    91  }