@rocket.chat/houston 0.27.0-next.2 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
package/dist/lib/home.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.pathHome = pathHome;
|
|
37
|
+
exports.joinPath = joinPath;
|
|
38
|
+
exports.pathExpandUser = pathExpandUser;
|
|
39
|
+
exports.osPathAbspath = osPathAbspath;
|
|
40
|
+
exports.pathResolve = pathResolve;
|
|
41
|
+
/**
|
|
42
|
+
* The user's home directory, as the state directory has always been found from it -- which
|
|
43
|
+
* is not what `os.homedir()` returns.
|
|
44
|
+
*
|
|
45
|
+
* `HOME` is taken when it is in the environment and the password database asked only when
|
|
46
|
+
* it is not; Node's `os.homedir()` is exactly that choice, verbatim. The home then has
|
|
47
|
+
* every trailing `/` stripped from whichever value it got, and a value that strips to
|
|
48
|
+
* nothing becomes `/`. So with `HOME` set but EMPTY the state directory is `/.houston`,
|
|
49
|
+
* and every site that joined `os.homedir()` resolved `.houston` in the working directory
|
|
50
|
+
* instead -- a different directory for each place the command happened to be run from,
|
|
51
|
+
* none of which an earlier release would ever look in. Measured, `HOUSTON_HOME` unset:
|
|
52
|
+
*
|
|
53
|
+
* HOME unset config.home() -> <password-database home>/.houston
|
|
54
|
+
* HOME='' config.home() -> /.houston (os.homedir() is '')
|
|
55
|
+
* HOME='/' config.home() -> /.houston
|
|
56
|
+
* HOME='//' config.home() -> /.houston (os.homedir() is '//')
|
|
57
|
+
* HOME='/tmp/x/' config.home() -> /tmp/x/.houston (os.homedir() is '/tmp/x/')
|
|
58
|
+
* HOME='/tmp/x//' config.home() -> /tmp/x/.houston
|
|
59
|
+
*
|
|
60
|
+
* The strip applies to the password-database value too, since it comes after the choice,
|
|
61
|
+
* and `os.homedir()` does not strip: measured against a bind-mounted passwd in a user
|
|
62
|
+
* namespace, an entry of `/fake/home//` is `/fake/home//` to Node and `/fake/home` to
|
|
63
|
+
* `pathHome`, and an empty entry is `''` to Node and `/` to `pathHome`.
|
|
64
|
+
*
|
|
65
|
+
* WHAT IS LEFT TO THE CALLER, deliberately: the join. `joinPath` keeps a leading `//`
|
|
66
|
+
* and every `..`, where `path.join` collapses both, so `HOME='//tmp/x'` resolves
|
|
67
|
+
* `//tmp/x/.houston` through the one and `/tmp/x/.houston` through the other -- the same
|
|
68
|
+
* directory on Linux, and a spelling difference that belongs to each site's path
|
|
69
|
+
* arithmetic, not to which directory is home. And a uid with no password-database entry
|
|
70
|
+
* and no `HOME` fails: `os.homedir()` throws a `SystemError`, where earlier releases raised
|
|
71
|
+
* their own could-not-determine-home error.
|
|
72
|
+
*
|
|
73
|
+
* `os.homedir()` rather than `process.env.HOME`, although they agree in production:
|
|
74
|
+
* under Jest `process.env` is the test file's own copy and `os.homedir()` is native, so
|
|
75
|
+
* the suite moves HOME by mocking `node:os` -- and a helper that read the copy would make
|
|
76
|
+
* every one of those mocks answer the developer's real home.
|
|
77
|
+
*
|
|
78
|
+
* A rank-0 module that imports nothing from `src/`, because `config.ts` is one of its
|
|
79
|
+
* twelve callers and `lib/lock.ts` (rank 1), which joins the marker onto a home, another,
|
|
80
|
+
* and nothing may reach up or sideways for it. The rule is this module's alone.
|
|
81
|
+
*/
|
|
82
|
+
const fs = __importStar(require("node:fs"));
|
|
83
|
+
const os = __importStar(require("node:os"));
|
|
84
|
+
/** The home: `os.homedir()` with trailing `/` stripped, or `/` if that leaves nothing. */
|
|
85
|
+
function pathHome() {
|
|
86
|
+
const raw = os.homedir();
|
|
87
|
+
let end = raw.length;
|
|
88
|
+
while (end > 0 && raw[end - 1] === '/')
|
|
89
|
+
end -= 1;
|
|
90
|
+
return end === 0 ? '/' : raw.slice(0, end);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The segments joined component by component, which is not `path.join`.
|
|
94
|
+
*
|
|
95
|
+
* The segments are joined as `posixJoin` joins them, the result is parsed once, and two
|
|
96
|
+
* things `path.join`'s normalisation removes are kept: every `..` (a lexical parent is not a
|
|
97
|
+
* resolved one -- `nonexistent/../x` needs `nonexistent` to exist before the kernel walks
|
|
98
|
+
* back out of it, so the two spellings can name different files) and a root of exactly two
|
|
99
|
+
* slashes, whose meaning POSIX leaves to the system. It drops what `path.join` drops too:
|
|
100
|
+
* empty and `.` parts, a trailing `/`, and a root of three or more slashes, which is one. An
|
|
101
|
+
* absolute segment discards what came before it, as `joinPath('a', '/b')` is `/b`, and
|
|
102
|
+
* nothing at all is `.`. Measured; `home.test.ts` holds the table.
|
|
103
|
+
*
|
|
104
|
+
* The home itself is `pathHome`'s; this is the join the paragraph above leaves to the caller.
|
|
105
|
+
*/
|
|
106
|
+
function joinPath(...segments) {
|
|
107
|
+
const joined = posixJoin('', ...segments);
|
|
108
|
+
let root = '';
|
|
109
|
+
let rest = joined;
|
|
110
|
+
if (joined.startsWith('/')) {
|
|
111
|
+
root = joined[1] === '/' && joined[2] !== '/' ? '//' : '/';
|
|
112
|
+
rest = joined.slice(root.length);
|
|
113
|
+
}
|
|
114
|
+
const parts = rest.split('/').filter((part) => part !== '' && part !== '.');
|
|
115
|
+
return root + parts.join('/') || '.';
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* `name`'s home in the password database, or null for a name the database does not hold.
|
|
119
|
+
*
|
|
120
|
+
* `/etc/passwd` first, the first line with that name, as the `files` source answers; then
|
|
121
|
+
* the current user through `os.userInfo()`, which asks the whole name service. Node has no
|
|
122
|
+
* `getpwnam`, and nothing here may start a process for `getent`, so ANOTHER user known only
|
|
123
|
+
* to a network source (LDAP, sssd) is not found here, where `getpwnam` would find it.
|
|
124
|
+
*/
|
|
125
|
+
function passwordHome(name) {
|
|
126
|
+
let table = '';
|
|
127
|
+
try {
|
|
128
|
+
table = fs.readFileSync('/etc/passwd', 'utf8');
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (!isOsError(error))
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
for (const line of table.split('\n')) {
|
|
135
|
+
const fields = line.split(':');
|
|
136
|
+
if (fields.length >= 7 && fields[0] === name)
|
|
137
|
+
return fields[5] ?? '';
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const self = os.userInfo();
|
|
141
|
+
if (self.username === name)
|
|
142
|
+
return self.homedir;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (!isOsError(error))
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* `target` with a leading `~` or `~name` expanded, which is not "replace a leading `~` with
|
|
152
|
+
* the home".
|
|
153
|
+
*
|
|
154
|
+
* The path is spelled first -- a trailing `/`, `.` parts and doubled slashes gone, `..`
|
|
155
|
+
* kept -- and only a FIRST PART that starts with `~` is expanded: `~` is `pathHome()`, and
|
|
156
|
+
* `~name` is that user's password-database home, both with trailing slashes stripped (or `/`
|
|
157
|
+
* if nothing is left) and then parsed, so a HOME holding `..` or a two-slash root keeps it.
|
|
158
|
+
* A `~name` nobody has, or a home that itself starts with `~`, is
|
|
159
|
+
* `Could not determine home directory.`, thrown as a `HomeUnknown` so the CLI's last line
|
|
160
|
+
* keeps that wording.
|
|
161
|
+
*
|
|
162
|
+
* The ports this replaces joined `pathHome()` onto the text after the `~` with `path.join`:
|
|
163
|
+
* `~bob/x` was the CURRENT user's `bob/x`, `~/x/` kept its slash, and a HOME of `/a/../b`
|
|
164
|
+
* became `/b`.
|
|
165
|
+
*/
|
|
166
|
+
function pathExpandUser(target) {
|
|
167
|
+
const spelled = joinPath(target);
|
|
168
|
+
if (!spelled.startsWith('~'))
|
|
169
|
+
return spelled;
|
|
170
|
+
const cut = spelled.indexOf('/');
|
|
171
|
+
const first = cut < 0 ? spelled : spelled.slice(0, cut);
|
|
172
|
+
const rest = cut < 0 ? '' : spelled.slice(cut + 1);
|
|
173
|
+
let home = first === '~' ? pathHome() : passwordHome(first.slice(1));
|
|
174
|
+
if (home !== null && first !== '~')
|
|
175
|
+
home = home.replace(/\/+$/u, '') || '/';
|
|
176
|
+
if (home === null || home.startsWith('~')) {
|
|
177
|
+
const refused = new Error('Could not determine home directory.');
|
|
178
|
+
refused.name = 'HomeUnknown';
|
|
179
|
+
throw refused;
|
|
180
|
+
}
|
|
181
|
+
return joinPath(home, rest);
|
|
182
|
+
}
|
|
183
|
+
/** A plain POSIX join: no normalisation at all, and an absolute segment restarts the path. */
|
|
184
|
+
function posixJoin(first, ...rest) {
|
|
185
|
+
let joined = first;
|
|
186
|
+
for (const segment of rest) {
|
|
187
|
+
if (segment.startsWith('/'))
|
|
188
|
+
joined = segment;
|
|
189
|
+
else if (joined === '' || joined.endsWith('/'))
|
|
190
|
+
joined += segment;
|
|
191
|
+
else
|
|
192
|
+
joined += `/${segment}`;
|
|
193
|
+
}
|
|
194
|
+
return joined;
|
|
195
|
+
}
|
|
196
|
+
/** Head and tail, the head's trailing slashes dropped unless it is all slashes. */
|
|
197
|
+
function posixSplit(target) {
|
|
198
|
+
const at = target.lastIndexOf('/') + 1;
|
|
199
|
+
let head = target.slice(0, at);
|
|
200
|
+
if (head !== '' && !/^\/+$/u.test(head))
|
|
201
|
+
head = head.replace(/\/+$/u, '');
|
|
202
|
+
return [head, target.slice(at)];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Lexical normalisation, which is not `path.normalize`: a root of exactly two slashes is
|
|
206
|
+
* kept, and a trailing `/` is not.
|
|
207
|
+
*/
|
|
208
|
+
function posixNormpath(target) {
|
|
209
|
+
if (target === '')
|
|
210
|
+
return '.';
|
|
211
|
+
const slashes = !target.startsWith('/')
|
|
212
|
+
? ''
|
|
213
|
+
: target.startsWith('//') && !target.startsWith('///')
|
|
214
|
+
? '//'
|
|
215
|
+
: '/';
|
|
216
|
+
const parts = [];
|
|
217
|
+
for (const part of target.split('/')) {
|
|
218
|
+
if (part === '' || part === '.')
|
|
219
|
+
continue;
|
|
220
|
+
if (part !== '..' ||
|
|
221
|
+
(slashes === '' && parts.length === 0) ||
|
|
222
|
+
(parts.length > 0 && parts[parts.length - 1] === '..')) {
|
|
223
|
+
parts.push(part);
|
|
224
|
+
}
|
|
225
|
+
else if (parts.length > 0) {
|
|
226
|
+
parts.pop();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return slashes + parts.join('/') || '.';
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The absolute path: joined onto the working directory when relative, then `posixNormpath`
|
|
233
|
+
* -- so a `..` is folded lexically and a root of exactly two slashes is kept, where
|
|
234
|
+
* `path.resolve` makes that root one slash.
|
|
235
|
+
*/
|
|
236
|
+
function osPathAbspath(target) {
|
|
237
|
+
return posixNormpath(target.startsWith('/') ? target : posixJoin(process.cwd(), target));
|
|
238
|
+
}
|
|
239
|
+
/** Whether `error` is a failed system call, which carries a numeric errno. */
|
|
240
|
+
function isOsError(error) {
|
|
241
|
+
return typeof error?.errno === 'number';
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The non-strict realpath walk: each component is looked up as it is reached, so a symlink
|
|
245
|
+
* is followed BEFORE a `..` after it walks back out -- the kernel's order, which
|
|
246
|
+
* `path.resolve` (and `fs.realpathSync`, which calls it first) do not keep. A failed
|
|
247
|
+
* system call on the lookup means "not a link"; a loop returns what it has, unfinished.
|
|
248
|
+
*/
|
|
249
|
+
function joinRealpath(start, remaining, seen) {
|
|
250
|
+
let current = start;
|
|
251
|
+
let rest = remaining;
|
|
252
|
+
if (rest.startsWith('/')) {
|
|
253
|
+
rest = rest.slice(1);
|
|
254
|
+
current = '/';
|
|
255
|
+
}
|
|
256
|
+
while (rest !== '') {
|
|
257
|
+
const cut = rest.indexOf('/');
|
|
258
|
+
let name = cut < 0 ? rest : rest.slice(0, cut);
|
|
259
|
+
rest = cut < 0 ? '' : rest.slice(cut + 1);
|
|
260
|
+
if (name === '' || name === '.')
|
|
261
|
+
continue;
|
|
262
|
+
if (name === '..') {
|
|
263
|
+
if (current !== '') {
|
|
264
|
+
[current, name] = posixSplit(current);
|
|
265
|
+
if (name === '..')
|
|
266
|
+
current = posixJoin(current, '..', '..');
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
current = '..';
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const next = posixJoin(current, name);
|
|
274
|
+
let isLink = false;
|
|
275
|
+
try {
|
|
276
|
+
isLink = fs.lstatSync(next).isSymbolicLink();
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
if (!isOsError(error))
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
if (!isLink) {
|
|
283
|
+
current = next;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (seen.has(next)) {
|
|
287
|
+
const cached = seen.get(next) ?? null;
|
|
288
|
+
if (cached !== null) {
|
|
289
|
+
current = cached;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
return [posixJoin(next, rest), false];
|
|
293
|
+
}
|
|
294
|
+
seen.set(next, null);
|
|
295
|
+
const [resolved, ok] = joinRealpath(current, fs.readlinkSync(next), seen);
|
|
296
|
+
if (!ok)
|
|
297
|
+
return [posixJoin(resolved, rest), false];
|
|
298
|
+
current = resolved;
|
|
299
|
+
seen.set(next, current);
|
|
300
|
+
}
|
|
301
|
+
return [current, true];
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* `target` resolved: the realpath of `joinPath`'s spelling of the path, then the `stat`
|
|
305
|
+
* that turns a symlink loop into a `Symlink loop from '...'` error.
|
|
306
|
+
*
|
|
307
|
+
* NOT `path.resolve` and not `fs.realpathSync`: both fold every `..` against the text before
|
|
308
|
+
* it first, so `link/../hh` with `link -> other/sub` resolved to `hh` in the working directory
|
|
309
|
+
* where the kernel walks through the link to `other/hh`. A path that does not exist resolves
|
|
310
|
+
* as far as it can and keeps the rest.
|
|
311
|
+
*/
|
|
312
|
+
function pathResolve(target) {
|
|
313
|
+
const spelled = joinPath(target);
|
|
314
|
+
const [found] = joinRealpath('', spelled, new Map());
|
|
315
|
+
const resolved = joinPath(posixNormpath(found.startsWith('/') ? found : posixJoin(process.cwd(), found)));
|
|
316
|
+
try {
|
|
317
|
+
fs.statSync(resolved);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (isOsError(error) && error.code === 'ELOOP') {
|
|
321
|
+
throw new Error(`Symlink loop from '${resolved}'`, { cause: error });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return resolved;
|
|
325
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Durable notes for side effects a killed process must not leave, asked for from a layer
|
|
4
|
+
* that must not import the module that stores them.
|
|
5
|
+
*
|
|
6
|
+
* `core/journal` ranks above `core/eks`, and `core/eks` needs it, for the most
|
|
7
|
+
* expensive note in the product: `eksctl create cluster` is twenty minutes of building a
|
|
8
|
+
* VPC, a NAT gateway and a control plane, and the note goes down BEFORE the call and is
|
|
9
|
+
* cleared only once eksctl has returned. A note written afterwards describes nothing --
|
|
10
|
+
* the whole case it exists for is the process not getting there.
|
|
11
|
+
*
|
|
12
|
+
* The registry is the same dependency inversion `events.ts` uses for sinks, `teammode.ts`
|
|
13
|
+
* for its probe and `audit.ts` for its recorder: this module is owned by a lower layer,
|
|
14
|
+
* and the upper one registers into it.
|
|
15
|
+
*
|
|
16
|
+
* ## The default writes to stderr, for a sharper version of audit's reason
|
|
17
|
+
*
|
|
18
|
+
* The journal is best-effort -- a journal that cannot be written must not stop the
|
|
19
|
+
* operation it was describing, and a record returns '' for an unwritable directory. So
|
|
20
|
+
* throwing here would invent a behaviour. But a dropped CLUSTER_UNFINISHED note is not a
|
|
21
|
+
* missing log line: it is the only record that something billable may exist, written
|
|
22
|
+
* precisely for the case where the process does not survive to say so itself. Silence
|
|
23
|
+
* there is the failure the note exists to prevent.
|
|
24
|
+
*
|
|
25
|
+
* So the fallback WRITES THE NOTE, to stderr, with its kind, its subject and its detail.
|
|
26
|
+
* Nothing is lost, and the gap is loud the first time somebody builds a cluster before
|
|
27
|
+
* the real journal is registered.
|
|
28
|
+
*
|
|
29
|
+
* ## Subject predicates are queued, not dropped
|
|
30
|
+
*
|
|
31
|
+
* `registerSubjectPredicate` runs at import time (`core/eks.ts`), which can be before
|
|
32
|
+
* `core/journal` has installed a sink here. A registration made against no sink is
|
|
33
|
+
* REMEMBERED and replayed when one arrives, because the alternative -- losing it -- makes
|
|
34
|
+
* recovery unable to ask whether a note's subject still exists, which is what turns a
|
|
35
|
+
* stale note into a permanent false alarm.
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.CLUSTER_UNFINISHED = void 0;
|
|
39
|
+
exports.installJournalSink = installJournalSink;
|
|
40
|
+
exports.journalSinkInstalled = journalSinkInstalled;
|
|
41
|
+
exports.registerSubjectPredicate = registerSubjectPredicate;
|
|
42
|
+
exports.clearPendingPredicates = clearPendingPredicates;
|
|
43
|
+
exports.recordJournal = recordJournal;
|
|
44
|
+
exports.clearJournal = clearJournal;
|
|
45
|
+
/** A cluster create that was started and never seen to return. */
|
|
46
|
+
exports.CLUSTER_UNFINISHED = 'cluster_unfinished';
|
|
47
|
+
let sink = null;
|
|
48
|
+
/** Registrations made before a sink existed, replayed when one arrives. */
|
|
49
|
+
const pending = [];
|
|
50
|
+
/** Install the real journal. Returns a function that removes it again. */
|
|
51
|
+
function installJournalSink(fn) {
|
|
52
|
+
sink = fn;
|
|
53
|
+
for (const [kind, predicate] of pending)
|
|
54
|
+
fn.registerSubjectPredicate(kind, predicate);
|
|
55
|
+
pending.length = 0;
|
|
56
|
+
return () => {
|
|
57
|
+
if (sink === fn)
|
|
58
|
+
sink = null;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function journalSinkInstalled() {
|
|
62
|
+
return sink !== null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Teach recovery how to ask whether one kind of note's subject still exists.
|
|
66
|
+
*
|
|
67
|
+
* Queued when no sink is installed, because this runs at module scope and losing it would
|
|
68
|
+
* leave recovery unable to tell a live note from a stale one.
|
|
69
|
+
*/
|
|
70
|
+
function registerSubjectPredicate(kind, predicate) {
|
|
71
|
+
if (sink === null) {
|
|
72
|
+
pending.push([kind, predicate]);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
sink.registerSubjectPredicate(kind, predicate);
|
|
76
|
+
}
|
|
77
|
+
/** For a test that wants a clean slate; the queue is module state like any other. */
|
|
78
|
+
function clearPendingPredicates() {
|
|
79
|
+
pending.length = 0;
|
|
80
|
+
}
|
|
81
|
+
function shout(kind, workspace, detail) {
|
|
82
|
+
let rendered;
|
|
83
|
+
try {
|
|
84
|
+
rendered = JSON.stringify(detail);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
rendered = '{}';
|
|
88
|
+
}
|
|
89
|
+
process.stderr.write(`houston.journal\t${kind}\t${workspace || '-'}\t${rendered}\n`);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Note a side effect. Returns the entry id, or '' when there is nothing holding it.
|
|
93
|
+
*
|
|
94
|
+
* Best-effort by contract: a sink that throws must not stop the operation it was
|
|
95
|
+
* describing, exactly as an unwritable journal directory does not.
|
|
96
|
+
*/
|
|
97
|
+
function recordJournal(kind, workspace, detail = {}) {
|
|
98
|
+
if (sink !== null) {
|
|
99
|
+
try {
|
|
100
|
+
return sink.record(kind, workspace, detail);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Fall through and say it out loud rather than losing the note entirely.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
shout(kind, workspace, detail);
|
|
107
|
+
return '';
|
|
108
|
+
}
|
|
109
|
+
/** Forget an entry. An empty id is a note that was never written, and is a no-op. */
|
|
110
|
+
function clearJournal(entryId) {
|
|
111
|
+
if (entryId === '')
|
|
112
|
+
return;
|
|
113
|
+
if (sink === null)
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
sink.clear(entryId);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Clearing a note that cannot be cleared leaves a stale one, which recovery reports
|
|
120
|
+
// and a person resolves. Raising here would fail an operation that has succeeded.
|
|
121
|
+
}
|
|
122
|
+
}
|