certificates.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package unversioned
  14. import (
  15. "k8s.io/kubernetes/pkg/apis/certificates"
  16. "k8s.io/kubernetes/pkg/client/restclient"
  17. )
  18. // Interface holds the methods for clients of Kubernetes to allow mock testing.
  19. type CertificatesInterface interface {
  20. CertificateSigningRequests() CertificateSigningRequestInterface
  21. }
  22. type CertificatesClient struct {
  23. *restclient.RESTClient
  24. }
  25. func (c *CertificatesClient) CertificateSigningRequests() CertificateSigningRequestInterface {
  26. return newCertificateSigningRequests(c)
  27. }
  28. // NewCertificates creates a new CertificatesClient for the given config.
  29. func NewCertificates(c *restclient.Config) (*CertificatesClient, error) {
  30. config := *c
  31. if err := setCertificatesDefaults(&config); err != nil {
  32. return nil, err
  33. }
  34. client, err := restclient.RESTClientFor(&config)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return &CertificatesClient{client}, nil
  39. }
  40. // NewCertificatesOrDie creates a new CertificatesClient for the given config and
  41. // panics if there is an error in the config.
  42. func NewCertificatesOrDie(c *restclient.Config) *CertificatesClient {
  43. client, err := NewCertificates(c)
  44. if err != nil {
  45. panic(err)
  46. }
  47. return client
  48. }
  49. func setCertificatesDefaults(config *restclient.Config) error {
  50. setGroupDefaults(certificates.GroupName, config)
  51. if config.QPS == 0 {
  52. config.QPS = 5
  53. }
  54. if config.Burst == 0 {
  55. config.Burst = 10
  56. }
  57. return nil
  58. }