api

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient interface {
	// Auth methods
	StartDeviceLogin(ctx context.Context, repository string, repoIds *RepoIds) (*DeviceStartResponse, error)
	PollDeviceLogin(ctx context.Context, deviceCode string) (*DevicePollResponse, error)
	ValidateToken(ctx context.Context) (*ValidateTokenResponse, error)
	CheckGitHubAppInstallation(ctx context.Context, repoOwner, repoName string) (*GitHubAppInstallationStatus, error)
	GetRepoIdsFromBackend(ctx context.Context, repoFullName string) (*RepoIds, error)

	// Vault methods
	InitVault(ctx context.Context, repoFullName string) (*InitVaultResponse, error)
	CheckVaultExists(ctx context.Context, repoFullName string) (bool, error)
	GetVaultDetails(ctx context.Context, repoFullName string) (*VaultDetails, error)
	GetVaultEnvironments(ctx context.Context, repoFullName string) ([]string, error)

	// Org methods
	StartOrganizationTrial(ctx context.Context, orgLogin string) (*StartTrialResponse, error)

	// Secrets methods
	PushSecrets(ctx context.Context, repo, env string, secrets map[string]string) (*PushSecretsResponse, error)
	PullSecrets(ctx context.Context, repo, env string) (*PullSecretsResponse, error)

	// Provider methods
	GetProviders(ctx context.Context) ([]Provider, error)
	GetConnections(ctx context.Context) ([]Connection, error)
	DeleteConnection(ctx context.Context, connectionID string) error
	GetProviderAuthURL(provider string) string
	ConnectWithToken(ctx context.Context, provider, providerToken string) (*ConnectTokenResponse, error)
	GetAllProviderProjects(ctx context.Context, provider string) ([]ProviderProject, []Connection, error)

	// Sync methods
	GetSyncStatus(ctx context.Context, repo, connectionID, projectID, environment string) (*SyncStatus, error)
	GetSyncDiff(ctx context.Context, repo string, opts SyncOptions) (*SyncDiff, error)
	GetSyncPreview(ctx context.Context, repo string, opts SyncOptions) (*SyncPreview, error)
	ExecuteSync(ctx context.Context, repo string, opts SyncOptions) (*SyncResult, error)
}

APIClient defines the interface for the Keyway API client This interface enables mocking in tests

type APIError

type APIError struct {
	StatusCode int               `json:"-"`
	Type       string            `json:"type,omitempty"`
	Title      string            `json:"title,omitempty"`
	Detail     string            `json:"detail,omitempty"`
	UpgradeURL string            `json:"upgradeUrl,omitempty"`
	TrialInfo  *TrialEligibility `json:"trialInfo,omitempty"`
}

APIError represents an error from the API (RFC 7807)

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the Keyway API client

func NewClient

func NewClient(token string) *Client

NewClient creates a new API client

func NewClientWithVersion

func NewClientWithVersion(token, version string) *Client

NewClientWithVersion creates a new API client with version

func (*Client) CanStartTrial

func (c *Client) CanStartTrial(ctx context.Context, orgLogin string) (bool, int, error)

CanStartTrial checks if an organization can start a trial

func (*Client) CheckGitHubAppInstallation

func (c *Client) CheckGitHubAppInstallation(ctx context.Context, repoOwner, repoName string) (*GitHubAppInstallationStatus, error)

CheckGitHubAppInstallation checks if the GitHub App is installed for a repo

func (*Client) CheckVaultExists

func (c *Client) CheckVaultExists(ctx context.Context, repoFullName string) (bool, error)

CheckVaultExists checks if a vault exists for a repository

func (*Client) ConnectWithToken

func (c *Client) ConnectWithToken(ctx context.Context, provider, providerToken string) (*ConnectTokenResponse, error)

ConnectWithToken connects to a provider using a token (e.g., Railway)

func (*Client) DeleteConnection

func (c *Client) DeleteConnection(ctx context.Context, connectionID string) error

DeleteConnection removes a provider connection

func (*Client) ExecuteSync

func (c *Client) ExecuteSync(ctx context.Context, repo string, opts SyncOptions) (*SyncResult, error)

ExecuteSync performs the sync operation

func (*Client) GetAllProviderProjects

func (c *Client) GetAllProviderProjects(ctx context.Context, provider string) ([]ProviderProject, []Connection, error)

GetAllProviderProjects returns all projects from all connections for a provider

func (*Client) GetConnections

