grpcclient.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/lockbox/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 LockboxClient.
  21. type grpcLockboxClient struct {
  22. lockboxPayloadClient api.PayloadServiceClient
  23. }
  24. func NewGrpcLockboxClient(ctx context.Context, apiEndpoint string, authorizedKey *iamkey.Key, caCertificate []byte) (LockboxClient, error) {
  25. conn, err := common.NewGrpcConnection(
  26. ctx,
  27. apiEndpoint,
  28. "lockbox-payload", // taken from https://api.cloud.yandex.net/endpoints
  29. authorizedKey,
  30. caCertificate,
  31. )
  32. if err != nil {
  33. return nil, err
  34. }
  35. return &grpcLockboxClient{api.NewPayloadServiceClient(conn)}, nil
  36. }
  37. func (c *grpcLockboxClient) GetPayloadEntries(ctx context.Context, iamToken, secretID, versionID string) ([]*api.Payload_Entry, error) {
  38. payload, err := c.lockboxPayloadClient.Get(
  39. ctx,
  40. &api.GetPayloadRequest{
  41. SecretId: secretID,
  42. VersionId: versionID,
  43. },
  44. grpc.PerRPCCredentials(common.PerRPCCredentials{IamToken: iamToken}),
  45. )
  46. if err != nil {
  47. return nil, err
  48. }
  49. return payload.Entries, nil
  50. }