Documentation
¶
Index ¶
- Constants
- func Backend() *backend
- func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error)
- func SanitizeServiceAccountName(name string) string
- func ValidateServiceAccountName(name string) error
- type APIKey
- type ActiveLease
- type CleanupManager
- type Client
- func (c *Client) CreateAdminAPIKey(ctx context.Context, name string) (string, string, error)
- func (c *Client) CreateServiceAccount(ctx context.Context, projectID string, req CreateServiceAccountRequest) (*ServiceAccount, *APIKey, error)
- func (c *Client) DeleteAPIKey(ctx context.Context, id string) error
- func (c *Client) DeleteServiceAccount(ctx context.Context, id string, projectID ...string) error
- func (c *Client) GetAdminAPIKey(ctx context.Context, keyID string) (map[string]interface{}, error)
- func (c *Client) GetProject(ctx context.Context, projectID string) (*ProjectInfo, error)
- func (c *Client) GetServiceAccount(ctx context.Context, id string, projectID string) (*ServiceAccount, error)
- func (c *Client) ListAdminAPIKeys(ctx context.Context) ([]map[string]interface{}, error)
- func (c *Client) ListServiceAccounts(ctx context.Context, projectID string) ([]*ServiceAccount, error)
- func (c *Client) RevokeAdminAPIKey(ctx context.Context, keyID string) error
- func (c *Client) SetConfig(config *Config) error
- func (c *Client) TestConnection(ctx context.Context) error
- func (c *Client) ValidateProject(ctx context.Context, projectID string) error
- type ClientAPI
- type Config
- type CreateServiceAccountRequest
- type IncrCounterWithLabelsFuncType
- type Label
- type Project
- type ProjectInfo
- type ServiceAccount
- type ServiceAccountResponse
- type UnixTime
Constants ¶
const (
// Default API endpoint for OpenAI
DefaultAPIEndpoint = "https://api.openai.com/v1"
)
Variables ¶
This section is empty.
Functions ¶
func SanitizeServiceAccountName ¶
SanitizeServiceAccountName modifies a name to conform to service account naming best practices This ensures names will be compatible with the OpenAI API and follow standard conventions for cloud resource naming
func ValidateServiceAccountName ¶
ValidateServiceAccountName validates a service account name based on common API naming conventions and observed behavior with the OpenAI API. These constraints help ensure compatibility with OpenAI's platform requirements.
Types ¶
type APIKey ¶
type APIKey struct {
ID string `json:"id"`
Value string `json:"value,omitempty"`
Name string `json:"name"`
ServiceAccID string `json:"service_account_id"`
CreatedAt *UnixTime `json:"created_at,omitempty"`
ExpiresAt *UnixTime `json:"expires_at,omitempty"`
}
APIKey represents an OpenAI API key
func (*APIKey) GetCreatedAt ¶
GetCreatedAt returns the created_at time as a time.Time pointer
func (*APIKey) GetExpiresAt ¶
GetExpiresAt returns the expires_at time as a time.Time pointer
func (*APIKey) MarshalJSON ¶
MarshalJSON implements custom marshaling for APIKey
type ActiveLease ¶
type ActiveLease struct {
RoleName string `json:"role_name"`
ServiceAccountID string `json:"service_account_id"`
ProjectID string `json:"project_id"`
}
ActiveLease represents an active service account lease
type CleanupManager ¶
type CleanupManager struct {
// contains filtered or unexported fields
}
CleanupManager handles periodic cleanup of orphaned service accounts and expired API keys
func NewCleanupManager ¶
func NewCleanupManager(b *backend) *CleanupManager
NewCleanupManager creates a new cleanup manager
func (*CleanupManager) RunCleanup ¶
func (c *CleanupManager) RunCleanup(ctx context.Context) error
RunCleanup performs a single cleanup operation
func (*CleanupManager) SetInterval ¶
func (c *CleanupManager) SetInterval(interval time.Duration)
SetInterval changes the cleanup interval
func (*CleanupManager) Start ¶
func (c *CleanupManager) Start()
Start begins the periodic cleanup process
func (*CleanupManager) Stop ¶
func (c *CleanupManager) Stop()
Stop gracefully shuts down the cleanup manager
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an OpenAI API client
func (*Client) CreateAdminAPIKey ¶
CreateAdminAPIKey creates a new admin API key and returns its value and ID
func (*Client) CreateServiceAccount ¶
func (c *Client) CreateServiceAccount(ctx context.Context, projectID string, req CreateServiceAccountRequest) (*ServiceAccount, *APIKey, error)
CreateServiceAccount creates a new project service account and returns both the service account and API key in a single operation, as per the actual OpenAI API behavior.
func (*Client) DeleteAPIKey ¶
DeleteAPIKey deletes an API key by ID
func (*Client) DeleteServiceAccount ¶
DeleteServiceAccount deletes a service account by ID
func (*Client) GetAdminAPIKey ¶
GetAdminAPIKey retrieves details for a specific admin API key by ID.
func (*Client) GetProject ¶
GetProject fetches project details from OpenAI API by project ID
func (*Client) GetServiceAccount ¶
func (c *Client) GetServiceAccount(ctx context.Context, id string, projectID string) (*ServiceAccount, error)
GetServiceAccount gets a service account by ID
func (*Client) ListAdminAPIKeys ¶
ListAdminAPIKeys lists all admin API keys
func (*Client) ListServiceAccounts ¶
func (c *Client) ListServiceAccounts(ctx context.Context, projectID string) ([]*ServiceAccount, error)
ListServiceAccounts returns all service accounts for a project
func (*Client) RevokeAdminAPIKey ¶
RevokeAdminAPIKey revokes the given admin API key
func (*Client) TestConnection ¶
TestConnection tests the client connection by listing admin API keys
type ClientAPI ¶
type ClientAPI interface {
CreateServiceAccount(ctx context.Context, projectID string, req CreateServiceAccountRequest) (*ServiceAccount, *APIKey, error)
DeleteServiceAccount(ctx context.Context, id string, projectID ...string) error
DeleteAPIKey(ctx context.Context, id string) error
SetConfig(config *Config) error
ListServiceAccounts(ctx context.Context, projectID string) ([]*ServiceAccount, error)
GetServiceAccount(ctx context.Context, serviceAccountID, projectID string) (*ServiceAccount, error)
ValidateProject(ctx context.Context, projectID string) error
GetProject(ctx context.Context, projectID string) (*ProjectInfo, error)
}
ClientAPI defines the interface for OpenAI client operations used by the backend This allows for mocking in tests.
type Config ¶
type Config struct {
AdminAPIKey string `json:"admin_api_key"`
AdminAPIKeyID string `json:"admin_api_key_id,omitempty"`
APIEndpoint string `json:"api_endpoint"`
OrganizationID string `json:"organization_id"`
}
Config contains configuration for the OpenAI client Add AdminAPIKeyID to track the key's ID for revocation
type CreateServiceAccountRequest ¶
type CreateServiceAccountRequest struct {
Name string `json:"name"`
}
CreateServiceAccountRequest represents a request to create a service account Only Name is supported by OpenAI Removed Description field
type IncrCounterWithLabelsFuncType ¶
type IncrCounterWithLabelsFuncType func(ctx context.Context, name []string, value float32, labels []Label)
IncrCounterWithLabelsFuncType defines the function signature for metric emission so it can be swapped in tests.
var IncrCounterWithLabels IncrCounterWithLabelsFuncType = func(ctx context.Context, name []string, value float32, labels []Label) { var mLabels []metrics.Label for _, l := range labels { mLabels = append(mLabels, metrics.Label{Name: l.Name, Value: l.Value}) } metrics.IncrCounterWithLabels(name, value, mLabels) }
IncrCounterWithLabels is a variable so it can be replaced in tests.
type ProjectInfo ¶
type ProjectInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
}
ProjectInfo represents the OpenAI project details response Used for project validation and caching
type ServiceAccount ¶
type ServiceAccount struct {
ID string `json:"id"`
ProjectID string `json:"project_id"`
Name string `json:"name"`
Role string `json:"role,omitempty"`
CreatedAt *UnixTime `json:"created_at,omitempty"`
}
ServiceAccount represents an OpenAI project service account Updated: OpenAI does not support a description field for service accounts Added Role field per API response Removed Description field
func (*ServiceAccount) GetCreatedAt ¶
func (sa *ServiceAccount) GetCreatedAt() *time.Time
GetCreatedAt returns the created_at time as a time.Time pointer
func (*ServiceAccount) MarshalJSON ¶
func (sa *ServiceAccount) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshaling for ServiceAccount
type ServiceAccountResponse ¶
type ServiceAccountResponse struct {
ServiceAccount *ServiceAccount `json:"service_account"`
APIKey *APIKey `json:"api_key"`
}
ServiceAccountResponse represents the API response for creating a service account. It includes both the service account and the associated API key.
type UnixTime ¶
UnixTime wraps time.Time for custom UnmarshalJSON implementation to handle Unix timestamp formats from the OpenAI API
func UnixTimePtr ¶
UnixTimePtr converts a time.Time pointer to a UnixTime pointer
func (UnixTime) MarshalJSON ¶
MarshalJSON converts the UnixTime back to JSON
func (*UnixTime) UnmarshalJSON ¶
UnmarshalJSON implements custom unmarshaling for Unix timestamps It handles timestamps in seconds (integer), RFC3339 format (string), or null