session

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// EnvSpaceliftAPIEndpoint represents the name of the environment variable
	// pointing to the Spacelift API endpoint.
	//
	// Deprecated
	EnvSpaceliftAPIEndpoint = "SPACELIFT_API_ENDPOINT"

	// EnvSpaceliftAPIKeyEndpoint represents the name of the environment variable
	// pointing to the Spacelift API endpoint.
	EnvSpaceliftAPIKeyEndpoint = "SPACELIFT_API_KEY_ENDPOINT" //nolint: gosec

	// EnvSpaceliftAPIKeyID represents the name of the environment variable
	// pointing to the Spacelift API key ID.
	EnvSpaceliftAPIKeyID = "SPACELIFT_API_KEY_ID" //nolint: gosec

	// EnvSpaceliftAPIKeySecret represents the name of the environment variable
	// pointing to the Spacelift API key secret.
	EnvSpaceliftAPIKeySecret = "SPACELIFT_API_KEY_SECRET" // #nosec G101

	// EnvSpaceliftAPIToken represents the name of the environment variable
	// pointing to the Spacelift API token.
	EnvSpaceliftAPIToken = "SPACELIFT_API_TOKEN" // #nosec G101

	// EnvSpaceliftAPIGitHubToken represents the name of the environment variable
	// pointing to the GitHub access token used to get the Spacelift API token.
	EnvSpaceliftAPIGitHubToken = "SPACELIFT_API_GITHUB_TOKEN" // #nosec G101
)
View Source
const (
	// SpaceliftConfigDirectory is the name of the Spacelift config directory.
	SpaceliftConfigDirectory = ".spacelift"

	// ConfigFileName is the name of the file containing the spacectl config.
	ConfigFileName = "config.json"
)

Variables

This section is empty.

Functions

func Defaults

func Defaults() (context.Context, *http.Client)

Defaults returns default context and HTTP client to use by clients that don't need any further configuration.

func FromAPIKey

func FromAPIKey(ctx context.Context, client *http.Client) func(string, string, string) (Session, error)

FromAPIKey builds a Spacelift session from a combination of endpoint, API key ID and API key secret.

func FromAPIToken

func FromAPIToken(_ context.Context, client *http.Client) func(string, string) (Session, error)

FromAPIToken creates a session from a ready API token.

func FromEnvironment

func FromEnvironment(ctx context.Context, client *http.Client) func(func(string) (string, bool)) (Session, error)

FromEnvironment creates a Spacelift session from the environment.

func FromGitHubToken

func FromGitHubToken(ctx context.Context, client *http.Client) func(string, string) (Session, error)

FromGitHubToken builds a Spacelift session from a combination of endpoint, and a GitHub access token.

Types

type CredentialsType

type CredentialsType uint

CredentialsType represents the type of credentials being used.

const (
	// CredentialsTypeInvalid represents an invalid zero value for the
	// CredentialsType.
	CredentialsTypeInvalid CredentialsType = iota

	// CredentialsTypeAPIKey represents credentials stored as an API key
	// id-secret pair.
	CredentialsTypeAPIKey

	// CredentialsTypeGitHubToken represents credentials stored as a GitHub
	// access token.
	CredentialsTypeGitHubToken

	// CredentialsTypeAPIToken represents credentials stored as a JWT
	// access token.
	CredentialsTypeAPIToken
)

func (CredentialsType) String

func (t CredentialsType) String() string

String returns the string representation of the type.

type Profile

type Profile struct {
	// The alias (name) of the profile.
	Alias string `json:"alias,omitempty"`

	// The credentials used to make Spacelift API requests.
	Credentials *StoredCredentials `json:"credentials,omitempty"`
}

A Profile represents a spacectl profile which is used to store credential information for accessing Spacelift.

type ProfileManager

type ProfileManager struct {
	// The full path to the spacectl config file.
	ConfigurationFile string

	// The spacectl configuration.
	Configuration *configuration
}

A ProfileManager is used to interact with Spacelift profiles.

func NewProfileManager

func NewProfileManager(profilesDirectory string) (*ProfileManager, error)

NewProfileManager creates a new ProfileManager using the specified directory to store the profile data.

func UserProfileManager added in v0.17.3

func UserProfileManager() (*ProfileManager, error)

UserProfileManager creates a new ProfileManager using the user home directory to store the profile data.

func (*ProfileManager) Create

func (m *ProfileManager) Create(profile *Profile) error

Create adds a new Spacelift profile.

func (*ProfileManager) Current

func (m *ProfileManager) Current() *Profile

Current gets the user's currently selected profile, and returns nil if no profile is selected.

func (*ProfileManager) Delete

func (m *ProfileManager) Delete(profileAlias string) error

Delete removes the profile with the specified alias, and un-selects it as the current profile if it was selected.

func (*ProfileManager) Get

func (m *ProfileManager) Get(profileAlias string) (*Profile, error)

Get returns the profile with the specified alias, returning nil if that profile does not exist.

func (*ProfileManager) GetAll

func (m *ProfileManager) GetAll() []*Profile

GetAll returns all the currently stored profiles, returning an empty slice if no profiles exist.

func (*ProfileManager) Select

func (m *ProfileManager) Select(profileAlias string) error

Select sets the currently selected profile.

type Session

type Session interface {
	BearerToken(ctx context.Context) (string, error)
	Endpoint() string
	Type() CredentialsType
}

Session is an abstraction around session creation based on credentials from various sources.

func FromCurrentProfile

func FromCurrentProfile(ctx context.Context, client *http.Client) (Session, error)

FromCurrentProfile creates a session from credentials stored in the currently selected profile.

func Must

func Must(out Session, err error) Session

Must provides a helper that either creates a Session or dies trying.

func New

func New(ctx context.Context, client *http.Client) (Session, error)

New creates a session using the default chain of credentials sources: first the environment, then the current credentials file.

type StoredCredentials

type StoredCredentials struct {
	Type        CredentialsType `json:"type,omitempty"`
	Endpoint    string          `json:"endpoint,omitempty"`
	AccessToken string          `json:"access_token,omitempty"`
	KeyID       string          `json:"key_id,omitempty"`
	KeySecret   string          `json:"key_secret,omitempty"`
}

StoredCredentials is a filesystem representation of the credentials.

func (*StoredCredentials) Session

func (s *StoredCredentials) Session(ctx context.Context, client *http.Client) (Session, error)

Session creates a Spacelift Session from stored credentials.

Jump to

Keyboard shortcuts

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