func (c *Client) GetConnections(ctx context.Context) ([]Connection, error)

GetConnections returns user's provider connections

func (*Client) GetOrganization

func (c *Client) GetOrganization(ctx context.Context, orgLogin string) (*OrganizationInfo, error)

GetOrganization retrieves information about an organization

func (*Client) GetProviderAuthURL

func (c *Client) GetProviderAuthURL(provider string) string

GetProviderAuthURL returns the OAuth URL for a provider

func (*Client) GetProviders

func (c *Client) GetProviders(ctx context.Context) ([]Provider, error)

GetProviders returns available providers

func (*Client) GetRepoIdsFromBackend

func (c *Client) GetRepoIdsFromBackend(ctx context.Context, repoFullName string) (*RepoIds, error)

GetRepoIdsFromBackend fetches repo IDs from the backend Works for private repos if GitHub App is installed with "all repos" on the org

func (*Client) GetSyncDiff

func (c *Client) GetSyncDiff(ctx context.Context, repo string, opts SyncOptions) (*SyncDiff, error)

GetSyncDiff returns the diff between Keyway and provider secrets

func (*Client) GetSyncPreview

func (c *Client) GetSyncPreview(ctx context.Context, repo string, opts SyncOptions) (*SyncPreview, error)

GetSyncPreview returns what will change during sync

func (*Client) GetSyncStatus

func (c *Client) GetSyncStatus(ctx context.Context, repo, connectionID, projectID, environment string) (*SyncStatus, error)

GetSyncStatus returns the sync status for a vault/project pair

func (*Client) GetVaultDetails added in v0.5.1

func (c *Client) GetVaultDetails(ctx context.Context, repoFullName string) (*VaultDetails, error)

GetVaultDetails returns detailed information about a vault including secret count

func (*Client) GetVaultEnvironments

func (c *Client) GetVaultEnvironments(ctx context.Context, repoFullName string) ([]string, error)

GetVaultEnvironments returns the environments for a vault

func (*Client) InitVault

func (c *Client) InitVault(ctx context.Context, repoFullName string) (*InitVaultResponse, error)

InitVault creates a new vault for a repository

func (*Client) LinkProject added in v0.5.2

func (c *Client) LinkProject(ctx context.Context, repo string, opts SyncOptions) (*ProjectLink, error)

LinkProject links a vault to a provider project without syncing

func (*Client) PollDeviceLogin

func (c *Client) PollDeviceLogin(ctx context.Context, deviceCode string) (*DevicePollResponse, error)

PollDeviceLogin polls for device login completion

func (*Client) PullSecrets

func (c *Client) PullSecrets(ctx context.Context, repo, env string) (*PullSecretsResponse, error)

PullSecrets downloads secrets from the vault

func (*Client) PushSecrets

func (c *Client) PushSecrets(ctx context.Context, repo, env string, secrets map[string]string) (*PushSecretsResponse, error)

PushSecrets uploads secrets to the vault

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout sets a custom timeout for requests

func (*Client) StartDeviceLogin

func (c *Client) StartDeviceLogin(ctx context.Context, repository string, repoIds *RepoIds) (*DeviceStartResponse, error)

StartDeviceLogin initiates the device login flow

func (*Client) StartOrganizationTrial

func (c *Client) StartOrganizationTrial(ctx context.Context, orgLogin string) (*StartTrialResponse, error)

StartOrganizationTrial starts a trial for an organization

func (*Client) ValidateToken

func (c *Client) ValidateToken(ctx context.Context) (*ValidateTokenResponse, error)

ValidateToken validates the current token

type ConnectTokenResponse

type ConnectTokenResponse struct {
	Success bool `json:"success"`
	User    struct {
		Username string  `json:"username"`
		TeamName *string `json:"teamName,omitempty"`
	} `json:"user"`
}

ConnectTokenResponse represents the response from token-based connection

type Connection

type Connection struct {
	ID             string  `json:"id"`
	Provider       string  `json:"provider"`
	ProviderTeamID *string `json:"providerTeamId,omitempty"`
	CreatedAt      string  `json:"createdAt"`
}

Connection represents a provider connection

type DevicePollResponse

type DevicePollResponse struct {
	Status      string `json:"status"` // pending, approved, expired, denied
	KeywayToken string `json:"keywayToken,omitempty"`
	GitHubLogin string `json:"githubLogin,omitempty"`
	ExpiresAt   string `json:"expiresAt,omitempty"`
	Message     string `json:"message,omitempty"`
}

