github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/securityservices/requests.go (about)

     1  package securityservices
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  type SecurityServiceType string
     9  
    10  // Valid security service types
    11  const (
    12  	LDAP            SecurityServiceType = "ldap"
    13  	Kerberos        SecurityServiceType = "kerberos"
    14  	ActiveDirectory SecurityServiceType = "active_directory"
    15  )
    16  
    17  // CreateOptsBuilder allows extensions to add additional parameters to the
    18  // Create request.
    19  type CreateOptsBuilder interface {
    20  	ToSecurityServiceCreateMap() (map[string]interface{}, error)
    21  }
    22  
    23  // CreateOpts contains options for creating a SecurityService. This object is
    24  // passed to the securityservices.Create function. For more information about
    25  // these parameters, see the SecurityService object.
    26  type CreateOpts struct {
    27  	// The security service type. A valid value is ldap, kerberos, or active_directory
    28  	Type SecurityServiceType `json:"type" required:"true"`
    29  	// The security service name
    30  	Name string `json:"name,omitempty"`
    31  	// The security service description
    32  	Description string `json:"description,omitempty"`
    33  	// The DNS IP address that is used inside the tenant network
    34  	DNSIP string `json:"dns_ip,omitempty"`
    35  	// The security service organizational unit (OU). Minimum supported microversion for OU is 2.44.
    36  	OU string `json:"ou,omitempty"`
    37  	// The security service user or group name that is used by the tenant
    38  	User string `json:"user,omitempty"`
    39  	// The user password, if you specify a user
    40  	Password string `json:"password,omitempty"`
    41  	// The security service domain
    42  	Domain string `json:"domain,omitempty"`
    43  	// The security service host name or IP address
    44  	Server string `json:"server,omitempty"`
    45  }
    46  
    47  // ToSecurityServicesCreateMap assembles a request body based on the contents of a
    48  // CreateOpts.
    49  func (opts CreateOpts) ToSecurityServiceCreateMap() (map[string]interface{}, error) {
    50  	return gophercloud.BuildRequestBody(opts, "security_service")
    51  }
    52  
    53  // Create will create a new SecurityService based on the values in CreateOpts. To
    54  // extract the SecurityService object from the response, call the Extract method
    55  // on the CreateResult.
    56  func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    57  	b, err := opts.ToSecurityServiceCreateMap()
    58  	if err != nil {
    59  		r.Err = err
    60  		return
    61  	}
    62  	resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
    63  		OkCodes: []int{200},
    64  	})
    65  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    66  	return
    67  }
    68  
    69  // Delete will delete the existing SecurityService with the provided ID.
    70  func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
    71  	resp, err := client.Delete(deleteURL(client, id), nil)
    72  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    73  	return
    74  }
    75  
    76  // ListOptsBuilder allows extensions to add additional parameters to the List
    77  // request.
    78  type ListOptsBuilder interface {
    79  	ToSecurityServiceListQuery() (string, error)
    80  }
    81  
    82  // ListOpts holds options for listing SecurityServices. It is passed to the
    83  // securityservices.List function.
    84  type ListOpts struct {
    85  	// admin-only option. Set it to true to see all tenant security services.
    86  	AllTenants bool `q:"all_tenants"`
    87  	// The security service ID
    88  	ID string `q:"id"`
    89  	// The security service domain
    90  	Domain string `q:"domain"`
    91  	// The security service type. A valid value is ldap, kerberos, or active_directory
    92  	Type SecurityServiceType `q:"type"`
    93  	// The security service name
    94  	Name string `q:"name"`
    95  	// The DNS IP address that is used inside the tenant network
    96  	DNSIP string `q:"dns_ip"`
    97  	// The security service organizational unit (OU). Minimum supported microversion for OU is 2.44.
    98  	OU string `q:"ou"`
    99  	// The security service user or group name that is used by the tenant
   100  	User string `q:"user"`
   101  	// The security service host name or IP address
   102  	Server string `q:"server"`
   103  	// The ID of the share network using security services
   104  	ShareNetworkID string `q:"share_network_id"`
   105  }
   106  
   107  // ToSecurityServiceListQuery formats a ListOpts into a query string.
   108  func (opts ListOpts) ToSecurityServiceListQuery() (string, error) {
   109  	q, err := gophercloud.BuildQueryString(opts)
   110  	return q.String(), err
   111  }
   112  
   113  // List returns SecurityServices optionally limited by the conditions provided in ListOpts.
   114  func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   115  	url := listURL(client)
   116  	if opts != nil {
   117  		query, err := opts.ToSecurityServiceListQuery()
   118  		if err != nil {
   119  			return pagination.Pager{Err: err}
   120  		}
   121  		url += query
   122  	}
   123  
   124  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   125  		return SecurityServicePage{pagination.SinglePageBase(r)}
   126  	})
   127  }
   128  
   129  // Get retrieves the SecurityService with the provided ID. To extract the SecurityService
   130  // object from the response, call the Extract method on the GetResult.
   131  func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
   132  	resp, err := client.Get(getURL(client, id), &r.Body, nil)
   133  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   134  	return
   135  }
   136  
   137  // UpdateOptsBuilder allows extensions to add additional parameters to the
   138  // Update request.
   139  type UpdateOptsBuilder interface {
   140  	ToSecurityServiceUpdateMap() (map[string]interface{}, error)
   141  }
   142  
   143  // UpdateOpts contain options for updating an existing SecurityService. This object is passed
   144  // to the securityservices.Update function. For more information about the parameters, see
   145  // the SecurityService object.
   146  type UpdateOpts struct {
   147  	// The security service name
   148  	Name *string `json:"name"`
   149  	// The security service description
   150  	Description *string `json:"description,omitempty"`
   151  	// The security service type. A valid value is ldap, kerberos, or active_directory
   152  	Type string `json:"type,omitempty"`
   153  	// The DNS IP address that is used inside the tenant network
   154  	DNSIP *string `json:"dns_ip,omitempty"`
   155  	// The security service organizational unit (OU). Minimum supported microversion for OU is 2.44.
   156  	OU *string `json:"ou,omitempty"`
   157  	// The security service user or group name that is used by the tenant
   158  	User *string `json:"user,omitempty"`
   159  	// The user password, if you specify a user
   160  	Password *string `json:"password,omitempty"`
   161  	// The security service domain
   162  	Domain *string `json:"domain,omitempty"`
   163  	// The security service host name or IP address
   164  	Server *string `json:"server,omitempty"`
   165  }
   166  
   167  // ToSecurityServiceUpdateMap assembles a request body based on the contents of an
   168  // UpdateOpts.
   169  func (opts UpdateOpts) ToSecurityServiceUpdateMap() (map[string]interface{}, error) {
   170  	return gophercloud.BuildRequestBody(opts, "security_service")
   171  }
   172  
   173  // Update will update the SecurityService with provided information. To extract the updated
   174  // SecurityService from the response, call the Extract method on the UpdateResult.
   175  func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   176  	b, err := opts.ToSecurityServiceUpdateMap()
   177  	if err != nil {
   178  		r.Err = err
   179  		return
   180  	}
   181  	resp, err := client.Put(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
   182  		OkCodes: []int{200},
   183  	})
   184  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   185  	return
   186  }