fs

package
v0.0.84 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fs provides a filesystem-backed credential store that persists oneauth client server credentials as a single JSON file keyed by normalized server URL.

<!-- design:start --> The package owns one type, FSCredentialStore, which keeps server credentials in an in-memory map guarded by a RWMutex and mirrors them to a JSON file on disk. Keys are normalized server URLs (scheme://host); the normalizer defaults a missing scheme to https and strips paths/queries so that variant URLs collapse onto one entry. Mutations (Set, Remove) only touch memory and flip a modified flag — nothing is written until Save is called, which no-ops when unchanged and otherwise writes the directory at 0700 and the file at 0600 because the contents are secrets. The default path resolves to ~/.config/<appName>/credentials.json (falling back to ~/.config when UserConfigDir is unavailable, and to "oneauth" when appName is empty). A missing file at construction is tolerated, so first-run callers get an empty but usable store.

ENTITIES

FSCredentialStore — in-memory map of server credentials backed by a JSON file, guarded by a RWMutex; mutations stay in memory until Save.

NewFSCredentialStore — constructs a store, defaulting the path to ~/.config/<appName>/credentials.json and eagerly loading any existing file; a missing file is not an error.

GetCredential — looks up a credential by normalized server URL; returns (nil, nil) on a miss, so callers must nil-check the credential.

SetCredential — stores a credential under its normalized URL key and marks the store dirty; does not write to disk.

RemoveCredential — deletes a credential by normalized URL key and marks the store dirty; defers the file rewrite to Save.

ListServers — returns all normalized server URL keys (scheme://host), not the original input strings.

Save — persists the map to disk as indented JSON if modified, creating the directory 0700 and file 0600; no-ops when nothing changed.

Path — returns the resolved path to the credentials file after default-path resolution. <!-- design:end -->

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSCredentialStore

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

FSCredentialStore stores credentials as a JSON file on the filesystem

func NewFSCredentialStore

func NewFSCredentialStore(path string, appName string) (*FSCredentialStore, error)

NewFSCredentialStore creates a new FS-based credential store. If path is empty, defaults to ~/.config/<appName>/credentials.json

func (*FSCredentialStore) GetCredential

func (s *FSCredentialStore) GetCredential(serverURL string) (*client.ServerCredential, error)

GetCredential retrieves a credential for a server URL

func (*FSCredentialStore) ListServers

func (s *FSCredentialStore) ListServers() ([]string, error)

ListServers returns all server URLs with stored credentials

func (*FSCredentialStore) Path

func (s *FSCredentialStore) Path() string

Path returns the path to the credentials file

func (*FSCredentialStore) RemoveCredential

func (s *FSCredentialStore) RemoveCredential(serverURL string) error

RemoveCredential removes a credential for a server URL

func (*FSCredentialStore) Save

func (s *FSCredentialStore) Save() error

Save persists credentials to disk

func (*FSCredentialStore) SetCredential

func (s *FSCredentialStore) SetCredential(serverURL string, cred *client.ServerCredential) error

SetCredential stores a credential for a server URL

Jump to

Keyboard shortcuts

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