subscription.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // Copyright 2019 Yunion
  15. // Licensed under the Apache License, Version 2.0 (the "License");
  16. // you may not use this file except in compliance with the License.
  17. // You may obtain a copy of the License at
  18. //
  19. // http://www.apache.org/licenses/LICENSE-2.0
  20. //
  21. // Unless required by applicable law or agreed to in writing, software
  22. // distributed under the License is distributed on an "AS IS" BASIS,
  23. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. // See the License for the specific language governing permissions and
  25. // limitations under the License.
  26. package notify
  27. import (
  28. "yunion.io/x/jsonutils"
  29. "yunion.io/x/onecloud/pkg/mcclient/options"
  30. )
  31. type SubscriberCreateOptions struct {
  32. TopicId string `positional:"true"`
  33. ResourceScope string `positional:"true" choices:"system|domain|project"`
  34. ResourceAttributionId string `help:"project id or domain id of resource"`
  35. Type string `positional:"true" choices:"receiver|robot|role"`
  36. Receivers []string `help:"required if type is 'receiver'"`
  37. Role string `help:"required if type is 'role'"`
  38. RoleScope string `help:"required if type is 'role'"`
  39. Robot string `help:"required if type is 'robot'"`
  40. Scope string `positional:"true"`
  41. // minutes
  42. GroupTimes int
  43. }
  44. func (sc *SubscriberCreateOptions) Params() (jsonutils.JSONObject, error) {
  45. return jsonutils.Marshal(sc), nil
  46. }
  47. type SubscriberListOptions struct {
  48. options.BaseListOptions
  49. TopicId string
  50. ResourceScope string `choices:"system|domain|project"`
  51. Type string `choices:"receiver|robot|role"`
  52. SCOPE string `choices:"system|domain"`
  53. }
  54. func (sl *SubscriberListOptions) Params() (jsonutils.JSONObject, error) {
  55. return options.ListStructToParams(sl)
  56. }
  57. type SubscriberOptions struct {
  58. ID string
  59. }
  60. func (s *SubscriberOptions) GetId() string {
  61. return s.ID
  62. }
  63. func (s *SubscriberOptions) Params() (jsonutils.JSONObject, error) {
  64. return nil, nil
  65. }
  66. type SubscriberChangeOptions struct {
  67. SubscriberOptions
  68. Receivers []string
  69. Role string
  70. RoleScope string
  71. Robot string
  72. // minutes
  73. GroupTimes *int
  74. }
  75. func (ssr *SubscriberChangeOptions) Params() (jsonutils.JSONObject, error) {
  76. params := jsonutils.Marshal(ssr)
  77. params.(*jsonutils.JSONDict).Remove("id")
  78. return params, nil
  79. }