mod_elasticcache.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/pkg/utils"
  18. "yunion.io/x/onecloud/pkg/httperrors"
  19. "yunion.io/x/onecloud/pkg/mcclient"
  20. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  21. "yunion.io/x/onecloud/pkg/mcclient/modules"
  22. )
  23. var (
  24. ElasticCache ElasticCacheManager
  25. ElasticCacheAccount ElasticCacheAccountManager
  26. ElasticCacheBackup modulebase.ResourceManager
  27. ElasticCacheAcl modulebase.ResourceManager
  28. ElasticCacheParameter modulebase.ResourceManager
  29. ElasticCacheSecgroup modulebase.JointResourceManager
  30. )
  31. type ElasticCacheManager struct {
  32. modulebase.ResourceManager
  33. }
  34. type ElasticCacheAccountManager struct {
  35. modulebase.ResourceManager
  36. }
  37. func init() {
  38. ElasticCache = ElasticCacheManager{modules.NewComputeManager("elasticcache", "elasticcaches",
  39. []string{"ID", "Name", "Cloudregion_Id", "Status", "InstanceType", "CapacityMB", "Engine", "EngineVersion"},
  40. []string{})}
  41. ElasticCacheAccount = ElasticCacheAccountManager{modules.NewComputeManager("elasticcacheaccount", "elasticcacheaccounts",
  42. []string{},
  43. []string{})}
  44. ElasticCacheBackup = modules.NewComputeManager("elasticcachebackup", "elasticcachebackups",
  45. []string{},
  46. []string{})
  47. ElasticCacheAcl = modules.NewComputeManager("elasticcacheacl", "elasticcacheacls",
  48. []string{},
  49. []string{})
  50. ElasticCacheParameter = modules.NewComputeManager("elasticcacheparameter", "elasticcacheparameters",
  51. []string{},
  52. []string{})
  53. ElasticCacheSecgroup = modules.NewJointComputeManager("elasticcachesecgroup",
  54. "elasticcachesecgroups",
  55. []string{},
  56. []string{},
  57. &ElasticCache,
  58. &SecGroups)
  59. modules.RegisterCompute(&ElasticCache)
  60. modules.RegisterCompute(&ElasticCacheAccount)
  61. modules.RegisterCompute(&ElasticCacheAcl)
  62. modules.RegisterCompute(&ElasticCacheBackup)
  63. modules.RegisterCompute(&ElasticCacheParameter)
  64. modules.RegisterCompute(&ElasticCacheSecgroup)
  65. }
  66. func (self *ElasticCacheManager) GetLoginInfo(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  67. data, e := self.GetSpecific(s, id, "login-info", params)
  68. if e != nil {
  69. return nil, e
  70. }
  71. ret := jsonutils.NewDict()
  72. username, _ := data.GetString("username")
  73. ret.Set("username", jsonutils.NewString(username))
  74. account_id, _ := data.GetString("account_id")
  75. password, _ := data.GetString("password")
  76. if len(password) == 0 {
  77. return nil, httperrors.NewNotFoundError("No password found")
  78. }
  79. passwd, e := utils.DescryptAESBase64(account_id, password)
  80. if e != nil {
  81. return nil, e
  82. }
  83. ret.Set("password", jsonutils.NewString(passwd))
  84. return ret, nil
  85. }
  86. func (self *ElasticCacheAccountManager) GetLoginInfo(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  87. data, e := self.GetSpecific(s, id, "login-info", params)
  88. if e != nil {
  89. return nil, e
  90. }
  91. ret := jsonutils.NewDict()
  92. username, _ := data.GetString("username")
  93. ret.Set("username", jsonutils.NewString(username))
  94. password, _ := data.GetString("password")
  95. if len(password) == 0 {
  96. return nil, httperrors.NewNotFoundError("No password found")
  97. }
  98. passwd, e := utils.DescryptAESBase64(id, password)
  99. if e != nil {
  100. return nil, e
  101. }
  102. ret.Set("password", jsonutils.NewString(passwd))
  103. return ret, nil
  104. }