DevicePollResponse is the response from polling device login

type DeviceStartResponse

type DeviceStartResponse struct {
	DeviceCode              string `json:"deviceCode"`
	UserCode                string `json:"userCode"`
	VerificationURIComplete string `json:"verificationUriComplete"`
	VerificationURI         string `json:"verificationUri"`
	ExpiresIn               int    `json:"expiresIn"`
	Interval                int    `json:"interval"`
	GitHubAppInstallURL     string `json:"githubAppInstallUrl,omitempty"`
}

DeviceStartResponse is the response from starting device login

type GitHubAppInstallationStatus

type GitHubAppInstallationStatus struct {
	Installed      bool   `json:"installed"`
	InstallationID int    `json:"installationId,omitempty"`
	InstallURL     string `json:"installUrl"`
	Message        string `json:"message,omitempty"`
}

GitHubAppInstallationStatus is the status of GitHub App installation

type InitVaultResponse

type InitVaultResponse struct {
	VaultID      string `json:"vaultId"`
	RepoFullName string `json:"repoFullName"`
	Message      string `json:"message"`
}

InitVaultResponse is the response from initializing a vault

type MockClient

type MockClient struct {
	// Auth mocks
	StartDeviceLoginFn           func(ctx context.Context, repository string, repoIds *RepoIds) (*DeviceStartResponse, error)
	PollDeviceLoginFn            func(ctx context.Context, deviceCode string) (*DevicePollResponse, error)
	ValidateTokenFn              func(ctx context.Context) (*ValidateTokenResponse, error)
	CheckGitHubAppInstallationFn func(ctx context.Context, repoOwner, repoName string) (*GitHubAppInstallationStatus, error)
	GetRepoIdsFromBackendFn      func(ctx context.Context, repoFullName string) (*RepoIds, error)

	// Vault mocks
	InitVaultFn            func(ctx context.Context, repoFullName string) (*InitVaultResponse, error)
	CheckVaultExistsFn     func(ctx context.Context, repoFullName string) (bool, error)
	GetVaultDetailsFn      func(ctx context.Context, repoFullName string) (*VaultDetails, error)
	GetVaultEnvironmentsFn func(ctx context.Context, repoFullName string) ([]string, error)

	// Secrets mocks
	PushSecretsFn func(ctx context.Context, repo, env string, secrets map[string]string) (*PushSecretsResponse, error)
	PullSecretsFn func(ctx context.Context, repo, env string) (*PullSecretsResponse, error)

	// Provider mocks
	GetProvidersFn           func(ctx context.Context) ([]Provider, error)
	GetConnectionsFn         func(ctx context.Context) ([]Connection, error)
	DeleteConnectionFn       func(ctx context.Context, connectionID string) error
	GetProviderAuthURLFn     func(provider string) string
	ConnectWithTokenFn       func(ctx context.Context, provider, providerToken string) (*ConnectTokenResponse, error)
	GetAllProviderProjectsFn func(ctx context.Context, provider string) ([]ProviderProject, []Connection, error)

	// Sync mocks
	GetSyncStatusFn  func(ctx context.Context, repo, connectionID, projectID, environment string) (*SyncStatus, error)
	GetSyncDiffFn    func(ctx context.Context, repo string, opts SyncOptions) (*SyncDiff, error)
	GetSyncPreviewFn func(ctx context.Context, repo string, opts SyncOptions) (*SyncPreview, error)
	ExecuteSyncFn    func(ctx context.Context, repo string, opts SyncOptions) (*SyncResult, error)

	// Call tracking
	Calls map[string]int
}

MockClient is a mock implementation of APIClient for testing

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client with default implementations

func (*MockClient) CheckGitHubAppInstallation

func (m *MockClient) CheckGitHubAppInstallation(ctx context.Context, repoOwner, repoName string) (*GitHubAppInstallationStatus, error)

func (*MockClient) CheckVaultExists

func (m *MockClient) CheckVaultExists(ctx context.Context, repoFullName string) (bool, error)

func (*MockClient) ConnectWithToken

func (m *MockClient) ConnectWithToken(ctx context.Context, provider, providerToken string) (*ConnectTokenResponse, error)

func (*MockClient) DeleteConnection

func (m *MockClient) DeleteConnection(ctx context.Context, connectionID string) error

func (*MockClient) ExecuteSync

func (m *MockClient) ExecuteSync(ctx context.Context, repo string, opts SyncOptions) (*SyncResult, error)

