IF Commons GitHub

sql/cli/libpq

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0047-arcactl-init FR-008, 0047-arcactl-init FR-009, 0047-arcactl-init FR-010

The writers of the files libpq and psql read (commons data 0047-arcactl-init FR-008 to FR-010): .pgpass (the passwords), pg_service.conf (the instances: host, port, database, user, SSL) and .psqlrc (the prompt, the settings and a few helper queries). Each is a managed block (0047 FR-002) planned as a change (FR-003), so what a person wrote in the file is untouched. They are functions of their input and make nothing: the password is given to them and is written only to .pgpass, mode 0600, which libpq ignores where the group or others can read it.

Source: commons/data/sql/cli/libpq.ts

16 of 19 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Credentialinterface
interface Credential

A password for one place: each of host, port, database and user is exact or *.

MemberTypeWhat it is
hoststring
portstring
databasestring
userstring
passwordstring

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

checkCredentialfunction
function checkCredential(c: Credential): readonly WriteError[]

What is wrong with a credential.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

checkInstancefunction
function checkInstance(i: Instance): readonly WriteError[]

What is wrong with an instance, as a service.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

fixModesfunction
function fixModes(plan: Plan): readonly string[]

Puts right the mode of a password file that libpq would ignore.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Instanceinterface
interface Instance

An instance: what libpq's service file says of it, and what arcactl adds.

MemberTypeWhat it is
namestring
host?string
port?number
database?string
user?string
sslmode?stringdisable, allow, prefer, require, verify-ca or verify-full.
schema?stringThe schema the arca tables are in, which the service puts first on the search path.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Keytypeno test imports it
type Key = Pick<Credential, "host" | "port" | "database" | "user">;

The part of a credential that says where it is for.

PgpassChangeinterfaceno test imports it
interface PgpassChange

What a change of the credentials is: some set (a new password replaces the one for the same place), some removed.

MemberTypeWhat it is
set?readonly Credential[]
remove?readonly Key[]
parsePgpassfunction
function parsePgpass(text: string): { readonly credentials: readonly Credential[]; readonly other: readonly string[]; }

The credentials in a text (the body of a block or a whole file); a comment and a blank line are skipped, and a line that is not one is returned apart.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

parseServicesfunction
function parseServices(text: string): readonly { readonly name: string; readonly settings: Readonly<Record<string, string>>; }[]

The services in a text: each [name] section and its settings.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

pgpassLineconst
const pgpassLine: (c: Credential) => string

One line of .pgpass.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

planPgpassfunction
function planPgpass(paths: Paths, change: PgpassChange): Result<Plan, readonly WriteError[]>

Plans the change of .pgpass.

ParameterWhat it is
pathswhere the files are
changethe credentials to set and to remove

Returns: the plan (the file at mode 0600, a warning where a line of the person's own would be read first), or what is wrong

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

planPsqlfunction
function planPsql(paths: Paths): Result<Plan, readonly WriteError[]>

Plans the psql files: the one arcactl owns, and a block in the person's psqlrc that includes it.

ParameterWhat it is
pathswhere the files are

Returns: the plan

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

planServicesfunction
function planServices(paths: Paths, instances: readonly Instance[]): Result<Plan, readonly WriteError[]>

Plans the service file for a set of instances: the block holds exactly these.

ParameterWhat it is
pathswhere the files are
instancesevery instance arcactl is to write (none takes the block out)

Returns: the plan, or what is wrong: an instance that is not valid, or one a person already defined outside the block (libpq reads the first, so the one arcactl wrote would be ignored)

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

planUndofunction
function planUndo(paths: Paths): Result<Plan, readonly WriteError[]>

Plans taking away what the writers put in: the block of each file, and the credentials and services of arcactl.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

psqlrcBodyconst
const psqlrcBody: () => string

The file of psql that arcactl owns: the prompt, the settings and the helper queries. It needs psql 15 or later, which has \getenv.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

readInstancesfunction
function readInstances(paths: Paths): Result<readonly Instance[], readonly WriteError[]>

The instances arcactl has written to a service file, read back from its block.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

serviceSectionfunction
function serviceSection(i: Instance): string

One service, as the lines of its section.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

splitPgpassfunction
function splitPgpass(line: string): readonly string[] | undefined

The fields of a line, with the escapes undone; none where it does not have five.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

WriteErrortypeno test imports it
type WriteError =
  | { readonly kind: "invalid"; readonly what: string; readonly why: string }
  | { readonly kind: "conflict"; readonly service: string; readonly why: string }
  | { readonly kind: "block"; readonly path: string; readonly error: BlockError }
  | FileError;

What is wrong with what a writer is given.

Titles, headings, exports, tables, columns and requirements. Esc closes.