config.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. "strings"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type ConfigListOptions struct {
  21. options.BaseListOptions
  22. Type string `json:"type"`
  23. Attribution string `json:"attribution"`
  24. }
  25. func (cl *ConfigListOptions) Params() (jsonutils.JSONObject, error) {
  26. return options.ListStructToParams(cl)
  27. }
  28. type ConfigCreateOptions struct {
  29. NAME string `help:"Name of Config"`
  30. Domain string `help:"which domain create for, required if attribution is 'domain'"`
  31. Type string `help:"The type of config"`
  32. Configs []string `help:"Config content, format: 'key:value'"`
  33. Attribution string `help:"Attribution" choices:"system|domain"`
  34. }
  35. func (cc *ConfigCreateOptions) Params() (jsonutils.JSONObject, error) {
  36. jo := jsonutils.Marshal(cc)
  37. d := jo.(*jsonutils.JSONDict)
  38. d.Remove("configs")
  39. configs := jsonutils.NewDict()
  40. for _, kv := range cc.Configs {
  41. index := strings.IndexByte(kv, ':')
  42. configs.Set(kv[:index], jsonutils.NewString(kv[index+1:]))
  43. }
  44. d.Set("content", configs)
  45. return d, nil
  46. }
  47. type ConfigOptions struct {
  48. ID string
  49. }
  50. func (c *ConfigOptions) GetId() string {
  51. return c.ID
  52. }
  53. func (c *ConfigOptions) Params() (jsonutils.JSONObject, error) {
  54. return nil, nil
  55. }
  56. type ConfigUpdateOptions struct {
  57. ConfigOptions
  58. Configs []string
  59. }
  60. func (cu *ConfigUpdateOptions) Params() (jsonutils.JSONObject, error) {
  61. configs := jsonutils.NewDict()
  62. for _, kv := range cu.Configs {
  63. index := strings.IndexByte(kv, ':')
  64. configs.Set(kv[:index], jsonutils.NewString(kv[index+1:]))
  65. }
  66. d := jsonutils.NewDict()
  67. d.Set("content", configs)
  68. return d, nil
  69. }
  70. type ConfigCapabilityOptions struct {
  71. }
  72. func (c *ConfigCapabilityOptions) Property() string {
  73. return "capability"
  74. }
  75. func (c *ConfigCapabilityOptions) Params() (jsonutils.JSONObject, error) {
  76. return nil, nil
  77. }