unbound-cli 0.1.10 → 0.1.11
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/src/commands/status.js +8 -8
- package/src/commands/whoami.js +5 -3
- package/src/config.js +16 -0
package/package.json
CHANGED
package/src/commands/status.js
CHANGED
|
@@ -23,35 +23,35 @@ Examples:
|
|
|
23
23
|
.action(async (opts) => {
|
|
24
24
|
try {
|
|
25
25
|
const loggedIn = config.isLoggedIn();
|
|
26
|
-
const cfg = config.readConfig();
|
|
27
26
|
|
|
28
27
|
const pairs = [
|
|
29
28
|
['Config file', config.CONFIG_FILE],
|
|
30
29
|
['Logged in', loggedIn ? 'Yes' : 'No'],
|
|
31
30
|
];
|
|
32
31
|
|
|
33
|
-
if (loggedIn) {
|
|
34
|
-
pairs.push(['Email', cfg.email || '-']);
|
|
35
|
-
pairs.push(['Organization', cfg.org_name || '-']);
|
|
36
|
-
pairs.push(['Unbound Gateway', config.getFrontendUrl()]);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
32
|
// Check API connectivity
|
|
40
33
|
let connectivity = 'Not checked (not logged in)';
|
|
41
34
|
if (loggedIn) {
|
|
42
35
|
const spin = output.spinner('Checking API connectivity...');
|
|
43
36
|
try {
|
|
44
|
-
await api.get('/api/v1/users/privileges/');
|
|
37
|
+
const privileges = await api.get('/api/v1/users/privileges/');
|
|
38
|
+
config.backfillUserInfo(privileges);
|
|
45
39
|
spin.stop();
|
|
46
40
|
connectivity = 'Connected';
|
|
47
41
|
} catch (err) {
|
|
48
42
|
spin.stop();
|
|
49
43
|
connectivity = `Error: ${err.message}`;
|
|
50
44
|
}
|
|
45
|
+
|
|
46
|
+
const cfg = config.readConfig();
|
|
47
|
+
pairs.push(['Email', cfg.email || '-']);
|
|
48
|
+
pairs.push(['Organization', cfg.org_name || '-']);
|
|
49
|
+
pairs.push(['Unbound Gateway', config.getFrontendUrl()]);
|
|
51
50
|
}
|
|
52
51
|
pairs.push(['API status', connectivity]);
|
|
53
52
|
|
|
54
53
|
if (opts.json) {
|
|
54
|
+
const cfg = loggedIn ? config.readConfig() : {};
|
|
55
55
|
output.json({
|
|
56
56
|
config_file: config.CONFIG_FILE,
|
|
57
57
|
logged_in: loggedIn,
|
package/src/commands/whoami.js
CHANGED
|
@@ -36,17 +36,19 @@ Examples:
|
|
|
36
36
|
try {
|
|
37
37
|
const privileges = await api.get('/api/v1/users/privileges/');
|
|
38
38
|
spin.stop();
|
|
39
|
+
config.backfillUserInfo(privileges);
|
|
39
40
|
|
|
40
41
|
const role = roleFromPrivileges(privileges);
|
|
42
|
+
const freshCfg = config.readConfig();
|
|
41
43
|
|
|
42
44
|
if (opts.json) {
|
|
43
|
-
output.json({ email:
|
|
45
|
+
output.json({ email: freshCfg.email || null, organization: freshCfg.org_name || null, role });
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
output.keyValue([
|
|
48
|
-
['Email',
|
|
49
|
-
['Organization',
|
|
50
|
+
['Email', freshCfg.email || '-'],
|
|
51
|
+
['Organization', freshCfg.org_name || '-'],
|
|
50
52
|
['Role', role],
|
|
51
53
|
]);
|
|
52
54
|
} catch (err) {
|
package/src/config.js
CHANGED
|
@@ -70,6 +70,21 @@ function isLoggedIn() {
|
|
|
70
70
|
return !!getApiKey();
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function backfillUserInfo(apiResponse) {
|
|
74
|
+
if (!apiResponse) return;
|
|
75
|
+
const cfg = readConfig();
|
|
76
|
+
let changed = false;
|
|
77
|
+
if (!cfg.email && apiResponse.email) {
|
|
78
|
+
cfg.email = apiResponse.email;
|
|
79
|
+
changed = true;
|
|
80
|
+
}
|
|
81
|
+
if (!cfg.org_name && (apiResponse.org_name || apiResponse.organization_name || apiResponse.organization)) {
|
|
82
|
+
cfg.org_name = apiResponse.org_name || apiResponse.organization_name || apiResponse.organization;
|
|
83
|
+
changed = true;
|
|
84
|
+
}
|
|
85
|
+
if (changed) writeConfig(cfg);
|
|
86
|
+
}
|
|
87
|
+
|
|
73
88
|
module.exports = {
|
|
74
89
|
CONFIG_DIR,
|
|
75
90
|
CONFIG_FILE,
|
|
@@ -84,4 +99,5 @@ module.exports = {
|
|
|
84
99
|
setFrontendUrl,
|
|
85
100
|
clearConfig,
|
|
86
101
|
isLoggedIn,
|
|
102
|
+
backfillUserInfo,
|
|
87
103
|
};
|