fake.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 impliec.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package fake
  13. import (
  14. "errors"
  15. "time"
  16. "github.com/external-secrets/external-secrets/pkg/provider/infisical/api"
  17. )
  18. var (
  19. ErrMissingMockImplementation = errors.New("missing mock implmentation")
  20. )
  21. type MockInfisicalClient struct {
  22. MockedGetSecretV3 func(data api.GetSecretsV3Request) (map[string]string, error)
  23. MockedGetSecretByKeyV3 func(data api.GetSecretByKeyV3Request) (string, error)
  24. }
  25. func (a *MockInfisicalClient) MachineIdentityLoginViaUniversalAuth(data api.MachineIdentityUniversalAuthLoginRequest) (*api.MachineIdentityDetailsResponse, error) {
  26. return &api.MachineIdentityDetailsResponse{
  27. AccessToken: "test-access-token",
  28. ExpiresIn: int(time.Hour * 24),
  29. TokenType: "bearer",
  30. AccessTokenMaxTTL: int(time.Hour * 24 * 2),
  31. }, nil
  32. }
  33. func (a *MockInfisicalClient) GetSecretsV3(data api.GetSecretsV3Request) (map[string]string, error) {
  34. if a.MockedGetSecretV3 == nil {
  35. return nil, ErrMissingMockImplementation
  36. }
  37. return a.MockedGetSecretV3(data)
  38. }
  39. func (a *MockInfisicalClient) GetSecretByKeyV3(data api.GetSecretByKeyV3Request) (string, error) {
  40. if a.MockedGetSecretByKeyV3 == nil {
  41. return "", ErrMissingMockImplementation
  42. }
  43. return a.MockedGetSecretByKeyV3(data)
  44. }
  45. func (a *MockInfisicalClient) RevokeAccessToken() error {
  46. return nil
  47. }