Documentation
¶
Overview ¶
Package client builds a configured cinc-api client from CLI configuration. It is the single seam between cinc CLI state and the server API library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Explain ¶ added in v0.24.0
Explain rewrites the transport failures a user can fix themselves (a server certificate no trusted CA signed, a server that isn't listening, a host name that doesn't resolve) into a sentence that names the server and says what to check. Go's own text for these is a chain of package prefixes that buries both. Any other error, including every error the server itself returned, is returned unchanged.
func ExplainFor ¶ added in v0.30.0
ExplainFor is Explain plus the errors the server itself returned: a 400, 401, 403, 404, 409, 413 or 5xx is retold as what went wrong, which client, org and object it concerns (from t and the request path), and what to do about it. The server's own message and the request stay in the text.
Only an error whose text still carries the server's response verbatim is rewritten, so a command that already explained the failure in its own words (the acl commands do) is left alone, while a plain prefix such as "explore: " is kept. The result wraps err, so errors.Is and errors.As see everything they did before.
func New ¶
New builds a cinc-api client from a resolved configuration profile. All server authentication and transport is handled by the cinc-api library; this function only loads the signing key and wires up the connection parameters.
func SilenceTLSWarning ¶
func SilenceTLSWarning() (restore func())
SilenceTLSWarning suppresses the "TLS verification disabled" warning until the returned restore func is called. `cinc config validate` uses it: it reports TLS posture as its own check, so the warning would be redundant in the report.
Types ¶
type Target ¶ added in v0.30.0
type Target struct {
Profile string // profile name, e.g. "default"
ConfigPath string // credentials file the profile came from
ServerURL string // server root, without /organizations/<org>
ClientName string
KeyPath string // client_key with ~ expanded
}
Target names who a request was signed as and where it went: the profile a command built its client from. ExplainFor uses it to name the client, server, key and credentials file in a server error. Every field may be empty; a command that never built a client has no target.
type TrustedCerts ¶ added in v0.24.0
type TrustedCerts struct {
// Dir is the directory the certificates were read from.
Dir string
// Pool is a copy of the system pool with every loaded certificate added.
Pool *x509.CertPool
// Loaded names the files (base names, sorted) that held at least one
// certificate.
Loaded []string
// Skipped names the *.crt / *.pem files that held no parseable
// certificate or could not be read. Normal commands ignore them;
// `cinc config validate` reports them.
Skipped []string
}
TrustedCerts is the result of loading a trusted_certs_dir: the cert pool to verify servers against, plus which files contributed to it.
func LoadTrustedCerts ¶ added in v0.24.0
func LoadTrustedCerts(dir string) (*TrustedCerts, error)
LoadTrustedCerts reads every *.crt and *.pem file in dir and adds the certificates they hold to a copy of the system cert pool (an empty pool when the system one is unavailable). Subdirectories and other files are ignored; a certificate file that holds nothing parseable is listed in Skipped rather than failing the load. The returned errors deliberately do not wrap fs.ErrNotExist or fs.ErrPermission, so the command layer never mistakes them for a missing client key.
func TrustedCertsFor ¶ added in v0.24.0
func TrustedCertsFor(p config.Profile) (*TrustedCerts, error)
TrustedCertsFor resolves and loads the profile's trusted certificates. It returns nil, nil when the profile trusts only the system pool: no trusted_certs_dir is configured and neither default directory exists. An explicitly configured directory that is missing or unreadable is an error.