func (*MockClient) GetAllProviderProjects

func (m *MockClient) GetAllProviderProjects(ctx context.Context, provider string) ([]ProviderProject, []Connection, error)

func (*MockClient) GetConnections

func (m *MockClient) GetConnections(ctx context.Context) ([]Connection, error)

func (*MockClient) GetProviderAuthURL

func (m *MockClient) GetProviderAuthURL(provider string) string

func (*MockClient) GetProviders

func (m *MockClient) GetProviders(ctx context.Context) ([]Provider, error)

Provider methods

func (*MockClient) GetRepoIdsFromBackend

func (m *MockClient) GetRepoIdsFromBackend(ctx context.Context, repoFullName string) (*RepoIds, error)

func (*MockClient) GetSyncDiff

func (m *MockClient) GetSyncDiff(ctx context.Context, repo string, opts SyncOptions) (*SyncDiff, error)

func (*MockClient) GetSyncPreview

func (m *MockClient) GetSyncPreview(ctx context.Context, repo string, opts SyncOptions) (*SyncPreview, error)

func (*MockClient) GetSyncStatus

func (m *MockClient) GetSyncStatus(ctx context.Context, repo, connectionID, projectID, environment string) (*SyncStatus, error)

Sync methods

func (*MockClient) GetVaultDetails added in v0.5.1

func (m *MockClient) GetVaultDetails(ctx context.Context, repoFullName string) (*VaultDetails, error)

func (*MockClient) GetVaultEnvironments

func (m *MockClient) GetVaultEnvironments(ctx context.Context, repoFullName string) ([]string, error)

func (*MockClient) InitVault

func (m *MockClient) InitVault(ctx context.Context, repoFullName string) (*InitVaultResponse, error)

Vault methods

func (*MockClient) PollDeviceLogin

func (m *MockClient) PollDeviceLogin(ctx context.Context, deviceCode string) (*DevicePollResponse, error)

func (*MockClient) PullSecrets

func (m *MockClient) PullSecrets(ctx context.Context, repo, env string) (*PullSecretsResponse, error)

func (*MockClient) PushSecrets

func (m *MockClient) PushSecrets(ctx context.Context, repo, env string, secrets map[string]string) (*PushSecretsResponse, error)

Secrets methods

func (*MockClient) StartDeviceLogin

func (m *MockClient) StartDeviceLogin(ctx context.Context, repository string, repoIds *RepoIds) (*DeviceStartResponse, error)

Auth methods

func (*MockClient) StartOrganizationTrial

func (m *MockClient) StartOrganizationTrial(ctx context.Context, orgLogin string) (*StartTrialResponse, error)

func (*MockClient) ValidateToken

func (m *MockClient) ValidateToken(ctx context.Context) (*ValidateTokenResponse, error)

type OrganizationInfo

type OrganizationInfo struct {
	ID            string    `json:"id"`
	Login         string    `json:"login"`
	DisplayName   string    `json:"display_name"`
	AvatarURL     string    `json:"avatar_url"`
	Plan          string    `json:"plan"`
	EffectivePlan string    `json:"effective_plan"`
	MemberCount   int       `json:"member_count"`
	VaultCount    int       `json:"vault_count"`
	Trial         TrialInfo `json:"trial"`
	Role          string    `json:"role"`
}

OrganizationInfo contains information about an organization

type ProjectLink struct {
	ID                  string  `json:"id"`
	ProjectID           string  `json:"projectId"`
	ProjectName         *string `json:"projectName"`
	KeywayEnvironment   string  `json:"keywayEnvironment"`
	ProviderEnvironment string  `json:"providerEnvironment"`
	LastSyncedAt        *string `json:"lastSyncedAt"`
	IsNew               bool    `json:"isNew"`
}

ProjectLink represents a link between a vault and a provider project

type Provider

type Provider struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	Configured  bool   `json:"configured"`
}

Provider represents a supported provider

type ProviderProject

type ProviderProject struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	ServiceID    *string  `json:"serviceId,omitempty"`   // Railway: service ID
	ServiceName  *string  `json:"serviceName,omitempty"` // Railway: service name
	LinkedRepo   *string  `json:"linkedRepo,omitempty"`
	Environments []string `json:"environments,omitempty"`
	ConnectionID string   `json:"connectionId"`
	TeamID       *string  `json:"teamId,omitempty"`
	TeamName     *string  `json:"teamName,omitempty"`
}

