grpcclient.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package client
  13. import (
  14. "context"
  15. api "github.com/yandex-cloud/go-genproto/yandex/cloud/certificatemanager/v1"
  16. "github.com/yandex-cloud/go-sdk/iamkey"
  17. "google.golang.org/grpc"
  18. "github.com/external-secrets/external-secrets/pkg/provider/yandex/common"
  19. )
  20. // Real/gRPC implementation of CertificateManagerClient.
  21. type grpcCertificateManagerClient struct {
  22. certificateContentServiceClient api.CertificateContentServiceClient
  23. }
  24. func NewGrpcCertificateManagerClient(ctx context.Context, apiEndpoint string, authorizedKey *iamkey.Key, caCertificate []byte) (CertificateManagerClient, error) {
  25. conn, err := common.NewGrpcConnection(
  26. ctx,
  27. apiEndpoint,
  28. "certificate-manager-data", // taken from https://api.cloud.yandex.net/endpoints
  29. authorizedKey,
  30. caCertificate,
  31. )
  32. if err != nil {
  33. return nil, err
  34. }
  35. return &grpcCertificateManagerClient{api.NewCertificateContentServiceClient(conn)}, nil
  36. }
  37. func (c *grpcCertificateManagerClient) GetCertificateContent(ctx context.Context, iamToken, certificateID, _ string) (*api.GetCertificateContentResponse, error) {
  38. response, err := c.certificateContentServiceClient.Get(
  39. ctx,
  40. &api.GetCertificateContentRequest{
  41. CertificateId: certificateID,
  42. },
  43. grpc.PerRPCCredentials(common.PerRPCCredentials{IamToken: iamToken}),
  44. )
  45. if err != nil {
  46. return nil, err
  47. }
  48. return response, nil
  49. }