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
- func Clear() error
- func ClearKeystoreBlob() error
- func ClearServerNames() error
- func ConfigDirPath() (string, error)
- func ConfigFilePath() (string, error)
- func LoadKeystoreBlob() (string, error)
- func LoadServerName(baseURL string) (string, error)
- func Save(c *Credentials) error
- func SaveKeystoreBlob(blob string) error
- func SaveServerName(baseURL, name string) error
- type Credentials
Constants ¶
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 ClearServerNames ¶ added in v0.1.54
func ClearServerNames() error
ClearServerNames removes the server-names file. A missing file is not an error, so logout stays idempotent.
func ConfigDirPath ¶
ConfigDirPath returns the full path to the Harbor configuration directory (~/.config/harbor).
func ConfigFilePath ¶
ConfigFilePath returns the full path to the credentials file.
func LoadKeystoreBlob ¶
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 LoadServerName ¶ added in v0.1.54
LoadServerName returns the saved server name for an API base URL, or "" (no error) when none is saved.
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 ¶
SaveKeystoreBlob atomically writes the keystore blob cache with 0600 permissions, creating the config directory if needed.
func SaveServerName ¶ added in v0.1.54
SaveServerName records the server name for an API base URL; an empty name removes the entry. Other base URLs' entries are kept. A file that cannot be parsed is replaced, since it only holds routing hints the next response gives back.
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.