secret.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. )
  18. type SecretListOptions struct {
  19. NamespaceResourceListOptions
  20. Type string `help:"Secret type"`
  21. }
  22. func (o SecretListOptions) Params() (jsonutils.JSONObject, error) {
  23. params, err := o.NamespaceResourceListOptions.Params()
  24. if err != nil {
  25. return nil, err
  26. }
  27. if o.Type != "" {
  28. params.(*jsonutils.JSONDict).Add(jsonutils.NewString(o.Type), "type")
  29. }
  30. return params, nil
  31. }
  32. type RegistrySecretCreateOptions struct {
  33. SecretCreateOptions
  34. Server string `help:"Docker registry server, e.g. 'https://index.docker.io/v1/'" required:"true"`
  35. User string `help:"Docker registry user" required:"true"`
  36. Password string `help:"Docker registry password" required:"true"`
  37. Email string `help:"Docker registry user email"`
  38. }
  39. func (o RegistrySecretCreateOptions) Params() (jsonutils.JSONObject, error) {
  40. input, err := o.SecretCreateOptions.Params("kubernetes.io/dockerconfigjson")
  41. if err != nil {
  42. return nil, err
  43. }
  44. params := jsonutils.NewDict()
  45. params.Add(jsonutils.NewString(o.Server), "server")
  46. params.Add(jsonutils.NewString(o.User), "user")
  47. params.Add(jsonutils.NewString(o.Password), "password")
  48. if o.Email != "" {
  49. params.Add(jsonutils.NewString(o.Email), "email")
  50. }
  51. input.Add(params, "dockerConfigJson")
  52. return input, nil
  53. }
  54. type SecretCreateOptions struct {
  55. NamespaceWithClusterOptions
  56. NAME string `help:"Name of secret"`
  57. }
  58. func (o SecretCreateOptions) Params(typ string) (*jsonutils.JSONDict, error) {
  59. params := o.NamespaceWithClusterOptions.Params()
  60. params.Add(jsonutils.NewString(o.NAME), "name")
  61. params.Add(jsonutils.NewString(typ), "type")
  62. return params, nil
  63. }
  64. type CephCSISecretCreateOptions struct {
  65. SecretCreateOptions
  66. USERID string `help:"User id"`
  67. USERKEY string `help:"User key"`
  68. }
  69. func (o CephCSISecretCreateOptions) Params() (jsonutils.JSONObject, error) {
  70. params, err := o.SecretCreateOptions.Params("yunion.io/ceph-csi")
  71. if err != nil {
  72. return nil, err
  73. }
  74. conf := jsonutils.NewDict()
  75. conf.Add(jsonutils.NewString(o.USERID), "userId")
  76. conf.Add(jsonutils.NewString(o.USERKEY), "userKey")
  77. params.Add(conf, "cephCSI")
  78. return params, nil
  79. }