IF Commons GitHub

logical/shapes

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0002-linux-observe-shapes FR-001, 0002-linux-observe-shapes FR-002, 0002-linux-observe-shapes FR-003

What a command printed, read in the shape a requirement declares: pure functions from the text of getent, stat, id, systemctl, dpkg-query and a file to the value that desired of the requirement would equal were the machine as declared, and nothing where the resource is not there. A field the requirement does not declare is not read, so that a requirement that says less is satisfied by more. Nothing here runs a program.

import { userShape } from "./shapes.ts";
userShape({ name: "ada", shell: "/bin/bash" }, "ada:x:1000:1000:Ada:/home/ada:/bin/bash\n", "ada sudo\n"); // { name: "ada", shell: "/bin/bash" }

Source: commons/linux-observe/src/logical/shapes.ts

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

logical.groupShapefunctionno test imports it
function groupShape(d: Obj, getent: string | undefined): JsonValue | undefined

A group from the line of getent group, or nothing where there is none.

logical.userShapefunctionno test imports it
function userShape(d: Obj, passwd: string | undefined, groupsOf: string | undefined): JsonValue | undefined

A user from the line of getent passwd and the output of id -nG: only the fields the requirement declares, and of the groups it names only those the user is in, in the order it names them.

logical.Stattypeno test imports it
type Stat = { readonly type: string; readonly owner: string; readonly group: string; readonly mode: string };

The kind of a file as stat -c %F says it, with its owner, group and mode (%a).

logical.parseStatfunctionno test imports it
function parseStat(text: string): Stat | undefined

stat -c '%F|%U|%G|%a' read.

logical.pathShapefunctionno test imports it
function pathShape(kind: "directory" | "file", d: Obj, stat: Stat | undefined, content: string | undefined): JsonValue | undefined

A file or a directory from its stat and, for a file, its content: the path, and the content, owner, group and mode as far as the requirement declares them (a mode is written as long as the requirement writes it).

logical.serviceShapefunctionno test imports it
function serviceShape(d: Obj, active: string, enabled: string): JsonValue

A service: whether it is running (systemctl is-active says active) and whether it starts at boot (is-enabled says enabled). A service is always there to ask about.

logical.keyShapefunctionno test imports it
function keyShape(d: Obj, fileText: string | undefined): JsonValue | undefined

A key: the requirement itself where the key file has the line, and nothing where it has not.

logical.packageShapefunctionno test imports it
function packageShape(d: Obj, dpkg: string | undefined): JsonValue | undefined

A package from dpkg-query -W -f '${db:Status-Abbrev}|${Version}': there where its status says installed (ii), with its version where the requirement names one.

logical.rpmPackageShapefunctionno test imports it
function rpmPackageShape(d: Obj, rpm: string | undefined): JsonValue | undefined

A package of an rpm family from rpm -q --qf '%{VERSION}-%{RELEASE}': the version it prints where it is installed (the command fails, and there is nothing to read, where it is not), with the version of the requirement where it names one.

logical.pacmanPackageShapefunctionno test imports it
function pacmanPackageShape(d: Obj, pacman: string | undefined): JsonValue | undefined

A package of Arch from pacman -Q name, which prints name version where it is installed.

logical.settingShapefunctionno test imports it
function settingShape(name: string, text: string | undefined): JsonValue | undefined

A setting of the system from the file that holds it: the time zone is where /etc/localtime points (after zoneinfo/), the keyboard layout is XKBLAYOUT of /etc/default/keyboard and the locale is LANG of /etc/default/locale.

logical.keyFileOffunctionno test imports it
function keyFileOf(d: Obj): string

The path a key file is at: the requirement's own, or the account's .ssh/authorized_keys.

logical.settingFileOffunctionno test imports it
function settingFileOf(family: string, name: string): string | undefined

The file a setting is read from on a family: the time zone is the link /etc/localtime everywhere; the locale is LANG of /etc/default/locale on Debian and /etc/locale.conf elsewhere; the keyboard layout is XKBLAYOUT of /etc/default/keyboard on Debian only (the other families keep a console keymap of another name, which is not the same fact).

groupShapefunction
function groupShape(d: Obj, getent: string | undefined): JsonValue | undefined

A group from the line of getent group, or nothing where there is none.

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

userShapefunction
function userShape(d: Obj, passwd: string | undefined, groupsOf: string | undefined): JsonValue | undefined

A user from the line of getent passwd and the output of id -nG: only the fields the requirement declares, and of the groups it names only those the user is in, in the order it names them.

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

Stattypeno test imports it
type Stat = { readonly type: string; readonly owner: string; readonly group: string; readonly mode: string };

The kind of a file as stat -c %F says it, with its owner, group and mode (%a).

parseStatfunction
function parseStat(text: string): Stat | undefined

stat -c '%F|%U|%G|%a' read.

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

pathShapefunction
function pathShape(kind: "directory" | "file", d: Obj, stat: Stat | undefined, content: string | undefined): JsonValue | undefined

A file or a directory from its stat and, for a file, its content: the path, and the content, owner, group and mode as far as the requirement declares them (a mode is written as long as the requirement writes it).

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

serviceShapefunction
function serviceShape(d: Obj, active: string, enabled: string): JsonValue

A service: whether it is running (systemctl is-active says active) and whether it starts at boot (is-enabled says enabled). A service is always there to ask about.

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

keyShapefunction
function keyShape(d: Obj, fileText: string | undefined): JsonValue | undefined

A key: the requirement itself where the key file has the line, and nothing where it has not.

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

packageShapefunction
function packageShape(d: Obj, dpkg: string | undefined): JsonValue | undefined

A package from dpkg-query -W -f '${db:Status-Abbrev}|${Version}': there where its status says installed (ii), with its version where the requirement names one.

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

rpmPackageShapefunction
function rpmPackageShape(d: Obj, rpm: string | undefined): JsonValue | undefined

A package of an rpm family from rpm -q --qf '%{VERSION}-%{RELEASE}': the version it prints where it is installed (the command fails, and there is nothing to read, where it is not), with the version of the requirement where it names one.

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

pacmanPackageShapefunction
function pacmanPackageShape(d: Obj, pacman: string | undefined): JsonValue | undefined

A package of Arch from pacman -Q name, which prints name version where it is installed.

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

settingShapefunction
function settingShape(name: string, text: string | undefined): JsonValue | undefined

A setting of the system from the file that holds it: the time zone is where /etc/localtime points (after zoneinfo/), the keyboard layout is XKBLAYOUT of /etc/default/keyboard and the locale is LANG of /etc/default/locale.

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

keyFileOffunction
function keyFileOf(d: Obj): string

The path a key file is at: the requirement's own, or the account's .ssh/authorized_keys.

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

settingFileOffunction
function settingFileOf(family: string, name: string): string | undefined

The file a setting is read from on a family: the time zone is the link /etc/localtime everywhere; the locale is LANG of /etc/default/locale on Debian and /etc/locale.conf elsewhere; the keyboard layout is XKBLAYOUT of /etc/default/keyboard on Debian only (the other families keep a console keymap of another name, which is not the same fact).

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

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