@routr/ctl 2.0.8-alpha.21
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 +21 -0
- package/README.md +973 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +25 -0
- package/bin/run.cmd +3 -0
- package/dist/base.d.ts +8 -0
- package/dist/base.js +42 -0
- package/dist/commands/acl/create.d.ts +6 -0
- package/dist/commands/acl/create.js +122 -0
- package/dist/commands/acl/delete.d.ts +6 -0
- package/dist/commands/acl/delete.js +40 -0
- package/dist/commands/acl/get.d.ts +19 -0
- package/dist/commands/acl/get.js +135 -0
- package/dist/commands/acl/update.d.ts +11 -0
- package/dist/commands/acl/update.js +100 -0
- package/dist/commands/agents/create.d.ts +6 -0
- package/dist/commands/agents/create.js +179 -0
- package/dist/commands/agents/delete.d.ts +6 -0
- package/dist/commands/agents/delete.js +40 -0
- package/dist/commands/agents/get.d.ts +19 -0
- package/dist/commands/agents/get.js +149 -0
- package/dist/commands/agents/update.d.ts +11 -0
- package/dist/commands/agents/update.js +150 -0
- package/dist/commands/credentials/create.d.ts +6 -0
- package/dist/commands/credentials/create.js +122 -0
- package/dist/commands/credentials/delete.d.ts +6 -0
- package/dist/commands/credentials/delete.js +40 -0
- package/dist/commands/credentials/get.d.ts +19 -0
- package/dist/commands/credentials/get.js +130 -0
- package/dist/commands/credentials/update.d.ts +11 -0
- package/dist/commands/credentials/update.js +98 -0
- package/dist/commands/domains/create.d.ts +6 -0
- package/dist/commands/domains/create.js +187 -0
- package/dist/commands/domains/delete.d.ts +6 -0
- package/dist/commands/domains/delete.js +40 -0
- package/dist/commands/domains/get.d.ts +19 -0
- package/dist/commands/domains/get.js +142 -0
- package/dist/commands/domains/update.d.ts +11 -0
- package/dist/commands/domains/update.js +163 -0
- package/dist/commands/numbers/create.d.ts +6 -0
- package/dist/commands/numbers/create.js +171 -0
- package/dist/commands/numbers/delete.d.ts +6 -0
- package/dist/commands/numbers/delete.js +40 -0
- package/dist/commands/numbers/get.d.ts +19 -0
- package/dist/commands/numbers/get.js +147 -0
- package/dist/commands/numbers/update.d.ts +11 -0
- package/dist/commands/numbers/update.js +130 -0
- package/dist/commands/peers/create.d.ts +6 -0
- package/dist/commands/peers/create.js +177 -0
- package/dist/commands/peers/delete.d.ts +6 -0
- package/dist/commands/peers/delete.js +40 -0
- package/dist/commands/peers/get.d.ts +19 -0
- package/dist/commands/peers/get.js +159 -0
- package/dist/commands/peers/update.d.ts +11 -0
- package/dist/commands/peers/update.js +156 -0
- package/dist/commands/trunks/create.d.ts +6 -0
- package/dist/commands/trunks/create.js +231 -0
- package/dist/commands/trunks/delete.d.ts +6 -0
- package/dist/commands/trunks/delete.js +40 -0
- package/dist/commands/trunks/get.d.ts +19 -0
- package/dist/commands/trunks/get.js +145 -0
- package/dist/commands/trunks/update.d.ts +11 -0
- package/dist/commands/trunks/update.js +217 -0
- package/dist/countries.d.ts +4 -0
- package/dist/countries.js +270 -0
- package/dist/delete.d.ts +9 -0
- package/dist/delete.js +46 -0
- package/dist/help.d.ts +6 -0
- package/dist/help.js +84 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +97 -0
- package/dist/validators.d.ts +16 -0
- package/dist/validators.js +180 -0
- package/oclif.manifest.json +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,179 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/*
|
|
30
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
31
|
+
* http://github.com/fonoster
|
|
32
|
+
*
|
|
33
|
+
* This file is part of Routr.
|
|
34
|
+
*
|
|
35
|
+
* Licensed under the MIT License (the "License");
|
|
36
|
+
* you may not use this file except in compliance with
|
|
37
|
+
* the License. You may obtain a copy of the License at
|
|
38
|
+
*
|
|
39
|
+
* https://opensource.org/licenses/MIT
|
|
40
|
+
*
|
|
41
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
42
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
43
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
44
|
+
* See the License for the specific language governing permissions and
|
|
45
|
+
* limitations under the License.
|
|
46
|
+
*/
|
|
47
|
+
/* eslint-disable require-jsdoc */
|
|
48
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
49
|
+
const core_1 = require("@oclif/core");
|
|
50
|
+
const base_1 = require("../../base");
|
|
51
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
52
|
+
const common_1 = require("@routr/common");
|
|
53
|
+
const validators_1 = require("../../validators");
|
|
54
|
+
const fuzzy_search_1 = __importDefault(require("fuzzy-search"));
|
|
55
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
56
|
+
// NOTE: Newer versions of inquirer have a bug that causes the following error:
|
|
57
|
+
// (node:75345) [ERR_REQUIRE_ESM] Error Plugin: @routr/ctl [ERR_REQUIRE_ESM]: require() of ES Module
|
|
58
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
59
|
+
const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
|
|
60
|
+
inquirer_1.default.registerPrompt("autocomplete", inquirer_autocomplete_prompt_1.default);
|
|
61
|
+
class CreateAgentCommand extends base_1.BaseCommand {
|
|
62
|
+
async run() {
|
|
63
|
+
const { flags } = await this.parse(CreateAgentCommand);
|
|
64
|
+
const { endpoint, insecure } = flags;
|
|
65
|
+
this.log("This utility will help you create a new Agent.");
|
|
66
|
+
this.log("Press ^C at any time to quit.");
|
|
67
|
+
// TODO: Fix hardcoded pageSize
|
|
68
|
+
const domains = await new sdk_1.default.Domains({ endpoint, insecure }).listDomains({
|
|
69
|
+
pageSize: 25,
|
|
70
|
+
pageToken: ""
|
|
71
|
+
});
|
|
72
|
+
// TODO: Fix hardcoded pageSize
|
|
73
|
+
const credentials = await new sdk_1.default.Credentials({
|
|
74
|
+
endpoint,
|
|
75
|
+
insecure
|
|
76
|
+
}).listCredentials({
|
|
77
|
+
pageSize: 25,
|
|
78
|
+
pageToken: ""
|
|
79
|
+
});
|
|
80
|
+
const domainsList = domains.items.map((domain) => {
|
|
81
|
+
return {
|
|
82
|
+
name: domain.domainUri,
|
|
83
|
+
description: domain.name,
|
|
84
|
+
value: domain.ref
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const credentialsList = credentials.items.map((credential) => {
|
|
88
|
+
return { name: credential.name, value: credential.ref };
|
|
89
|
+
});
|
|
90
|
+
const searcher = new fuzzy_search_1.default(domainsList, ["name", "value", "description"], {
|
|
91
|
+
caseSensitive: false
|
|
92
|
+
});
|
|
93
|
+
const answers = await inquirer_1.default.prompt([
|
|
94
|
+
{
|
|
95
|
+
name: "name",
|
|
96
|
+
message: "Friendly Name",
|
|
97
|
+
type: "input",
|
|
98
|
+
validate: validators_1.nameValidator
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: "autocomplete",
|
|
102
|
+
name: "domainRef",
|
|
103
|
+
message: "Select a Domain",
|
|
104
|
+
source: (_, input) => searcher.search(input),
|
|
105
|
+
when: () => domains.items.length > 0
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "username",
|
|
109
|
+
message: "Username",
|
|
110
|
+
type: "input",
|
|
111
|
+
validate: validators_1.usernameValidator
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "credentialsRef",
|
|
115
|
+
message: "Credentials Name",
|
|
116
|
+
type: "list",
|
|
117
|
+
choices: [{ name: "None", value: undefined }, ...credentialsList]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "privacy",
|
|
121
|
+
message: "Privacy",
|
|
122
|
+
type: "list",
|
|
123
|
+
choices: [
|
|
124
|
+
{
|
|
125
|
+
name: "None",
|
|
126
|
+
value: common_1.CommonTypes.Privacy.NONE
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "Private",
|
|
130
|
+
value: common_1.CommonTypes.Privacy.PRIVATE
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
default: common_1.CommonTypes.Privacy.NONE
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "enabled",
|
|
137
|
+
message: "Enabled",
|
|
138
|
+
type: "confirm",
|
|
139
|
+
default: true
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "confirm",
|
|
143
|
+
message: "Ready?",
|
|
144
|
+
type: "confirm"
|
|
145
|
+
}
|
|
146
|
+
]);
|
|
147
|
+
// Re-write privacy to enum
|
|
148
|
+
answers.privacy =
|
|
149
|
+
common_1.CommonTypes.Privacy[answers.privacy.toUpperCase()];
|
|
150
|
+
if (!answers.confirm) {
|
|
151
|
+
this.warn("Aborted");
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
try {
|
|
155
|
+
core_1.CliUx.ux.action.start(`Creating Agent ${answers.name}`);
|
|
156
|
+
const api = new sdk_1.default.Agents({ endpoint, insecure });
|
|
157
|
+
const agent = await api.createAgent(answers);
|
|
158
|
+
await core_1.CliUx.ux.wait(1000);
|
|
159
|
+
core_1.CliUx.ux.action.stop(agent.ref);
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
core_1.CliUx.ux.action.stop();
|
|
163
|
+
if (e.code === grpc.status.ALREADY_EXISTS) {
|
|
164
|
+
throw new errors_1.CLIError("This Agent already exist");
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new errors_1.CLIError(e.message);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.default = CreateAgentCommand;
|
|
174
|
+
CreateAgentCommand.description = "Creates a new Agent";
|
|
175
|
+
CreateAgentCommand.examples = [
|
|
176
|
+
`<%= config.bin %> <%= command.id %>
|
|
177
|
+
Creating Agent Jhon Doe... b148b4b4-6884-4c06-bb7e-bd098f5fe793
|
|
178
|
+
`
|
|
179
|
+
];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Routr.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
/* eslint-disable require-jsdoc */
|
|
25
|
+
const delete_1 = __importDefault(require("../../delete"));
|
|
26
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
27
|
+
class DeleteAgentCommand extends delete_1.default {
|
|
28
|
+
async run() {
|
|
29
|
+
const { flags } = await this.parse(DeleteAgentCommand);
|
|
30
|
+
const { endpoint, insecure } = flags;
|
|
31
|
+
await super.deleteResource(new sdk_1.default.Agents({ endpoint, insecure }), "deleteAgent");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = DeleteAgentCommand;
|
|
35
|
+
DeleteAgentCommand.description = "Deletes an Agent";
|
|
36
|
+
DeleteAgentCommand.examples = [
|
|
37
|
+
`<%= config.bin %> <%= command.id %>
|
|
38
|
+
Deleting item 80181ca6-d4aa-4575-9375-8f72b071111... Done
|
|
39
|
+
`
|
|
40
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base";
|
|
2
|
+
import { CommandError } from "@oclif/core/lib/interfaces";
|
|
3
|
+
export default class GetAgentsCommand extends BaseCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
size: import("@oclif/core/lib/interfaces").OptionFlag<number>;
|
|
8
|
+
};
|
|
9
|
+
static args: {
|
|
10
|
+
name: string;
|
|
11
|
+
required: boolean;
|
|
12
|
+
description: string;
|
|
13
|
+
}[];
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
catch(error: {
|
|
16
|
+
code: number;
|
|
17
|
+
message: string;
|
|
18
|
+
} | CommandError): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
/*
|
|
27
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
28
|
+
* http://github.com/fonoster
|
|
29
|
+
*
|
|
30
|
+
* This file is part of Routr.
|
|
31
|
+
*
|
|
32
|
+
* Licensed under the MIT License (the "License");
|
|
33
|
+
* you may not use this file except in compliance with
|
|
34
|
+
* the License. You may obtain a copy of the License at
|
|
35
|
+
*
|
|
36
|
+
* https://opensource.org/licenses/MIT
|
|
37
|
+
*
|
|
38
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
39
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
40
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
41
|
+
* See the License for the specific language governing permissions and
|
|
42
|
+
* limitations under the License.
|
|
43
|
+
*/
|
|
44
|
+
/* eslint-disable require-jsdoc */
|
|
45
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
|
+
const core_1 = require("@oclif/core");
|
|
47
|
+
const base_1 = require("../../base");
|
|
48
|
+
const utils_1 = require("../../utils");
|
|
49
|
+
const common_1 = require("@routr/common");
|
|
50
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
51
|
+
class GetAgentsCommand extends base_1.BaseCommand {
|
|
52
|
+
async run() {
|
|
53
|
+
const { args, flags } = await this.parse(GetAgentsCommand);
|
|
54
|
+
const showTable = (request) => {
|
|
55
|
+
const { showHeader, data, self, flags } = request;
|
|
56
|
+
core_1.CliUx.ux.table(data, {
|
|
57
|
+
ref: {
|
|
58
|
+
minWidth: 7,
|
|
59
|
+
extended: true
|
|
60
|
+
},
|
|
61
|
+
name: {
|
|
62
|
+
minWidth: 7
|
|
63
|
+
},
|
|
64
|
+
username: {
|
|
65
|
+
header: "Username"
|
|
66
|
+
},
|
|
67
|
+
domain: {
|
|
68
|
+
header: "Domain",
|
|
69
|
+
get: (row) => { var _a; return ((_a = row.domain) === null || _a === void 0 ? void 0 : _a.domainUri) || "None"; }
|
|
70
|
+
},
|
|
71
|
+
privacy: {
|
|
72
|
+
header: "Privacy",
|
|
73
|
+
get: (row) => (0, utils_1.capitalize)(row.privacy)
|
|
74
|
+
},
|
|
75
|
+
credentials: {
|
|
76
|
+
header: "Credentials Name",
|
|
77
|
+
get: (row) => row.credentials
|
|
78
|
+
? `${row.credentials.name} (${row.credentials.username})`
|
|
79
|
+
: "None",
|
|
80
|
+
extended: true
|
|
81
|
+
},
|
|
82
|
+
enabled: {
|
|
83
|
+
header: "Enabled",
|
|
84
|
+
get: (row) => (row.enabled ? "Yes" : "No")
|
|
85
|
+
},
|
|
86
|
+
createdAt: {
|
|
87
|
+
header: "Created",
|
|
88
|
+
get: (row) => new Date(row.createdAt * 1000),
|
|
89
|
+
extended: true
|
|
90
|
+
},
|
|
91
|
+
updatedAt: {
|
|
92
|
+
header: "Updated",
|
|
93
|
+
get: (row) => new Date(row.updatedAt * 1000),
|
|
94
|
+
extended: true
|
|
95
|
+
},
|
|
96
|
+
extended: {
|
|
97
|
+
header: "Extended",
|
|
98
|
+
get: (row) => row.extended || {},
|
|
99
|
+
extended: true
|
|
100
|
+
},
|
|
101
|
+
apiVersion: {
|
|
102
|
+
header: "API",
|
|
103
|
+
extended: true
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
"no-header": !showHeader,
|
|
107
|
+
printLine: self.log.bind(self),
|
|
108
|
+
...flags // parsed flags
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
await (0, utils_1.showPaginatedList)({
|
|
112
|
+
showTable,
|
|
113
|
+
args,
|
|
114
|
+
flags,
|
|
115
|
+
kind: common_1.CommonConnect.Kind.AGENT,
|
|
116
|
+
self: this
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async catch(error) {
|
|
120
|
+
// To be handled globally
|
|
121
|
+
if ("code" in error && error.code === grpc.status.NOT_FOUND) {
|
|
122
|
+
const { args } = await this.parse(GetAgentsCommand);
|
|
123
|
+
throw new errors_1.CLIError("the Agent you are looking for does not exist: " + args.ref);
|
|
124
|
+
}
|
|
125
|
+
throw new errors_1.CLIError(error.message);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.default = GetAgentsCommand;
|
|
129
|
+
GetAgentsCommand.description = "Shows a list of paginated Agents or a single Agent if ref is provided";
|
|
130
|
+
GetAgentsCommand.examples = [
|
|
131
|
+
`<%= config.bin %> <%= command.id %>
|
|
132
|
+
Ref Name Username Domain Privacy Enabled
|
|
133
|
+
d31f5fb8-e367-42f7-9884-1a7999f53fe8 John Doe jdoe sip.local PRIVATE Yes
|
|
134
|
+
`
|
|
135
|
+
];
|
|
136
|
+
GetAgentsCommand.flags = {
|
|
137
|
+
size: core_1.Flags.integer({
|
|
138
|
+
char: "s",
|
|
139
|
+
description: "The number of items to return",
|
|
140
|
+
default: 50
|
|
141
|
+
})
|
|
142
|
+
};
|
|
143
|
+
GetAgentsCommand.args = [
|
|
144
|
+
{
|
|
145
|
+
name: "ref",
|
|
146
|
+
required: false,
|
|
147
|
+
description: "Optional Agents reference"
|
|
148
|
+
}
|
|
149
|
+
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base";
|
|
2
|
+
export default class UpdateCommand extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
name: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
description: string;
|
|
9
|
+
}[];
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/*
|
|
7
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
8
|
+
* http://github.com/fonoster
|
|
9
|
+
*
|
|
10
|
+
* This file is part of Routr.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the MIT License (the "License");
|
|
13
|
+
* you may not use this file except in compliance with
|
|
14
|
+
* the License. You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://opensource.org/licenses/MIT
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
/* eslint-disable require-jsdoc */
|
|
25
|
+
const core_1 = require("@oclif/core");
|
|
26
|
+
const base_1 = require("../../base");
|
|
27
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
28
|
+
const common_1 = require("@routr/common");
|
|
29
|
+
const fuzzy_search_1 = __importDefault(require("fuzzy-search"));
|
|
30
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
31
|
+
// NOTE: Newer versions of inquirer have a bug that causes the following error:
|
|
32
|
+
// (node:75345) [ERR_REQUIRE_ESM] Error Plugin: @routr/ctl [ERR_REQUIRE_ESM]: require() of ES Module
|
|
33
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
34
|
+
const validators_1 = require("../../validators");
|
|
35
|
+
class UpdateCommand extends base_1.BaseCommand {
|
|
36
|
+
async run() {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const { args, flags } = await this.parse(UpdateCommand);
|
|
39
|
+
const { endpoint, insecure } = flags;
|
|
40
|
+
const api = new sdk_1.default.Agents({ endpoint, insecure });
|
|
41
|
+
this.log("This utility will help you update an existing Agent.");
|
|
42
|
+
this.log("Press ^C at any time to quit.");
|
|
43
|
+
const agentFromDB = await api.getAgent(args.ref);
|
|
44
|
+
// TODO: Fix hardcoded pageSize
|
|
45
|
+
const domains = await new sdk_1.default.Domains({ endpoint, insecure }).listDomains({
|
|
46
|
+
pageSize: 25,
|
|
47
|
+
pageToken: ""
|
|
48
|
+
});
|
|
49
|
+
// TODO: Fix hardcoded pageSize
|
|
50
|
+
const credentials = await new sdk_1.default.Credentials({
|
|
51
|
+
endpoint,
|
|
52
|
+
insecure
|
|
53
|
+
}).listCredentials({
|
|
54
|
+
pageSize: 25,
|
|
55
|
+
pageToken: ""
|
|
56
|
+
});
|
|
57
|
+
const domainsList = (_a = domains.items) === null || _a === void 0 ? void 0 : _a.map((domain) => {
|
|
58
|
+
return { name: domain.domainUri, value: domain.ref };
|
|
59
|
+
});
|
|
60
|
+
const credentialsList = (_b = credentials.items) === null || _b === void 0 ? void 0 : _b.map((credential) => {
|
|
61
|
+
return { name: credential.name, value: credential.ref };
|
|
62
|
+
});
|
|
63
|
+
const searcher = new fuzzy_search_1.default(domainsList, ["name", "value", "description"], {
|
|
64
|
+
caseSensitive: false
|
|
65
|
+
});
|
|
66
|
+
const answers = await inquirer_1.default.prompt([
|
|
67
|
+
{
|
|
68
|
+
name: "name",
|
|
69
|
+
message: "Friendly Name",
|
|
70
|
+
type: "input",
|
|
71
|
+
default: agentFromDB.name,
|
|
72
|
+
validate: validators_1.nameValidator
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "autocomplete",
|
|
76
|
+
name: "domainRef",
|
|
77
|
+
message: "Select a Domain",
|
|
78
|
+
source: (_, input) => searcher.search(input),
|
|
79
|
+
when: () => domains.items.length > 0
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "credentialsRef",
|
|
83
|
+
message: "Credentials Name",
|
|
84
|
+
type: "list",
|
|
85
|
+
choices: [{ name: "None", value: undefined }, ...credentialsList],
|
|
86
|
+
default: agentFromDB.credentialsRef
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "privacy",
|
|
90
|
+
message: "Privacy",
|
|
91
|
+
type: "list",
|
|
92
|
+
choices: [
|
|
93
|
+
{
|
|
94
|
+
name: "None",
|
|
95
|
+
value: common_1.CommonTypes.Privacy.NONE
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "Private",
|
|
99
|
+
value: common_1.CommonTypes.Privacy.PRIVATE
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
default: agentFromDB.privacy
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "enabled",
|
|
106
|
+
message: "Enabled",
|
|
107
|
+
type: "confirm",
|
|
108
|
+
default: agentFromDB.enabled
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "confirm",
|
|
112
|
+
message: "Ready?",
|
|
113
|
+
type: "confirm"
|
|
114
|
+
}
|
|
115
|
+
]);
|
|
116
|
+
// Re-write privacy to enum
|
|
117
|
+
answers.privacy =
|
|
118
|
+
common_1.CommonTypes.Privacy[answers.privacy.toUpperCase()];
|
|
119
|
+
answers.ref = args.ref;
|
|
120
|
+
if (!answers.confirm) {
|
|
121
|
+
this.warn("Aborted");
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
try {
|
|
125
|
+
core_1.CliUx.ux.action.start(`Updating Agent ${answers.name}`);
|
|
126
|
+
const agent = await api.updateAgent(answers);
|
|
127
|
+
await core_1.CliUx.ux.wait(1000);
|
|
128
|
+
core_1.CliUx.ux.action.stop(agent.ref);
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
core_1.CliUx.ux.action.stop();
|
|
132
|
+
throw new errors_1.CLIError(e.message);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.default = UpdateCommand;
|
|
138
|
+
UpdateCommand.description = "Updates an existing Agent";
|
|
139
|
+
UpdateCommand.examples = [
|
|
140
|
+
`<%= config.bin %> <%= command.id %>
|
|
141
|
+
Updating Agent John Doe... 80181ca6-d4aa-4575-9375-8f72b07d5555
|
|
142
|
+
`
|
|
143
|
+
];
|
|
144
|
+
UpdateCommand.args = [
|
|
145
|
+
{
|
|
146
|
+
name: "ref",
|
|
147
|
+
required: true,
|
|
148
|
+
description: "reference to an existing Agent"
|
|
149
|
+
}
|
|
150
|
+
];
|
|
@@ -0,0 +1,122 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/*
|
|
30
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
31
|
+
* http://github.com/fonoster
|
|
32
|
+
*
|
|
33
|
+
* This file is part of Routr.
|
|
34
|
+
*
|
|
35
|
+
* Licensed under the MIT License (the "License");
|
|
36
|
+
* you may not use this file except in compliance with
|
|
37
|
+
* the License. You may obtain a copy of the License at
|
|
38
|
+
*
|
|
39
|
+
* https://opensource.org/licenses/MIT
|
|
40
|
+
*
|
|
41
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
42
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
43
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
44
|
+
* See the License for the specific language governing permissions and
|
|
45
|
+
* limitations under the License.
|
|
46
|
+
*/
|
|
47
|
+
/* eslint-disable require-jsdoc */
|
|
48
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
49
|
+
const core_1 = require("@oclif/core");
|
|
50
|
+
const base_1 = require("../../base");
|
|
51
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
52
|
+
const sdk_1 = __importDefault(require("@routr/sdk"));
|
|
53
|
+
// NOTE: Newer versions of inquirer have a bug that causes the following error:
|
|
54
|
+
// (node:75345) [ERR_REQUIRE_ESM] Error Plugin: @routr/ctl [ERR_REQUIRE_ESM]: require() of ES Module
|
|
55
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
56
|
+
const validators_1 = require("../../validators");
|
|
57
|
+
class CreateCommand extends base_1.BaseCommand {
|
|
58
|
+
async run() {
|
|
59
|
+
const { flags } = await this.parse(CreateCommand);
|
|
60
|
+
const { endpoint, insecure } = flags;
|
|
61
|
+
this.log("This utility will help you create a new set of Credentials.");
|
|
62
|
+
this.log("Press ^C at any time to quit.");
|
|
63
|
+
const answers = await inquirer_1.default.prompt([
|
|
64
|
+
{
|
|
65
|
+
name: "name",
|
|
66
|
+
message: "Friendly Name",
|
|
67
|
+
type: "input",
|
|
68
|
+
validate: validators_1.nameValidator
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "username",
|
|
72
|
+
message: "Username",
|
|
73
|
+
type: "input",
|
|
74
|
+
validate: validators_1.usernameValidator
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "password",
|
|
78
|
+
message: "Password",
|
|
79
|
+
type: "password",
|
|
80
|
+
validate: (value) => {
|
|
81
|
+
if (!value) {
|
|
82
|
+
return "the password is required";
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "confirm",
|
|
89
|
+
message: "Ready?",
|
|
90
|
+
type: "confirm"
|
|
91
|
+
}
|
|
92
|
+
]);
|
|
93
|
+
if (!answers.confirm) {
|
|
94
|
+
this.warn("Aborted");
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
try {
|
|
98
|
+
core_1.CliUx.ux.action.start(`Creating Credentials ${answers.name}`);
|
|
99
|
+
const api = new sdk_1.default.Credentials({ endpoint, insecure });
|
|
100
|
+
const credentials = await api.createCredentials(answers);
|
|
101
|
+
await core_1.CliUx.ux.wait(1000);
|
|
102
|
+
core_1.CliUx.ux.action.stop(credentials.ref);
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
core_1.CliUx.ux.action.stop();
|
|
106
|
+
if (e.code === grpc.status.ALREADY_EXISTS) {
|
|
107
|
+
throw new errors_1.CLIError("This Credentials already exist");
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new errors_1.CLIError(e.message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.default = CreateCommand;
|
|
117
|
+
CreateCommand.description = "Creates a new set of Credentials";
|
|
118
|
+
CreateCommand.examples = [
|
|
119
|
+
`<%= config.bin %> <%= command.id %>
|
|
120
|
+
Creating Credentials JDoe Access... b148b4b4-6884-4c06-bb7e-bd098f5fe793
|
|
121
|
+
`
|
|
122
|
+
];
|