storage

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeychainTokenService is the service name for token keychain entries
	// Matches TypeScript PR #84: "datadog-cli"
	KeychainTokenService = "datadog-cli"

	// KeychainClientService is the service name for client credential keychain entries
	// Matches TypeScript PR #84: "datadog-cli-dcr"
	KeychainClientService = "datadog-cli-dcr"

	// TokenPrefix is the prefix for token keychain account names
	// Matches TypeScript PR #84: "oauth:"
	TokenPrefix = "oauth:"

	// ClientPrefix is the prefix for client credential keychain account names
	// Matches TypeScript PR #84: "client:"
	ClientPrefix = "client:"
)
View Source
const (
	// StorageEnvVar is the environment variable to override storage backend
	StorageEnvVar = "DD_TOKEN_STORAGE"
)

Variables

This section is empty.

Functions

func GetStorageDescription

func GetStorageDescription() string

GetStorageDescription returns a human-readable description of current storage

func IsKeychainAvailable

func IsKeychainAvailable() bool

IsKeychainAvailable checks if keychain storage is available on this system

func IsUsingSecureStorage

func IsUsingSecureStorage() bool

IsUsingSecureStorage returns true if keychain storage is active

func ResetStorage

func ResetStorage()

ResetStorage clears the cached storage instance (for testing)

Types

type BackendType

type BackendType string

BackendType represents the type of storage backend

const (
	BackendKeychain BackendType = "keychain"
	BackendFile     BackendType = "file"
)

func GetActiveBackend

func GetActiveBackend() BackendType

GetActiveBackend returns the currently active storage backend type

type FileStorage

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

FileStorage implements Storage using encrypted files

func NewFileStorage

func NewFileStorage() (*FileStorage, error)

NewFileStorage creates a new file-based storage

func (*FileStorage) DeleteClientCredentials

func (s *FileStorage) DeleteClientCredentials(site string) error

DeleteClientCredentials deletes DCR client credentials

func (*FileStorage) DeleteTokens

func (s *FileStorage) DeleteTokens(site string) error

DeleteTokens deletes OAuth2 tokens

func (*FileStorage) GetBackendType

func (s *FileStorage) GetBackendType() BackendType

GetBackendType returns the backend type

func (*FileStorage) GetStorageLocation

func (s *FileStorage) GetStorageLocation() string

GetStorageLocation returns the storage directory path

func (*FileStorage) LoadClientCredentials

func (s *FileStorage) LoadClientCredentials(site string) (*types.ClientCredentials, error)

LoadClientCredentials loads DCR client credentials

func (*FileStorage) LoadTokens

func (s *FileStorage) LoadTokens(site string) (*types.TokenSet, error)

LoadTokens loads OAuth2 tokens from file

func (*FileStorage) SaveClientCredentials

func (s *FileStorage) SaveClientCredentials(site string, creds *types.ClientCredentials) error

SaveClientCredentials saves DCR client credentials

func (*FileStorage) SaveTokens

func (s *FileStorage) SaveTokens(site string, tokens *types.TokenSet) error

SaveTokens saves OAuth2 tokens to file

type KeychainStorage

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

KeychainStorage stores OAuth tokens and credentials in the OS keychain Uses separate keyring services to match TypeScript PR #84

func NewKeychainStorage

func NewKeychainStorage() (*KeychainStorage, error)

NewKeychainStorage creates a new keychain storage instance Opens two separate keychains to match TypeScript PR #84 architecture

func (*KeychainStorage) DeleteClientCredentials

func (s *KeychainStorage) DeleteClientCredentials(site string) error

DeleteClientCredentials deletes OAuth client credentials for a site

func (*KeychainStorage) DeleteTokens

func (s *KeychainStorage) DeleteTokens(site string) error

DeleteTokens deletes OAuth tokens for a site

func (*KeychainStorage) GetBackendType

func (s *KeychainStorage) GetBackendType() BackendType

GetBackendType returns the backend type

func (*KeychainStorage) GetStorageLocation

func (s *KeychainStorage) GetStorageLocation() string

GetStorageLocation returns a human-readable description

func (*KeychainStorage) LoadClientCredentials

func (s *KeychainStorage) LoadClientCredentials(site string) (*types.ClientCredentials, error)

LoadClientCredentials loads OAuth client credentials for a site

func (*KeychainStorage) LoadTokens

func (s *KeychainStorage) LoadTokens(site string) (*types.TokenSet, error)

LoadTokens loads OAuth tokens for a site

func (*KeychainStorage) SaveClientCredentials

func (s *KeychainStorage) SaveClientCredentials(site string, creds *types.ClientCredentials) error

SaveClientCredentials saves OAuth client credentials for a site

func (*KeychainStorage) SaveTokens

func (s *KeychainStorage) SaveTokens(site string, tokens *types.TokenSet) error

SaveTokens saves OAuth tokens for a site

type Storage

type Storage interface {
	// GetBackendType returns the type of storage backend
	GetBackendType() BackendType

	// GetStorageLocation returns a human-readable description of storage location
	GetStorageLocation() string

	// SaveTokens saves OAuth2 tokens
	SaveTokens(site string, tokens *types.TokenSet) error

	// LoadTokens loads OAuth2 tokens
	LoadTokens(site string) (*types.TokenSet, error)

	// DeleteTokens deletes OAuth2 tokens
	DeleteTokens(site string) error

	// SaveClientCredentials saves DCR client credentials
	SaveClientCredentials(site string, creds *types.ClientCredentials) error

	// LoadClientCredentials loads DCR client credentials
	LoadClientCredentials(site string) (*types.ClientCredentials, error)

	// DeleteClientCredentials deletes DCR client credentials
	DeleteClientCredentials(site string) error
}

Storage interface for token and credential storage

func GetStorage

func GetStorage(opts *StorageOptions) (Storage, error)

GetStorage returns a storage instance, automatically detecting the best backend

Selection priority:

  1. DD_TOKEN_STORAGE=file → use file storage
  2. DD_TOKEN_STORAGE=keychain → use keychain (fail if unavailable)
  3. Auto-detect: try keychain, fall back to file with warning

Example:

storage := GetStorage() // Auto-detect
storage := GetStorage(&StorageOptions{ForceBackend: BackendKeychain}) // Force keychain

type StorageOptions

type StorageOptions struct {
	// ForceBackend forces a specific storage backend
	ForceBackend BackendType

	// StorageDir overrides the storage directory (file backend only)
	StorageDir string
}

StorageOptions configures storage backend selection

Jump to

Keyboard shortcuts

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