LDAPService.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // Copyright 2016, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package cloudstack
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "net/url"
  21. "strconv"
  22. )
  23. type LdapCreateAccountParams struct {
  24. p map[string]interface{}
  25. }
  26. func (p *LdapCreateAccountParams) toURLValues() url.Values {
  27. u := url.Values{}
  28. if p.p == nil {
  29. return u
  30. }
  31. if v, found := p.p["account"]; found {
  32. u.Set("account", v.(string))
  33. }
  34. if v, found := p.p["accountdetails"]; found {
  35. i := 0
  36. for k, vv := range v.(map[string]string) {
  37. u.Set(fmt.Sprintf("accountdetails[%d].key", i), k)
  38. u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv)
  39. i++
  40. }
  41. }
  42. if v, found := p.p["accountid"]; found {
  43. u.Set("accountid", v.(string))
  44. }
  45. if v, found := p.p["accounttype"]; found {
  46. vv := strconv.Itoa(v.(int))
  47. u.Set("accounttype", vv)
  48. }
  49. if v, found := p.p["domainid"]; found {
  50. u.Set("domainid", v.(string))
  51. }
  52. if v, found := p.p["networkdomain"]; found {
  53. u.Set("networkdomain", v.(string))
  54. }
  55. if v, found := p.p["timezone"]; found {
  56. u.Set("timezone", v.(string))
  57. }
  58. if v, found := p.p["userid"]; found {
  59. u.Set("userid", v.(string))
  60. }
  61. if v, found := p.p["username"]; found {
  62. u.Set("username", v.(string))
  63. }
  64. return u
  65. }
  66. func (p *LdapCreateAccountParams) SetAccount(v string) {
  67. if p.p == nil {
  68. p.p = make(map[string]interface{})
  69. }
  70. p.p["account"] = v
  71. return
  72. }
  73. func (p *LdapCreateAccountParams) SetAccountdetails(v map[string]string) {
  74. if p.p == nil {
  75. p.p = make(map[string]interface{})
  76. }
  77. p.p["accountdetails"] = v
  78. return
  79. }
  80. func (p *LdapCreateAccountParams) SetAccountid(v string) {
  81. if p.p == nil {
  82. p.p = make(map[string]interface{})
  83. }
  84. p.p["accountid"] = v
  85. return
  86. }
  87. func (p *LdapCreateAccountParams) SetAccounttype(v int) {
  88. if p.p == nil {
  89. p.p = make(map[string]interface{})
  90. }
  91. p.p["accounttype"] = v
  92. return
  93. }
  94. func (p *LdapCreateAccountParams) SetDomainid(v string) {
  95. if p.p == nil {
  96. p.p = make(map[string]interface{})
  97. }
  98. p.p["domainid"] = v
  99. return
  100. }
  101. func (p *LdapCreateAccountParams) SetNetworkdomain(v string) {
  102. if p.p == nil {
  103. p.p = make(map[string]interface{})
  104. }
  105. p.p["networkdomain"] = v
  106. return
  107. }
  108. func (p *LdapCreateAccountParams) SetTimezone(v string) {
  109. if p.p == nil {
  110. p.p = make(map[string]interface{})
  111. }
  112. p.p["timezone"] = v
  113. return
  114. }
  115. func (p *LdapCreateAccountParams) SetUserid(v string) {
  116. if p.p == nil {
  117. p.p = make(map[string]interface{})
  118. }
  119. p.p["userid"] = v
  120. return
  121. }
  122. func (p *LdapCreateAccountParams) SetUsername(v string) {
  123. if p.p == nil {
  124. p.p = make(map[string]interface{})
  125. }
  126. p.p["username"] = v
  127. return
  128. }
  129. // You should always use this function to get a new LdapCreateAccountParams instance,
  130. // as then you are sure you have configured all required params
  131. func (s *LDAPService) NewLdapCreateAccountParams(accounttype int, username string) *LdapCreateAccountParams {
  132. p := &LdapCreateAccountParams{}
  133. p.p = make(map[string]interface{})
  134. p.p["accounttype"] = accounttype
  135. p.p["username"] = username
  136. return p
  137. }
  138. // Creates an account from an LDAP user
  139. func (s *LDAPService) LdapCreateAccount(p *LdapCreateAccountParams) (*LdapCreateAccountResponse, error) {
  140. resp, err := s.cs.newRequest("ldapCreateAccount", p.toURLValues())
  141. if err != nil {
  142. return nil, err
  143. }
  144. var r LdapCreateAccountResponse
  145. if err := json.Unmarshal(resp, &r); err != nil {
  146. return nil, err
  147. }
  148. return &r, nil
  149. }
  150. type LdapCreateAccountResponse struct {
  151. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  152. Accounttype int `json:"accounttype,omitempty"`
  153. Cpuavailable string `json:"cpuavailable,omitempty"`
  154. Cpulimit string `json:"cpulimit,omitempty"`
  155. Cputotal int64 `json:"cputotal,omitempty"`
  156. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  157. Domain string `json:"domain,omitempty"`
  158. Domainid string `json:"domainid,omitempty"`
  159. Groups []string `json:"groups,omitempty"`
  160. Id string `json:"id,omitempty"`
  161. Ipavailable string `json:"ipavailable,omitempty"`
  162. Iplimit string `json:"iplimit,omitempty"`
  163. Iptotal int64 `json:"iptotal,omitempty"`
  164. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  165. Isdefault bool `json:"isdefault,omitempty"`
  166. Memoryavailable string `json:"memoryavailable,omitempty"`
  167. Memorylimit string `json:"memorylimit,omitempty"`
  168. Memorytotal int64 `json:"memorytotal,omitempty"`
  169. Name string `json:"name,omitempty"`
  170. Networkavailable string `json:"networkavailable,omitempty"`
  171. Networkdomain string `json:"networkdomain,omitempty"`
  172. Networklimit string `json:"networklimit,omitempty"`
  173. Networktotal int64 `json:"networktotal,omitempty"`
  174. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  175. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  176. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  177. Projectavailable string `json:"projectavailable,omitempty"`
  178. Projectlimit string `json:"projectlimit,omitempty"`
  179. Projecttotal int64 `json:"projecttotal,omitempty"`
  180. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  181. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  182. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  183. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  184. Sentbytes int64 `json:"sentbytes,omitempty"`
  185. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  186. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  187. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  188. State string `json:"state,omitempty"`
  189. Templateavailable string `json:"templateavailable,omitempty"`
  190. Templatelimit string `json:"templatelimit,omitempty"`
  191. Templatetotal int64 `json:"templatetotal,omitempty"`
  192. User []struct {
  193. Account string `json:"account,omitempty"`
  194. Accountid string `json:"accountid,omitempty"`
  195. Accounttype int `json:"accounttype,omitempty"`
  196. Apikey string `json:"apikey,omitempty"`
  197. Created string `json:"created,omitempty"`
  198. Domain string `json:"domain,omitempty"`
  199. Domainid string `json:"domainid,omitempty"`
  200. Email string `json:"email,omitempty"`
  201. Firstname string `json:"firstname,omitempty"`
  202. Id string `json:"id,omitempty"`
  203. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  204. Isdefault bool `json:"isdefault,omitempty"`
  205. Lastname string `json:"lastname,omitempty"`
  206. Secretkey string `json:"secretkey,omitempty"`
  207. State string `json:"state,omitempty"`
  208. Timezone string `json:"timezone,omitempty"`
  209. Username string `json:"username,omitempty"`
  210. } `json:"user,omitempty"`
  211. Vmavailable string `json:"vmavailable,omitempty"`
  212. Vmlimit string `json:"vmlimit,omitempty"`
  213. Vmrunning int `json:"vmrunning,omitempty"`
  214. Vmstopped int `json:"vmstopped,omitempty"`
  215. Vmtotal int64 `json:"vmtotal,omitempty"`
  216. Volumeavailable string `json:"volumeavailable,omitempty"`
  217. Volumelimit string `json:"volumelimit,omitempty"`
  218. Volumetotal int64 `json:"volumetotal,omitempty"`
  219. Vpcavailable string `json:"vpcavailable,omitempty"`
  220. Vpclimit string `json:"vpclimit,omitempty"`
  221. Vpctotal int64 `json:"vpctotal,omitempty"`
  222. }