Documentation
¶
Overview ¶
Package keyenv provides a Go SDK for the KeyEnv secrets management service.
Package keyenv provides a Go SDK for the KeyEnv secrets management service.
Index ¶
- Constants
- Variables
- type BulkImportOptions
- type BulkImportResult
- type Client
- func (c *Client) BulkImport(ctx context.Context, projectID, environment string, secrets []SecretInput, ...) (*BulkImportResult, error)
- func (c *Client) BulkSetPermissions(ctx context.Context, projectID, environment string, ...) error
- func (c *Client) ClearAllCache()
- func (c *Client) ClearCache(projectID, environment string)
- func (c *Client) CreateEnvironment(ctx context.Context, projectID, name string, inheritsFrom *string) (*Environment, error)
- func (c *Client) CreateProject(ctx context.Context, teamID, name string) (*Project, error)
- func (c *Client) DeleteEnvironment(ctx context.Context, projectID, environment string) error
- func (c *Client) DeletePermission(ctx context.Context, projectID, environment, userID string) error
- func (c *Client) DeleteProject(ctx context.Context, projectID string) error
- func (c *Client) DeleteSecret(ctx context.Context, projectID, environment, key string) error
- func (c *Client) ExportSecrets(ctx context.Context, projectID, environment string) ([]SecretWithValueAndInheritance, error)
- func (c *Client) ExportSecretsAsMap(ctx context.Context, projectID, environment string) (map[string]string, error)
- func (c *Client) GenerateEnvFile(ctx context.Context, projectID, environment string) (string, error)
- func (c *Client) GetCurrentUser(ctx context.Context) (*CurrentUserResponse, error)
- func (c *Client) GetMyPermissions(ctx context.Context, projectID string) (*MyPermissionsResponse, error)
- func (c *Client) GetProject(ctx context.Context, projectID string) (*Project, error)
- func (c *Client) GetProjectDefaults(ctx context.Context, projectID string) ([]DefaultPermission, error)
- func (c *Client) GetSecret(ctx context.Context, projectID, environment, key string) (*SecretWithValue, error)
- func (c *Client) GetSecretHistory(ctx context.Context, projectID, environment, key string) ([]SecretHistory, error)
- func (c *Client) ListEnvironments(ctx context.Context, projectID string) ([]Environment, error)
- func (c *Client) ListPermissions(ctx context.Context, projectID, environment string) ([]Permission, error)
- func (c *Client) ListProjects(ctx context.Context) ([]Project, error)
- func (c *Client) ListSecrets(ctx context.Context, projectID, environment string) ([]SecretWithInheritance, error)
- func (c *Client) LoadEnv(ctx context.Context, projectID, environment string) (int, error)
- func (c *Client) SetPermission(ctx context.Context, projectID, environment, userID, role string) error
- func (c *Client) SetProjectDefaults(ctx context.Context, projectID string, defaults []DefaultPermission) error
- func (c *Client) SetSecret(ctx context.Context, projectID, environment, key, value string) error
- func (c *Client) SetSecretWithDescription(ctx context.Context, projectID, environment, key, value string, ...) error
- func (c *Client) ValidateToken(ctx context.Context) (*CurrentUserResponse, error)
- type Config
- type CurrentUserResponse
- type DefaultPermission
- type Environment
- type Error
- type MyPermissionsResponse
- type Permission
- type PermissionInput
- type Project
- type Secret
- type SecretHistory
- type SecretInput
- type SecretWithInheritance
- type SecretWithValue
- type SecretWithValueAndInheritance
- type ServiceToken
- type Team
- type User
Constants ¶
const ( // DefaultBaseURL is the default API endpoint. DefaultBaseURL = "https://api.keyenv.dev" // DefaultTimeout is the default HTTP request timeout. DefaultTimeout = 30 * time.Second // Version is the SDK version. Version = "1.0.0" )
Variables ¶
var ( ErrForbidden = &Error{Status: 403, Message: "Forbidden"} ErrNotFound = &Error{Status: 404, Message: "Not found"} ErrConflict = &Error{Status: 409, Message: "Conflict"} ErrRateLimited = &Error{Status: 429, Message: "Rate limited"} )
Common error variables for sentinel error checking.
Functions ¶
This section is empty.
Types ¶
type BulkImportOptions ¶
type BulkImportOptions struct {
// Overwrite controls whether existing secrets should be updated.
Overwrite bool `json:"overwrite"`
}
BulkImportOptions holds options for bulk import operations.
type BulkImportResult ¶
type BulkImportResult struct {
Created int `json:"created"`
Updated int `json:"updated"`
Skipped int `json:"skipped"`
}
BulkImportResult contains the results of a bulk import operation.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the KeyEnv API client.
func (*Client) BulkImport ¶
func (c *Client) BulkImport(ctx context.Context, projectID, environment string, secrets []SecretInput, options BulkImportOptions) (*BulkImportResult, error)
BulkImport imports multiple secrets at once.
func (*Client) BulkSetPermissions ¶
func (c *Client) BulkSetPermissions(ctx context.Context, projectID, environment string, permissions []PermissionInput) error
BulkSetPermissions sets multiple permissions at once.
func (*Client) ClearAllCache ¶
func (c *Client) ClearAllCache()
ClearAllCache clears all cached data.
func (*Client) ClearCache ¶
ClearCache clears the cache for a specific project/environment combination.
func (*Client) CreateEnvironment ¶
func (c *Client) CreateEnvironment(ctx context.Context, projectID, name string, inheritsFrom *string) (*Environment, error)
CreateEnvironment creates a new environment in a project.
func (*Client) CreateProject ¶
CreateProject creates a new project.
func (*Client) DeleteEnvironment ¶
DeleteEnvironment deletes an environment from a project.
func (*Client) DeletePermission ¶
DeletePermission removes a user's permission for an environment.
func (*Client) DeleteProject ¶
DeleteProject deletes a project.
func (*Client) DeleteSecret ¶
DeleteSecret deletes a secret by key.
func (*Client) ExportSecrets ¶
func (c *Client) ExportSecrets(ctx context.Context, projectID, environment string) ([]SecretWithValueAndInheritance, error)
ExportSecrets returns all secrets with their values for an environment.
func (*Client) ExportSecretsAsMap ¶
func (c *Client) ExportSecretsAsMap(ctx context.Context, projectID, environment string) (map[string]string, error)
ExportSecretsAsMap returns secrets as a key-value map.
func (*Client) GenerateEnvFile ¶
func (c *Client) GenerateEnvFile(ctx context.Context, projectID, environment string) (string, error)
GenerateEnvFile generates a .env file content string.
func (*Client) GetCurrentUser ¶
func (c *Client) GetCurrentUser(ctx context.Context) (*CurrentUserResponse, error)
GetCurrentUser returns information about the current authenticated user or service token.
func (*Client) GetMyPermissions ¶
func (c *Client) GetMyPermissions(ctx context.Context, projectID string) (*MyPermissionsResponse, error)
GetMyPermissions returns the current user's permissions for a project.
func (*Client) GetProject ¶
GetProject returns a project by ID including its environments.
func (*Client) GetProjectDefaults ¶
func (c *Client) GetProjectDefaults(ctx context.Context, projectID string) ([]DefaultPermission, error)
GetProjectDefaults returns the default permissions for a project.
func (*Client) GetSecret ¶
func (c *Client) GetSecret(ctx context.Context, projectID, environment, key string) (*SecretWithValue, error)
GetSecret returns a single secret by key.
func (*Client) GetSecretHistory ¶
func (c *Client) GetSecretHistory(ctx context.Context, projectID, environment, key string) ([]SecretHistory, error)
GetSecretHistory returns the version history of a secret.
func (*Client) ListEnvironments ¶
ListEnvironments returns all environments in a project.
func (*Client) ListPermissions ¶
func (c *Client) ListPermissions(ctx context.Context, projectID, environment string) ([]Permission, error)
ListPermissions returns permissions for an environment.
func (*Client) ListProjects ¶
ListProjects returns all projects accessible to the current user or service token.
func (*Client) ListSecrets ¶
func (c *Client) ListSecrets(ctx context.Context, projectID, environment string) ([]SecretWithInheritance, error)
ListSecrets returns secret keys (without values) for an environment.
func (*Client) LoadEnv ¶
LoadEnv loads secrets into environment variables. Returns the number of secrets loaded.
func (*Client) SetPermission ¶
func (c *Client) SetPermission(ctx context.Context, projectID, environment, userID, role string) error
SetPermission sets a user's permission for an environment.
func (*Client) SetProjectDefaults ¶
func (c *Client) SetProjectDefaults(ctx context.Context, projectID string, defaults []DefaultPermission) error
SetProjectDefaults sets the default permissions for a project.
func (*Client) SetSecretWithDescription ¶
func (c *Client) SetSecretWithDescription(ctx context.Context, projectID, environment, key, value string, description *string) error
SetSecretWithDescription creates or updates a secret with a description.
func (*Client) ValidateToken ¶
func (c *Client) ValidateToken(ctx context.Context) (*CurrentUserResponse, error)
ValidateToken validates the token and returns user info.
type Config ¶
type Config struct {
// Token is the service token for authentication (required).
Token string
// BaseURL is the API base URL (optional, defaults to https://api.keyenv.dev).
BaseURL string
// Timeout is the HTTP request timeout (optional, defaults to 30s).
Timeout time.Duration
// CacheTTL is the cache time-to-live duration (optional, 0 means disabled).
CacheTTL time.Duration
}
Config holds the configuration options for the KeyEnv client.
type CurrentUserResponse ¶
type CurrentUserResponse struct {
// Common fields
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
// Auth type: "service_token" or "user"
AuthType string `json:"auth_type,omitempty"`
// Service token fields (when auth_type is "service_token")
TeamID string `json:"team_id,omitempty"`
ProjectIDs []string `json:"project_ids,omitempty"`
Scopes []string `json:"scopes,omitempty"`
// User fields (when auth_type is "user" or not a service token)
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
ClerkID string `json:"clerk_id,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
// Legacy fields for backward compatibility
Type string `json:"type,omitempty"` // Deprecated: use AuthType
User *User `json:"user,omitempty"`
ServiceToken *ServiceToken `json:"service_token,omitempty"`
}
CurrentUserResponse contains information about the current authenticated user or token. For service tokens, it returns a flat structure with token info. For users, it returns the user profile with team memberships.
func (*CurrentUserResponse) IsServiceToken ¶
func (r *CurrentUserResponse) IsServiceToken() bool
IsServiceToken returns true if this response represents a service token.
type DefaultPermission ¶
type DefaultPermission struct {
EnvironmentName string `json:"environment_name"`
DefaultRole string `json:"default_role"`
}
DefaultPermission represents default permission settings for an environment.
type Environment ¶
type Environment struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
ProjectID string `json:"project_id"`
InheritsFromID *string `json:"inherits_from_id,omitempty"`
Order int `json:"order"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Environment represents a KeyEnv environment within a project.
type Error ¶
type Error struct {
// Status is the HTTP status code.
Status int `json:"status"`
// Message is the error message.
Message string `json:"message"`
// Code is an optional error code for programmatic handling.
Code string `json:"code,omitempty"`
}
Error represents an error returned by the KeyEnv API.
func (*Error) IsConflict ¶
IsConflict returns true if the error is a 409 Conflict error.
func (*Error) IsForbidden ¶
IsForbidden returns true if the error is a 403 Forbidden error.
func (*Error) IsNotFound ¶
IsNotFound returns true if the error is a 404 Not Found error.
func (*Error) IsRateLimited ¶
IsRateLimited returns true if the error is a 429 Too Many Requests error.
func (*Error) IsServerError ¶
IsServerError returns true if the error is a 5xx server error.
func (*Error) IsUnauthorized ¶
IsUnauthorized returns true if the error is a 401 Unauthorized error.
type MyPermissionsResponse ¶
type MyPermissionsResponse struct {
Permissions []Permission `json:"permissions"`
IsTeamAdmin bool `json:"is_team_admin"`
}
MyPermissionsResponse contains the current user's permissions.
type Permission ¶
type Permission struct {
ID string `json:"id"`
UserID string `json:"user_id"`
UserEmail string `json:"user_email"`
EnvironmentID string `json:"environment_id"`
EnvironmentName string `json:"environment_name,omitempty"`
Role string `json:"role"`
CanWrite bool `json:"can_write"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Permission represents a user's permission for an environment.
type PermissionInput ¶
PermissionInput represents input for setting a permission.
type Project ¶
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
TeamID string `json:"team_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Environments []Environment `json:"environments,omitempty"`
}
Project represents a KeyEnv project.
type Secret ¶
type Secret struct {
ID string `json:"id"`
Key string `json:"key"`
Description *string `json:"description,omitempty"`
EnvironmentID string `json:"environment_id"`
SecretType string `json:"secret_type,omitempty"`
Version int `json:"version"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Secret represents a secret's metadata without the value.
type SecretHistory ¶
type SecretHistory struct {
ID string `json:"id"`
SecretID string `json:"secret_id"`
Key string `json:"key"`
Version int `json:"version"`
ChangedBy *string `json:"changed_by,omitempty"`
ChangeType string `json:"change_type"`
CreatedAt time.Time `json:"created_at"`
}
SecretHistory represents a historical version of a secret.
type SecretInput ¶
type SecretInput struct {
Key string `json:"key"`
Value string `json:"value"`
Description *string `json:"description,omitempty"`
}
SecretInput represents input for creating or importing a secret.
type SecretWithInheritance ¶
type SecretWithInheritance struct {
Secret
InheritedFrom *string `json:"inherited_from,omitempty"`
}
SecretWithInheritance represents a secret with inheritance information.
type SecretWithValue ¶
SecretWithValue represents a secret including its decrypted value.
type SecretWithValueAndInheritance ¶
type SecretWithValueAndInheritance struct {
Secret
Value string `json:"value"`
InheritedFrom *string `json:"inherited_from,omitempty"`
}
SecretWithValueAndInheritance represents a secret with value and inheritance info.
type ServiceToken ¶
type ServiceToken struct {
ID string `json:"id"`
Name string `json:"name"`
ProjectID string `json:"project_id"`
ProjectName string `json:"project_name,omitempty"`
Permissions []string `json:"permissions"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
ServiceToken represents information about a service token.