blob: cd4305b50b90825241154b7839ca7e7dbda039f7 [file] [log] [blame]
ehdoub5066cd2016-11-10 22:15:42 +02001package securityservices
2
ehdoub46ba5a2017-03-08 20:56:49 +02003import (
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02004 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02005 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
ehdoub46ba5a2017-03-08 20:56:49 +02006)
ehdoub5066cd2016-11-10 22:15:42 +02007
8type SecurityServiceType string
9
10// Valid security service types
11const (
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.
19type 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.
26type 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 user or group name that is used by the tenant
36 User string `json:"user,omitempty"`
37 // The user password, if you specify a user
38 Password string `json:"password,omitempty"`
39 // The security service domain
40 Domain string `json:"domain,omitempty"`
41 // The security service host name or IP address
42 Server string `json:"server,omitempty"`
43}
44
45// ToSecurityServicesCreateMap assembles a request body based on the contents of a
46// CreateOpts.
47func (opts CreateOpts) ToSecurityServiceCreateMap() (map[string]interface{}, error) {
48 return gophercloud.BuildRequestBody(opts, "security_service")
49}
50
51// Create will create a new SecurityService based on the values in CreateOpts. To
52// extract the SecurityService object from the response, call the Extract method
53// on the CreateResult.
54func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
55 b, err := opts.ToSecurityServiceCreateMap()
56 if err != nil {
57 r.Err = err
58 return
59 }
60 _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
61 OkCodes: []int{200},
62 })
63 return
64}
ehdou894b50d2017-01-07 00:38:03 +020065
66// Delete will delete the existing SecurityService with the provided ID.
67func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
68 _, r.Err = client.Delete(deleteURL(client, id), nil)
69 return
70}
ehdoub46ba5a2017-03-08 20:56:49 +020071
72// ListOptsBuilder allows extensions to add additional parameters to the List
73// request.
74type ListOptsBuilder interface {
75 ToSecurityServiceListQuery() (string, error)
76}
77
78// ListOpts holds options for listing SecurityServices. It is passed to the
79// securityservices.List function.
80type ListOpts struct {
81 // admin-only option. Set it to true to see all tenant security services.
82 AllTenants bool `q:"all_tenants"`
83 // The security service ID
84 ID string `q:"id"`
85 // The security service domain
86 Domain string `q:"domain"`
87 // The security service type. A valid value is ldap, kerberos, or active_directory
88 Type SecurityServiceType `q:"type"`
89 // The security service name
90 Name string `q:"name"`
91 // The DNS IP address that is used inside the tenant network
92 DNSIP string `q:"dns_ip"`
93 // The security service user or group name that is used by the tenant
94 User string `q:"user"`
95 // The security service host name or IP address
96 Server string `q:"server"`
97 // The ID of the share network using security services
98 ShareNetworkID string `q:"share_network_id"`
99}
100
101// ToSecurityServiceListQuery formats a ListOpts into a query string.
102func (opts ListOpts) ToSecurityServiceListQuery() (string, error) {
103 q, err := gophercloud.BuildQueryString(opts)
104 return q.String(), err
105}
106
107// List returns SecurityServices optionally limited by the conditions provided in ListOpts.
108func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
109 url := listURL(client)
110 if opts != nil {
111 query, err := opts.ToSecurityServiceListQuery()
112 if err != nil {
113 return pagination.Pager{Err: err}
114 }
115 url += query
116 }
117
118 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
119 return SecurityServicePage{pagination.SinglePageBase(r)}
120 })
121}