beyondtrustworkloadcredentials.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 btwcutil provides utility types and functions for interacting with BeyondtrustWorkloadCredentials.
  14. package btwcutil
  15. import (
  16. "context"
  17. "net/url"
  18. )
  19. // VersionInfo represents version information for a secret or folder.
  20. type VersionInfo struct {
  21. Version int `json:"version"`
  22. CreatedAt string `json:"createdAt"`
  23. DeletedAt string `json:"deletedAt,omitempty"`
  24. }
  25. // SecretMetadata represents metadata for a secret, including tags and version information.
  26. type SecretMetadata struct {
  27. ID string `json:"id"`
  28. Tags map[string]string `json:"tags,omitempty"`
  29. Version int `json:"version,omitempty"`
  30. CreatedAt string `json:"createdAt,omitempty"`
  31. DeletedAt string `json:"deletedAt,omitempty"`
  32. CreatedBy string `json:"createdBy,omitempty"`
  33. }
  34. // KV represents a key-value secret with its metadata.
  35. type KV struct {
  36. Secret map[string]any `json:"secret"`
  37. Type string `json:"type,omitempty"`
  38. Path string `json:"path,omitempty"`
  39. Metadata *SecretMetadata `json:"metadata,omitempty"`
  40. Versions []VersionInfo `json:"versions,omitempty"`
  41. }
  42. // KVListItem represents a minimal secret list item.
  43. type KVListItem struct {
  44. Path string `json:"path"`
  45. Type string `json:"type"`
  46. Metadata *SecretMetadata `json:"metadata,omitempty"`
  47. Versions []VersionInfo `json:"versions,omitempty"`
  48. }
  49. // GeneratedSecret represents a dynamically generated secret response.
  50. type GeneratedSecret struct {
  51. AccessKeyID string `json:"accessKeyId"`
  52. SecretAccessKey string `json:"secretAccessKey"`
  53. SessionToken string `json:"sessionToken,omitempty"`
  54. LeaseID string `json:"leaseId"`
  55. Expiration string `json:"expiration"`
  56. }
  57. // Client defines the interface for a BeyondtrustWorkloadCredentials client with methods for secret operations.
  58. type Client interface {
  59. BaseURL() *url.URL
  60. SetBaseURL(urlStr string) error
  61. CheckSession(ctx context.Context) error
  62. GetSecret(ctx context.Context, name string, folderPath *string) (*KV, error)
  63. GetSecrets(ctx context.Context, folderPath *string, recursive bool) ([]KVListItem, error)
  64. GenerateDynamicSecret(ctx context.Context, name string, folderPath *string) (*GeneratedSecret, error)
  65. }