auth

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_VERS_URL_STR = "https://api.vers.sh"

Variables

This section is empty.

Functions

func FindSSHPublicKey added in v0.7.2

func FindSSHPublicKey() (key string, keyPath string, err error)

FindSSHPublicKey finds the user's SSH public key, checking common locations. Returns the key contents and the path where it was found.

func GetAPIKey

func GetAPIKey() (string, error)

GetAPIKey retrieves the API key from environment variable or config file

func GetClientOptions

func GetClientOptions() ([]option.RequestOption, error)

GetClientOptions returns the options for the SDK client

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the path to the .versrc file in the user's home directory

func GetGitEmail added in v0.7.2

func GetGitEmail() (string, error)

GetGitEmail returns the user's git config email.

func GetOrCreateSSHKey

func GetOrCreateSSHKey(vmID string, client *vers.Client, apiCtx context.Context) (string, error)

GetOrCreateSSHKey retrieves the path to an SSH key, fetching and saving it if necessary.

func GetVMDomain added in v0.6.0

func GetVMDomain() string

GetVMDomain derives the VM SSH domain from the configured VERS_URL. For example:

func GetVersUrl

func GetVersUrl() (*url.URL, error)

GetVersUrl returns the full URL with protocol validation

func HasAPIKey

func HasAPIKey() (bool, error)

HasAPIKey checks if an API key is present in environment variable or config file

func PromptForLogin

func PromptForLogin() error

PromptForLogin creates a helper function that checks for API key and prompts for login if not found

func ReadSSHPublicKey added in v0.7.4

func ReadSSHPublicKey(path string) (string, error)

ReadSSHPublicKey reads an SSH public key from a specific path.

func SaveAPIKey

func SaveAPIKey(apiKey string) error

SaveAPIKey saves the API key to the config file

func SaveConfig

func SaveConfig(config *Config) error

SaveConfig saves the configuration to the .versrc file

Types

type Config

type Config struct {
	APIKey     string `json:"apiKey"`
	Email      string `json:"email,omitempty"`
	SSHKeyPath string `json:"sshKeyPath,omitempty"`
}

Config represents the structure of the .versrc file

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the configuration from the .versrc file

type SSHKeyResponse added in v0.5.0

type SSHKeyResponse struct {
	SSHPrivateKey string `json:"ssh_private_key"`
	SSHPort       int    `json:"ssh_port"`
}

SSHKeyResponse represents the API response for VM SSH key

type ShellAuthCreateKeyRequest added in v0.7.2

type ShellAuthCreateKeyRequest struct {
	Email        string `json:"email"`
	SSHPublicKey string `json:"ssh_public_key"`
	Label        string `json:"label"`
	OrgName      string `json:"org_name,omitempty"`
}

ShellAuthCreateKeyRequest is the request body for POST /api/shell-auth/api-keys.

type ShellAuthCreateKeyResponse added in v0.7.2

type ShellAuthCreateKeyResponse struct {
	Success  bool   `json:"success"`
	APIKey   string `json:"api_key"`
	APIKeyID string `json:"api_key_id"`
	OrgID    string `json:"org_id"`
	OrgName  string `json:"org_name"`
}

ShellAuthCreateKeyResponse is the response from POST /api/shell-auth/api-keys.

func ShellAuthCreateAPIKey added in v0.7.2

func ShellAuthCreateAPIKey(email, sshPubKey, label, orgName string) (*ShellAuthCreateKeyResponse, error)

ShellAuthCreateAPIKey creates an API key for the verified user.

type ShellAuthErrorResponse added in v0.7.2

type ShellAuthErrorResponse struct {
	Error   string `json:"error"`
	Message string `json:"message"`
}

ShellAuthErrorResponse captures error details from the API.

type ShellAuthInitRequest added in v0.7.2

type ShellAuthInitRequest struct {
	Email        string `json:"email"`
	SSHPublicKey string `json:"ssh_public_key"`
	Body         string `json:"body,omitempty"`
}

ShellAuthInitRequest is the request body for POST /api/shell-auth.

type ShellAuthInitResponse added in v0.7.2

type ShellAuthInitResponse struct {
	Success         bool   `json:"success"`
	UserID          string `json:"user_id"`
	Email           string `json:"email"`
	IsNewUser       bool   `json:"is_new_user"`
	Nonce           string `json:"nonce"`
	SSHPublicKey    string `json:"ssh_public_key"`
	AlreadyVerified bool   `json:"already_verified"`
}

ShellAuthInitResponse is the response from POST /api/shell-auth.

func ShellAuthInitiate added in v0.7.2

func ShellAuthInitiate(email, sshPubKey string) (*ShellAuthInitResponse, error)

ShellAuthInitiate starts the shell auth flow.

type ShellAuthOrg added in v0.7.2

type ShellAuthOrg struct {
	OrgID string `json:"org_id"`
	Name  string `json:"name"`
	Role  string `json:"role"`
}

ShellAuthOrg represents an organization in the verify response.

type ShellAuthVerifyRequest added in v0.7.2

type ShellAuthVerifyRequest struct {
	Email        string `json:"email"`
	SSHPublicKey string `json:"ssh_public_key"`
}

ShellAuthVerifyRequest is the request body for POST /api/shell-auth/verify-key.

type ShellAuthVerifyResponse added in v0.7.2

type ShellAuthVerifyResponse struct {
	Verified bool           `json:"verified"`
	IsActive bool           `json:"is_active"`
	UserID   string         `json:"user_id"`
	KeyID    string         `json:"key_id"`
	Orgs     []ShellAuthOrg `json:"orgs"`
	Reason   string         `json:"reason,omitempty"`
}

ShellAuthVerifyResponse is the response from POST /api/shell-auth/verify-key.

func ShellAuthCheckVerification added in v0.7.2

func ShellAuthCheckVerification(email, sshPubKey string) (*ShellAuthVerifyResponse, error)

ShellAuthCheckVerification does a single verification check (no polling). Use when you already know the key is verified and just need the org list.

func ShellAuthPollVerification added in v0.7.2

func ShellAuthPollVerification(email, sshPubKey string, timeout time.Duration) (*ShellAuthVerifyResponse, error)

ShellAuthPollVerification polls until the email is verified or timeout. Returns the verify response with orgs on success.

Jump to

Keyboard shortcuts

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