config

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config persists the logged-in Harbor session — OAuth tokens plus the API target and device identity — to ~/.config/harbor/credentials.json with 0600 permissions. It never logs or prints token material.

Index

Constants

View Source
const (
	// DefaultBaseURL is the production Harbor API endpoint that real customers
	// always use. It includes the /api/v1 prefix; domain client methods use
	// paths relative to it. The override (api_url / --api-url / HARBOR_API_URL)
	// exists only so the maintainer can point the CLI at staging or local
	// environments — it is not a customer-facing feature.
	DefaultBaseURL = "https://app.harbor.my/api/v1"

	// DefaultClientID is the fallback OAuth client id used only when a saved
	// credential predates the browser-login change and has no client_id. New
	// logins store "harbor-cli" explicitly; legacy sessions minted under
	// "harbor-app" keep working because they carry their own client_id.
	DefaultClientID = "harbor-app"
)

Variables

This section is empty.

Functions

func Clear

func Clear() error

Clear removes the credentials file. A missing file is not an error, so logout is idempotent.

func ClearKeystoreBlob

func ClearKeystoreBlob() error

ClearKeystoreBlob removes the cached keystore blob. A missing file is not an error, so logout/reset is idempotent.

func ConfigDirPath

func ConfigDirPath() (string, error)

ConfigDirPath returns the full path to the Harbor configuration directory (~/.config/harbor).

func ConfigFilePath

func ConfigFilePath() (string, error)

ConfigFilePath returns the full path to the credentials file.

func LoadKeystoreBlob

func LoadKeystoreBlob() (string, error)

LoadKeystoreBlob returns the cached HRBK1 keystore blob, or "" (no error) when no cache exists yet. The blob is the wrapped master key and is safe at rest.

func Save

func Save(c *Credentials) error

Save writes the credentials to disk atomically with 0600 permissions, creating the 0700 config directory if needed. It writes to a temp file in the same directory and renames, so a crash never leaves a half-written (and thus session-losing) credentials file.

func SaveKeystoreBlob

func SaveKeystoreBlob(blob string) error

SaveKeystoreBlob atomically writes the keystore blob cache with 0600 permissions, creating the config directory if needed.

Types

type Credentials

type Credentials struct {
	APIURL       string `json:"api_url"`
	ClientID     string `json:"client_id"`
	Email        string `json:"email"`
	UserID       string `json:"user_id,omitempty"` // resolved lazily; used as the sync scope_id
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
	ExpiresAt    int64  `json:"expires_at"` // epoch-ms when the access token expires
	DeviceID     string `json:"device_id"`
	DeviceName   string `json:"device_name"`
}

Credentials is the on-disk session: API target, identity, and the OAuth token pair. Times are UTC epoch milliseconds (matching the API), except where noted.

func Load

func Load() (*Credentials, error)

Load reads and parses the credentials file. A missing file returns an actionable error telling the user to run `harbor login` first.

func (*Credentials) BaseURL

func (c *Credentials) BaseURL() string

BaseURL returns the configured API base URL, falling back to the production default when unset. The returned value includes the /api/v1 prefix.

func (*Credentials) EffectiveClientID

func (c *Credentials) EffectiveClientID() string

EffectiveClientID returns the configured OAuth client id, defaulting to the first-party client.

func (*Credentials) ExpiresAtTime

func (c *Credentials) ExpiresAtTime() time.Time

ExpiresAtTime returns the access-token expiry as a time.Time (zero if unset).

func (*Credentials) IsExpired

func (c *Credentials) IsExpired(skew time.Duration) bool

IsExpired reports whether the access token is expired (or will be within the given skew). A zero ExpiresAt is treated as expired so callers refresh. The skew lets callers refresh proactively before a request rather than racing expiry mid-flight.

Jump to

Keyboard shortcuts

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