receiver.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 notify
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient/options"
  18. )
  19. type ReceiverListOptions struct {
  20. options.BaseListOptions
  21. UId string `help:"user id in keystone"`
  22. UName string `help:"user name in keystone"`
  23. EnabledContactType string `help:"enabled contact type"`
  24. VerifiedContactType string `help:"verified contact type"`
  25. ProjectDomainFilter bool `help:"filter receivers who join the project under the domain where the requester is currently located"`
  26. }
  27. func (rl *ReceiverListOptions) Params() (jsonutils.JSONObject, error) {
  28. return options.ListStructToParams(rl)
  29. }
  30. type ReceiverCreateOptions struct {
  31. UID string `help:"user id in keystone"`
  32. Email string `help:"email of receiver"`
  33. Mobile string `help:"mobile of receiver"`
  34. MobileAreaCode string `help:"area code of mobile"`
  35. EnabledContactTypes []string `help:"enabled contact type"`
  36. }
  37. func (rc *ReceiverCreateOptions) Params() (jsonutils.JSONObject, error) {
  38. d := jsonutils.NewDict()
  39. d.Set("uid", jsonutils.NewString(rc.UID))
  40. d.Set("email", jsonutils.NewString(rc.Email))
  41. d.Set("enabled_contact_types", jsonutils.NewStringArray(rc.EnabledContactTypes))
  42. d.Add(jsonutils.NewString(rc.Mobile), "international_mobile", "mobile")
  43. d.Add(jsonutils.NewString(rc.MobileAreaCode), "international_mobile", "area_code")
  44. return d, nil
  45. }
  46. type ReceiverOptions struct {
  47. ID string `help:"Id or Name of receiver"`
  48. }
  49. func (r *ReceiverOptions) GetId() string {
  50. return r.ID
  51. }
  52. func (r *ReceiverOptions) Params() (jsonutils.JSONObject, error) {
  53. return nil, nil
  54. }
  55. type ReceiverUpdateOptions struct {
  56. ReceiverOptions
  57. SreceiverUpdateOptions
  58. }
  59. type SreceiverUpdateOptions struct {
  60. Email string `help:"email of receiver"`
  61. Mobile string `help:"mobile of receiver"`
  62. MobileAreaCode string `help:"area code of mobile"`
  63. EnabledContactType []string `help:"enabled contact type"`
  64. }
  65. func (ru *ReceiverUpdateOptions) Params() (jsonutils.JSONObject, error) {
  66. d := jsonutils.NewDict()
  67. if len(ru.Email) > 0 {
  68. d.Set("email", jsonutils.NewString(ru.Email))
  69. }
  70. d.Set("enabled_contact_types", jsonutils.NewStringArray(ru.EnabledContactType))
  71. if len(ru.Mobile) > 0 {
  72. d.Add(jsonutils.NewString(ru.Mobile), "international_mobile", "mobile")
  73. d.Add(jsonutils.NewString(ru.MobileAreaCode), "international_mobile", "area_code")
  74. }
  75. return d, nil
  76. }
  77. type ReceiverTriggerVerifyOptions struct {
  78. ReceiverOptions
  79. SreceiverTriggerVerifyOptions
  80. }
  81. type SreceiverTriggerVerifyOptions struct {
  82. ContactType string `help:"Contact type to trigger verify" choices:"email|mobile"`
  83. }
  84. func (rt *ReceiverTriggerVerifyOptions) Params() (jsonutils.JSONObject, error) {
  85. return jsonutils.Marshal(rt.SreceiverTriggerVerifyOptions), nil
  86. }
  87. type ReceiverGetSubscriptionOptions struct {
  88. ReceiverOptions
  89. ShowDisabled bool `help:"List disabled subscription "`
  90. }
  91. func (rt *ReceiverGetSubscriptionOptions) Params() (jsonutils.JSONObject, error) {
  92. return jsonutils.Marshal(rt), nil
  93. }
  94. type ReceiverVerifyOptions struct {
  95. ReceiverOptions
  96. SreceiverVerifyOptions
  97. }
  98. type SreceiverVerifyOptions struct {
  99. ContactType string `help:"Contact type to trigger verify" choices:"email|mobile"`
  100. Token string `help:"Token from verify message sent to you"`
  101. }
  102. func (rv *ReceiverVerifyOptions) Params() (jsonutils.JSONObject, error) {
  103. return jsonutils.Marshal(rv.SreceiverVerifyOptions), nil
  104. }
  105. type ReceiverEnableContactTypeInput struct {
  106. ReceiverOptions
  107. SreceiverEnableContactTypeInput
  108. }
  109. func (re *ReceiverEnableContactTypeInput) Params() (jsonutils.JSONObject, error) {
  110. return jsonutils.Marshal(re.SreceiverEnableContactTypeInput), nil
  111. }
  112. type SreceiverEnableContactTypeInput struct {
  113. EnabledContactTypes []string `help:"Enabled contact types"`
  114. }
  115. type ReceiverIntellijGetOptions struct {
  116. USERID string `help:"user id in keystone" json:"user_id"`
  117. CreateIfNo *bool `help:"create if receiver with UserId does not exist"`
  118. SCOPE string `help:"scope"`
  119. }
  120. func (ri *ReceiverIntellijGetOptions) Params() (jsonutils.JSONObject, error) {
  121. return jsonutils.Marshal(ri), nil
  122. }
  123. type ReceiverGetTypeOptions struct {
  124. Receivers []string `help:"View the available notification channels for the receivers"`
  125. DomainIds []string `help:"View the available notification channels for the domains with these DomainIds"`
  126. Operation string `help:"Operation of reduce" choices:"merge|union"`
  127. }
  128. func (rg *ReceiverGetTypeOptions) Params() (jsonutils.JSONObject, error) {
  129. return jsonutils.Marshal(rg), nil
  130. }
  131. type SReceiverRoleContactType struct {
  132. ROLE_IDS []string
  133. Scope string
  134. ProjectDomainId string
  135. ProjectId string
  136. }
  137. func (rg *SReceiverRoleContactType) Property() string {
  138. return "role-contact-type"
  139. }
  140. func (rg *SReceiverRoleContactType) Params() (jsonutils.JSONObject, error) {
  141. return jsonutils.Marshal(rg), nil
  142. }