ProviderProject represents a project from a provider

type PullSecretsResponse

type PullSecretsResponse struct {
	Content string `json:"content"`
}

PullSecretsResponse is the response from pulling secrets

type PushSecretsResponse

type PushSecretsResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Stats   *struct {
		Created int `json:"created"`
		Updated int `json:"updated"`
		Deleted int `json:"deleted"`
	} `json:"stats,omitempty"`
}

PushSecretsResponse is the response from pushing secrets

type RepoIds

type RepoIds struct {
	OwnerID int `json:"ownerId"`
	RepoID  int `json:"repoId"`
}

RepoIds contains GitHub repository IDs for deep linking

func GetRepoIdsFromGitHub

func GetRepoIdsFromGitHub(ctx context.Context, owner, repo string) (*RepoIds, error)

GetRepoIdsFromGitHub fetches repo IDs from GitHub public API Only works for public repos (no auth required)

type StartTrialResponse

type StartTrialResponse struct {
	Message   string `json:"message"`
	TrialEnds string `json:"trial_ends"`
}

StartTrialResponse is the response from starting a trial

type SyncDiff

type SyncDiff struct {
	KeywayCount    int      `json:"keywayCount"`
	ProviderCount  int      `json:"providerCount"`
	OnlyInKeyway   []string `json:"onlyInKeyway"`
	OnlyInProvider []string `json:"onlyInProvider"`
	Different      []string `json:"different"`
	Same           []string `json:"same"`
}

SyncDiff represents the difference between Keyway and provider secrets

type SyncOptions

type SyncOptions struct {
	ConnectionID        string  `json:"connectionId"`
	ProjectID           string  `json:"projectId"`
	ServiceID           *string `json:"serviceId,omitempty"`
	KeywayEnvironment   string  `json:"keywayEnvironment"`
	ProviderEnvironment string  `json:"providerEnvironment"`
	Direction           string  `json:"direction,omitempty"` // "push" or "pull"
	AllowDelete         bool    `json:"allowDelete,omitempty"`
}

SyncOptions contains options for sync operations

type SyncPreview

type SyncPreview struct {
	ToCreate []string `json:"toCreate"`
	ToUpdate []string `json:"toUpdate"`
	ToDelete []string `json:"toDelete"`
	ToSkip   []string `json:"toSkip"`
}

SyncPreview represents what will change during sync

type SyncResult

type SyncResult struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
	Stats   struct {
		Created int `json:"created"`
		Updated int `json:"updated"`
		Deleted int `json:"deleted"`
	} `json:"stats"`
}

SyncResult represents the result of a sync operation

type SyncStatus

type SyncStatus struct {
	IsFirstSync         bool `json:"isFirstSync"`
	VaultIsEmpty        bool `json:"vaultIsEmpty"`
	ProviderHasSecrets  bool `json:"providerHasSecrets"`
	ProviderSecretCount int  `json:"providerSecretCount"`
}

SyncStatus represents the current sync status

type TrialEligibility

type TrialEligibility struct {
	Eligible      bool   `json:"eligible"`
	DaysAvailable int    `json:"daysAvailable"`
	OrgLogin      string `json:"orgLogin"`
	Reason        string `json:"reason,omitempty"`
}

TrialEligibility contains trial information for org repos

type TrialInfo

type TrialInfo struct {
	Status            string  `json:"status"` // "none", "active", "expired", "converted"
	DaysRemaining     *int    `json:"days_remaining"`
	EndsAt            *string `json:"ends_at"`
	TrialDurationDays int     `json:"trial_duration_days"`
}

TrialInfo contains trial status information

type ValidateTokenResponse

type ValidateTokenResponse struct {
	Login     string      `json:"login"`
	Username  string      `json:"username"`
	GitHubID  interface{} `json:"githubId,omitempty"` // Can be string or number
	Plan      string      `json:"plan,omitempty"`
	CreatedAt string      `json:"createdAt,omitempty"`
}

ValidateTokenResponse is the response from validating a token

type VaultDetails added in v0.5.1

type VaultDetails struct {
	ID           string `json:"id"`
	RepoFullName string `json:"repoFullName"`
	SecretCount  int    `json:"secretCount"`
}

VaultDetails contains detailed vault information including secret count

type VaultInfo

type VaultInfo struct {
	ID           string   `json:"id"`
	RepoFullName string   `json:"repoFullName"`
	Environments []string `json:"environments"`
}

VaultInfo contains information about a vault

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL