@idleware/ringi 0.7.1 → 0.7.2
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/package.json +1 -1
- package/target/dts/core/hub/usecases/hubs.d.ts +1 -0
- package/target/dts/lib/fail.d.ts +1 -0
- package/target/esm/clients/cli/operator/hub-commands.js +1 -1
- package/target/esm/core/hub/usecases/hubs.js +7 -5
- package/target/esm/lib/fail.js +6 -1
- package/target/esm/lib/index.js +4 -3
package/package.json
CHANGED
package/target/dts/lib/fail.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const createHub = (o) => {
|
|
|
14
14
|
const r = Hubs.create(arg ?? '', { signed: flag(o, 'signed'), url: opt(o, 'url') });
|
|
15
15
|
if (!r.add)
|
|
16
16
|
return out(`created hub ${arg} (${r.H.dir})`);
|
|
17
|
-
return out(`created signed hub ${arg}${r.
|
|
17
|
+
return out(`created signed hub ${arg}${r.remote ? `, published to ${r.remote}` : ''}. Its root key stays on this machine (${r.rootKey}).
|
|
18
18
|
Give every machine that joins it, out of band:
|
|
19
19
|
${r.add}`);
|
|
20
20
|
};
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { DEFAULT_PROFILE, PROFILES_CAPABILITY, parseProfile } from '../work/index.js';
|
|
3
3
|
import { OPERATOR, config, createHub, hubNames, openHub, roomNames, setConfig, transportOf } from '../rooms/index.js';
|
|
4
4
|
import { hubPorts } from '../ports/index.js';
|
|
5
|
-
import { fail, strictJson, words } from '../../../lib/index.js';
|
|
5
|
+
import { fail, strictJson, withoutCredentials, words } from '../../../lib/index.js';
|
|
6
6
|
import { ID_RE, compose } from '../protocol/index.js';
|
|
7
|
+
// A remote as shown and handed to other machines: never with a password or token in it; each machine has its own.
|
|
8
|
+
const shown = (url) => url ? withoutCredentials(url) : null;
|
|
7
9
|
// The operator's terminal context picks the hub unless one is named.
|
|
8
10
|
export const hubOf = (name) => openHub(name ?? config().hub);
|
|
9
11
|
export const hubs = () => {
|
|
@@ -14,7 +16,7 @@ export const hubs = () => {
|
|
|
14
16
|
return hubNames().map(n => {
|
|
15
17
|
const H = openHub(n);
|
|
16
18
|
return { name: H.name, current: H.name === cur, store: H.d.store.type, trust: H.contract.trust, contract: H.contract.version,
|
|
17
|
-
rooms: roomNames(H).length, remote: H.d.store.remote
|
|
19
|
+
rooms: roomNames(H).length, remote: shown(H.d.store.remote), dir: H.dir };
|
|
18
20
|
});
|
|
19
21
|
};
|
|
20
22
|
// A new hub; a signed one makes its root key here and returns what other machines need to pin it.
|
|
@@ -22,9 +24,9 @@ export const create = (name, { signed = false, url } = {}) => {
|
|
|
22
24
|
if (!ID_RE.test(name))
|
|
23
25
|
fail('usage: ringi hub create <name> [--signed [--url <git url>]]');
|
|
24
26
|
const { custody } = createHub(name, { signed, url });
|
|
25
|
-
const H = openHub(name);
|
|
26
|
-
return { H, rootKey: custody,
|
|
27
|
-
add: H.signed ? `ringi hub add ${name} ${
|
|
27
|
+
const H = openHub(name), remote = shown(H.d.store.remote);
|
|
28
|
+
return { H, rootKey: custody, remote,
|
|
29
|
+
add: H.signed ? `ringi hub add ${name} ${remote ?? '<url>'} --root '${H.d.root}' --genesis ${H.d.genesis}` : null };
|
|
28
30
|
};
|
|
29
31
|
export const use = (name) => {
|
|
30
32
|
openHub(name);
|
package/target/esm/lib/fail.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// fail: a refusal ringi explains (Fail, shown as its message), apart from a bug (any other error, shown with its stack).
|
|
2
|
+
// A URL's credentials never shown, however git or a person wrote them: everything before its host goes, up to the last
|
|
3
|
+
// `@` (a token may be the whole user, or hold an `@`), except an SSH login name, which is no secret.
|
|
4
|
+
const USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)([^\s/?#'"]*)@/gi;
|
|
5
|
+
export const withoutCredentials = (text) => text.replace(USERINFO, (_, scheme, user) => /^ssh:/i.test(scheme) && !user.includes(':') ? `${scheme}${user}@` : scheme);
|
|
2
6
|
export class Fail extends Error {
|
|
3
7
|
}
|
|
4
|
-
|
|
8
|
+
// Every refusal passes here, git's own diagnostics included, so none shows a URL's credentials.
|
|
9
|
+
export const fail = (msg) => { throw new Fail(withoutCredentials(msg)); };
|
|
5
10
|
export const errno = (e) => e?.code;
|
|
6
11
|
// A write the host refused: what to do is the same for every host; a tool's own way (its sandbox settings) is added
|
|
7
12
|
// by the interface that knows the tools (cli.ts).
|
package/target/esm/lib/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// lib: helpers that know nothing of ringi and touch no host: failing (fail.ts), notes, formatting, strict JSON
|
|
2
2
|
// (json.ts). Files and locks are the adapters' (adapters/fs).
|
|
3
|
-
|
|
4
|
-
//
|
|
3
|
+
import { withoutCredentials } from './fail.js';
|
|
4
|
+
// Notes and alarms go where the program sends them (composition/: stderr), never with a URL's credentials. Those
|
|
5
|
+
// written before it says where wait for it, so none is lost to the order modules load in.
|
|
5
6
|
const notes = [];
|
|
6
7
|
let sink = null;
|
|
7
8
|
export const notesTo = (fn) => {
|
|
@@ -10,7 +11,7 @@ export const notesTo = (fn) => {
|
|
|
10
11
|
fn(line);
|
|
11
12
|
};
|
|
12
13
|
export const note = (s) => {
|
|
13
|
-
const line = `ringi: ${s}\n`;
|
|
14
|
+
const line = `ringi: ${withoutCredentials(s)}\n`;
|
|
14
15
|
if (sink)
|
|
15
16
|
sink(line);
|
|
16
17
|
else
|