blob: 3db40abc284452aadd986c8c25a18eff302a5a30 [file] [log] [blame]
ehdoub5066cd2016-11-10 22:15:42 +02001package securityservices
2
jrperritt98d01622017-01-12 14:24:42 -06003import (
4 "encoding/json"
5 "time"
6
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02007 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02008 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
jrperritt98d01622017-01-12 14:24:42 -06009)
ehdoub5066cd2016-11-10 22:15:42 +020010
11// SecurityService contains all the information associated with an OpenStack
12// SecurityService.
13type SecurityService struct {
14 // The security service ID
15 ID string `json:"id"`
16 // The UUID of the project where the security service was created
17 ProjectID string `json:"project_id"`
18 // The security service domain
19 Domain string `json:"domain"`
20 // The security service status
21 Status string `json:"status"`
22 // The security service type. A valid value is ldap, kerberos, or active_directory
23 Type string `json:"type"`
24 // The security service name
25 Name string `json:"name"`
26 // The security service description
27 Description string `json:"description"`
28 // The DNS IP address that is used inside the tenant network
29 DNSIP string `json:"dns_ip"`
30 // The security service user or group name that is used by the tenant
31 User string `json:"user"`
32 // The user password, if you specify a user
33 Password string `json:"password"`
34 // The security service host name or IP address
35 Server string `json:"server"`
36 // The date and time stamp when the security service was created
jrperritt98d01622017-01-12 14:24:42 -060037 CreatedAt time.Time `json:"-"`
ehdoub5066cd2016-11-10 22:15:42 +020038 // The date and time stamp when the security service was updated
jrperritt98d01622017-01-12 14:24:42 -060039 UpdatedAt time.Time `json:"-"`
40}
41
42func (r *SecurityService) UnmarshalJSON(b []byte) error {
43 type tmp SecurityService
44 var s struct {
45 tmp
46 CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
47 UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
48 }
49 err := json.Unmarshal(b, &s)
50 if err != nil {
51 return err
52 }
53 *r = SecurityService(s.tmp)
54
55 r.CreatedAt = time.Time(s.CreatedAt)
56 r.UpdatedAt = time.Time(s.UpdatedAt)
57
58 return nil
ehdoub5066cd2016-11-10 22:15:42 +020059}
60
61type commonResult struct {
62 gophercloud.Result
63}
64
ehdoub46ba5a2017-03-08 20:56:49 +020065// SecurityServicePage is a pagination.pager that is returned from a call to the List function.
66type SecurityServicePage struct {
67 pagination.SinglePageBase
68}
69
70// IsEmpty returns true if a ListResult contains no SecurityServices.
71func (r SecurityServicePage) IsEmpty() (bool, error) {
72 securityServices, err := ExtractSecurityServices(r)
73 return len(securityServices) == 0, err
74}
75
76// ExtractSecurityServices extracts and returns SecurityServices. It is used while
77// iterating over a securityservices.List call.
78func ExtractSecurityServices(r pagination.Page) ([]SecurityService, error) {
79 var s struct {
80 SecurityServices []SecurityService `json:"security_services"`
81 }
82 err := (r.(SecurityServicePage)).ExtractInto(&s)
83 return s.SecurityServices, err
84}
85
ehdoub5066cd2016-11-10 22:15:42 +020086// Extract will get the SecurityService object out of the commonResult object.
87func (r commonResult) Extract() (*SecurityService, error) {
88 var s struct {
89 SecurityService *SecurityService `json:"security_service"`
90 }
91 err := r.ExtractInto(&s)
92 return s.SecurityService, err
93}
94
95// CreateResult contains the response body and error from a Create request.
96type CreateResult struct {
97 commonResult
98}
ehdou894b50d2017-01-07 00:38:03 +020099
100// DeleteResult contains the response body and error from a Delete request.
101type DeleteResult struct {
102 gophercloud.ErrResult
103}