grpc.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 grpc
  13. import (
  14. "context"
  15. "github.com/yandex-cloud/go-genproto/yandex/cloud/lockbox/v1"
  16. ycsdk "github.com/yandex-cloud/go-sdk"
  17. "github.com/yandex-cloud/go-sdk/iamkey"
  18. "github.com/external-secrets/external-secrets/pkg/provider/yandex/lockbox/client"
  19. )
  20. // Implementation of LockboxClientCreator.
  21. type LockboxClientCreator struct {
  22. }
  23. func (lb *LockboxClientCreator) Create(ctx context.Context, authorizedKey *iamkey.Key) (client.LockboxClient, error) {
  24. credentials, err := ycsdk.ServiceAccountKey(authorizedKey)
  25. if err != nil {
  26. return nil, err
  27. }
  28. sdk, err := ycsdk.Build(ctx, ycsdk.Config{
  29. Credentials: credentials,
  30. })
  31. if err != nil {
  32. return nil, err
  33. }
  34. return &LockboxClient{sdk}, nil
  35. }
  36. // Implementation of LockboxClient.
  37. type LockboxClient struct {
  38. sdk *ycsdk.SDK
  39. }
  40. func (lb *LockboxClient) GetPayloadEntries(ctx context.Context, secretID, versionID string) ([]*lockbox.Payload_Entry, error) {
  41. payload, err := lb.sdk.LockboxPayload().Payload().Get(ctx, &lockbox.GetPayloadRequest{
  42. SecretId: secretID,
  43. VersionId: versionID,
  44. })
  45. if err != nil {
  46. return nil, err
  47. }
  48. return payload.Entries, nil
  49. }
  50. func (lb *LockboxClient) Close(ctx context.Context) error {
  51. err := lb.sdk.Shutdown(ctx)
  52. if err != nil {
  53. return err
  54. }
  55. return nil
  56. }