repo.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 k8s
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient/options"
  18. )
  19. type RepoListOptions struct {
  20. options.BaseListOptions
  21. Type string `help:"Helm repostitory type" json:"type" choices:"internal|external"`
  22. }
  23. func (o *RepoListOptions) Params() (jsonutils.JSONObject, error) {
  24. params, err := o.BaseListOptions.Params()
  25. if err != nil {
  26. return nil, err
  27. }
  28. if o.Type != "" {
  29. params.Add(jsonutils.NewString(o.Type), "type")
  30. }
  31. return params, nil
  32. }
  33. type RepoGetOptions struct {
  34. NAME string `help:"ID or name of the repo"`
  35. }
  36. func (o *RepoGetOptions) GetId() string {
  37. return o.NAME
  38. }
  39. func (o *RepoGetOptions) Params() (jsonutils.JSONObject, error) {
  40. return nil, nil
  41. }
  42. type RepoCreateOptions struct {
  43. RepoGetOptions
  44. Type string `help:"Repository type" choices:"internal|external"`
  45. URL string `help:"Repository url"`
  46. Public bool `help:"Make repostitory public"`
  47. Backend string `help:"Repository backend" choices:"common|nexus"`
  48. Username string `help:"Repository auth username"`
  49. Password string `help:"Repository auth password"`
  50. }
  51. func (o RepoCreateOptions) Params() (jsonutils.JSONObject, error) {
  52. params := jsonutils.NewDict()
  53. params.Add(jsonutils.NewString(o.NAME), "name")
  54. params.Add(jsonutils.NewString(o.URL), "url")
  55. if o.Type != "" {
  56. params.Add(jsonutils.NewString(o.Type), "type")
  57. }
  58. if o.Public {
  59. params.Add(jsonutils.JSONTrue, "is_public")
  60. }
  61. if o.Backend != "" {
  62. params.Add(jsonutils.NewString(o.Backend), "backend")
  63. }
  64. if o.Username != "" {
  65. params.Add(jsonutils.NewString(o.Username), "username")
  66. }
  67. if o.Password != "" {
  68. params.Add(jsonutils.NewString(o.Password), "password")
  69. }
  70. return params, nil
  71. }
  72. type RepoUpdateOptions struct {
  73. RepoGetOptions
  74. Name string `help:"Repository name to change"`
  75. Url string `help:"Repository url to change"`
  76. Username string `help:"Repository auth username"`
  77. Password string `help:"Repository auth password"`
  78. }
  79. func (o RepoUpdateOptions) GetId() string {
  80. return o.NAME
  81. }
  82. func (o RepoUpdateOptions) Params() (jsonutils.JSONObject, error) {
  83. params := jsonutils.NewDict()
  84. if o.Name != "" {
  85. params.Add(jsonutils.NewString(o.Name), "name")
  86. }
  87. if o.Url != "" {
  88. params.Add(jsonutils.NewString(o.Url), "url")
  89. }
  90. if o.Username != "" {
  91. params.Add(jsonutils.NewString(o.Username), "username")
  92. }
  93. if o.Password != "" {
  94. params.Add(jsonutils.NewString(o.Password), "password")
  95. }
  96. return params, nil
  97. }
  98. type RepoPublicOptions struct {
  99. ID string `help:"ID or name of repo" json:"-"`
  100. Scope string `help:"sharing scope" choices:"system|domain"`
  101. SharedDomains []string `help:"share to domains"`
  102. }
  103. func (o *RepoPublicOptions) GetId() string {
  104. return o.ID
  105. }
  106. func (o *RepoPublicOptions) Params() (jsonutils.JSONObject, error) {
  107. return jsonutils.Marshal(o), nil
  108. }