session

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 13 Imported by: 0 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 session persists values captured from responses between apic invocations, so `apic run login` followed by `apic run get-user` works the way it does in a GUI client. State lives in .apic/session.json under the project root; the directory ignores itself via .apic/.gitignore.

Index

Constants

View Source
const (
	Dir        = ".apic"
	File       = "session.json"
	DefaultEnv = "default"
)
View Source
const CookieFile = "cookies.json"

CookieFile holds the cookie jar, beside session.json.

Variables

This section is empty.

Functions

func EnsureDir

func EnsureDir(dir string) error

EnsureDir creates a .apic directory with the .gitignore that keeps it out of commits. The session, the cookie jar and the history all write through it.

Types

type Cookie struct {
	Name     string    `json:"name"`
	Value    string    `json:"value"`
	Domain   string    `json:"domain"`
	Path     string    `json:"path"`
	Expires  time.Time `json:"expires,omitzero"`
	Secure   bool      `json:"secure,omitempty"`
	HTTPOnly bool      `json:"http_only,omitempty"`
	HostOnly bool      `json:"host_only,omitempty"`
}

Cookie is one stored cookie. Domain, Path and HostOnly are the jar's view after the RFC 6265 defaults were applied, so a saved cookie is sent to the same hosts after a restart as before it. A zero Expires means the cookie lives until `apic session clear`: apic keeps a login's session cookie for the same reason it keeps a captured token.

func (Cookie) ExpiryText

func (c Cookie) ExpiryText(now time.Time) string

ExpiryText describes when a cookie expires, for listings.

type EnvJar

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

EnvJar is the http.CookieJar of one environment. It wraps a net/http/cookiejar and records every cookie the server sets, since the standard jar cannot be enumerated for saving.

func (*EnvJar) Cookies

func (e *EnvJar) Cookies(u *url.URL) []*http.Cookie

Cookies returns the cookies to send with a request to u.

func (*EnvJar) SetCookies

func (e *EnvJar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies stores the cookies a response to u set, and records the ones the jar accepted so they survive the process.

type Jar

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

Jar is the cookie jar of a project, one set of cookies per environment, stored in .apic/cookies.json next to the session. The runtime behaviour is net/http/cookiejar's, without a public-suffix list: a project that talks to one API has no need for one, and it keeps the binary small.

func NewMemoryJar

func NewMemoryJar() *Jar

NewMemoryJar returns a jar that is never written to disk.

func OpenJar

func OpenJar(root string) (*Jar, error)

OpenJar loads the jar for a project root, or an empty one.

func (*Jar) Clear

func (j *Jar) Clear(env string)

Clear drops the cookies of env, or of every env when env is "*".

func (*Jar) Cookies

func (j *Jar) Cookies(env string) []Cookie

Cookies lists the unexpired cookies stored for env, sorted by domain, path and name.

func (*Jar) EnvNames

func (j *Jar) EnvNames() []string

EnvNames lists the environments that have cookies.

func (*Jar) HTTP

func (j *Jar) HTTP(env string) *EnvJar

HTTP returns the http.CookieJar for env, which records what the server sets so it can be saved.

func (*Jar) Save

func (j *Jar) Save() error

Save writes the jar to disk with the same protections as the session file. A memory-only jar is a no-op.

type Store

type Store struct {
	Envs map[string]map[string]string `json:"envs"`
	// contains filtered or unexported fields
}

Store is the on-disk session.

func NewMemory

func NewMemory() *Store

NewMemory returns a session that is never written to disk. Captured values and cached tokens still work within the process.

func Open

func Open(root string) (*Store, error)

Open loads the session for a project root, or an empty one.

func (*Store) Clear

func (s *Store) Clear(env string)

Clear drops captured values for env, or for every env when env is "*".

func (*Store) EnvNames

func (s *Store) EnvNames() []string

EnvNames lists the environments that have captured values.

func (*Store) Get

func (s *Store) Get(env, name string) (string, bool)

Get returns one captured value.

func (*Store) Save

func (s *Store) Save() error

Save writes the session to disk, creating .apic/ and its .gitignore. A memory-only store is a no-op.

func (*Store) Set

func (s *Store) Set(env string, vars map[string]string)

Set merges vars into env's captured values (in memory; call Save).

func (*Store) Snapshot

func (s *Store) Snapshot() *Store

Snapshot is a memory-only copy of the session: what it held when taken, changed and read without touching the original or the disk. Each iteration of `apic run --data` starts from one.

func (*Store) Vars

func (s *Store) Vars(env string) map[string]string

Vars returns a copy of the captured values for env.

Jump to

Keyboard shortcuts

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