ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 1 | package securityservices |
| 2 | |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 3 | import ( |
| 4 | "encoding/json" |
| 5 | "time" |
| 6 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame] | 7 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 8 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 9 | ) |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 10 | |
| 11 | // SecurityService contains all the information associated with an OpenStack |
| 12 | // SecurityService. |
| 13 | type 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 |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 37 | CreatedAt time.Time `json:"-"` |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 38 | // The date and time stamp when the security service was updated |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 39 | UpdatedAt time.Time `json:"-"` |
| 40 | } |
| 41 | |
| 42 | func (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 |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | type commonResult struct { |
| 62 | gophercloud.Result |
| 63 | } |
| 64 | |
ehdou | b46ba5a | 2017-03-08 20:56:49 +0200 | [diff] [blame] | 65 | // SecurityServicePage is a pagination.pager that is returned from a call to the List function. |
| 66 | type SecurityServicePage struct { |
| 67 | pagination.SinglePageBase |
| 68 | } |
| 69 | |
| 70 | // IsEmpty returns true if a ListResult contains no SecurityServices. |
| 71 | func (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. |
| 78 | func 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 | |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 86 | // Extract will get the SecurityService object out of the commonResult object. |
| 87 | func (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. |
| 96 | type CreateResult struct { |
| 97 | commonResult |
| 98 | } |
ehdou | 894b50d | 2017-01-07 00:38:03 +0200 | [diff] [blame] | 99 | |
| 100 | // DeleteResult contains the response body and error from a Delete request. |
| 101 | type DeleteResult struct { |
| 102 | gophercloud.ErrResult |
| 103 | } |