ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame^] | 1 | package securityservices |
| 2 | |
| 3 | import "github.com/gophercloud/gophercloud" |
| 4 | |
| 5 | type SecurityServiceType string |
| 6 | |
| 7 | // Valid security service types |
| 8 | const ( |
| 9 | LDAP SecurityServiceType = "ldap" |
| 10 | Kerberos SecurityServiceType = "kerberos" |
| 11 | ActiveDirectory SecurityServiceType = "active_directory" |
| 12 | ) |
| 13 | |
| 14 | // CreateOptsBuilder allows extensions to add additional parameters to the |
| 15 | // Create request. |
| 16 | type CreateOptsBuilder interface { |
| 17 | ToSecurityServiceCreateMap() (map[string]interface{}, error) |
| 18 | } |
| 19 | |
| 20 | // CreateOpts contains options for creating a SecurityService. This object is |
| 21 | // passed to the securityservices.Create function. For more information about |
| 22 | // these parameters, see the SecurityService object. |
| 23 | type CreateOpts struct { |
| 24 | // The security service type. A valid value is ldap, kerberos, or active_directory |
| 25 | Type SecurityServiceType `json:"type" required:"true"` |
| 26 | // The security service name |
| 27 | Name string `json:"name,omitempty"` |
| 28 | // The security service description |
| 29 | Description string `json:"description,omitempty"` |
| 30 | // The DNS IP address that is used inside the tenant network |
| 31 | DNSIP string `json:"dns_ip,omitempty"` |
| 32 | // The security service user or group name that is used by the tenant |
| 33 | User string `json:"user,omitempty"` |
| 34 | // The user password, if you specify a user |
| 35 | Password string `json:"password,omitempty"` |
| 36 | // The security service domain |
| 37 | Domain string `json:"domain,omitempty"` |
| 38 | // The security service host name or IP address |
| 39 | Server string `json:"server,omitempty"` |
| 40 | } |
| 41 | |
| 42 | // ToSecurityServicesCreateMap assembles a request body based on the contents of a |
| 43 | // CreateOpts. |
| 44 | func (opts CreateOpts) ToSecurityServiceCreateMap() (map[string]interface{}, error) { |
| 45 | return gophercloud.BuildRequestBody(opts, "security_service") |
| 46 | } |
| 47 | |
| 48 | // Create will create a new SecurityService based on the values in CreateOpts. To |
| 49 | // extract the SecurityService object from the response, call the Extract method |
| 50 | // on the CreateResult. |
| 51 | func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { |
| 52 | b, err := opts.ToSecurityServiceCreateMap() |
| 53 | if err != nil { |
| 54 | r.Err = err |
| 55 | return |
| 56 | } |
| 57 | _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ |
| 58 | OkCodes: []int{200}, |
| 59 | }) |
| 60 | return |
| 61 | } |