conjur_api.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Copyright © The ESO 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. https://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 conjur
  14. import (
  15. "github.com/cyberark/conjur-api-go/conjurapi"
  16. "github.com/cyberark/conjur-api-go/conjurapi/authn"
  17. )
  18. // SecretsClient is an interface for the Conjur client.
  19. type SecretsClient interface {
  20. RetrieveSecret(secret string) (result []byte, err error)
  21. RetrieveBatchSecrets(variableIDs []string) (map[string][]byte, error)
  22. Resources(filter *conjurapi.ResourceFilter) (resources []map[string]any, err error)
  23. }
  24. // SecretsClientFactory is an interface for creating a Conjur client.
  25. type SecretsClientFactory interface {
  26. NewClientFromKey(config conjurapi.Config, loginPair authn.LoginPair) (SecretsClient, error)
  27. NewClientFromJWT(config conjurapi.Config) (SecretsClient, error)
  28. }
  29. // ClientAPIImpl is an implementation of the ClientAPI interface.
  30. type ClientAPIImpl struct{}
  31. // NewClientFromKey creates a new Conjur client using API key authentication.
  32. func (c *ClientAPIImpl) NewClientFromKey(config conjurapi.Config, loginPair authn.LoginPair) (SecretsClient, error) {
  33. return conjurapi.NewClientFromKey(config, loginPair)
  34. }
  35. // NewClientFromJWT creates a new Conjur client from a JWT token.
  36. func (c *ClientAPIImpl) NewClientFromJWT(config conjurapi.Config) (SecretsClient, error) {
  37. return conjurapi.NewClientFromJwt(config)
  38. }