clicontext

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package clicontext holds what the CLI remembers between commands: the server it talks to, and where the user is working.

It lives beside the kubeconfig, in ~/.kube, because it is the same kind of thing — the local note about which cluster you mean — and because anyone debugging a CLI looks there first.

It belongs to the tenancy CLI because that is where it is written: `login` learns the server, `use` picks the project. Other components' commands are handed what they need from it by whichever binary composes them (contribctl), the way the marketplace's `enable` is handed a workspace resolver — so the components still never import each other, and a component's CLI on its own needs nothing but its flags.

Nothing here authorizes anything. It is a convenience that saves repeating flags — kcp decides what the caller may do.

Index

Constants

View Source
const EnvPath = "CONTRIBCTL_CONTEXT"

EnvPath overrides where the context is stored.

Variables

This section is empty.

Functions

func Save

func Save(c Context) error

Save writes the context, creating ~/.kube if it is not there yet.

func Update

func Update(mutate func(*Context)) error

Update reads the context, applies mutate, and writes it back, so a command changes only the field it owns.

func Where

func Where() string

Where returns the path the context is read from and written to.

Types

type Context

type Context struct {
	// Server is the front-proxy's base URL, e.g.
	// https://kcp.example.com:8443. Every virtual workspace hangs off it
	// under /services/<name>, so one address is all a client needs.
	Server string `json:"server,omitempty"`
	// Tenant and Project are what `use` selected.
	Tenant  string `json:"tenant,omitempty"`
	Project string `json:"project,omitempty"`
	// WorkspaceURL is the selected project's own workspace, as the
	// tenancy virtual workspace reported it.
	WorkspaceURL string `json:"workspaceURL,omitempty"`
	// Insecure records that the servers' certificates are not verified,
	// so a development setup does not need the flag on every command.
	Insecure bool `json:"insecureSkipTLSVerify,omitempty"`
	// CertificateAuthority is the CA bundle that verifies them, when they
	// are verified.
	CertificateAuthority string `json:"certificateAuthority,omitempty"`
}

Context is the CLI's memory between invocations.

func Load

func Load() Context

Load reads the stored context. A missing or unreadable file is an empty context, not an error: every caller has to cope with "nothing chosen yet" anyway, and a corrupt file should not make the CLI unusable.

func (Context) Selection

func (c Context) Selection() string

Selection renders where the user is working, for messages.

func (Context) ServiceURL

func (c Context) ServiceURL(name string) string

ServiceURL is where a virtual workspace answers on the stored server: the front-proxy routes /services/<name> to it.

Empty when no server is known, which is the caller's cue to ask for one — the CLI cannot guess an address.

Jump to

Keyboard shortcuts

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