@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,159 @@
|
|
|
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 core_1 = require("@oclif/core");
|
|
46
|
+
const base_1 = require("../../base");
|
|
47
|
+
const utils_1 = require("../../utils");
|
|
48
|
+
const common_1 = require("@routr/common");
|
|
49
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
50
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
51
|
+
class GetCommand extends base_1.BaseCommand {
|
|
52
|
+
async run() {
|
|
53
|
+
const { args, flags } = await this.parse(GetCommand);
|
|
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
|
+
aor: {
|
|
68
|
+
header: "AOR"
|
|
69
|
+
},
|
|
70
|
+
balancingAlgorithm: {
|
|
71
|
+
header: "Balancing Algorithm"
|
|
72
|
+
},
|
|
73
|
+
withSessionAffinity: {
|
|
74
|
+
header: "Session Affinity",
|
|
75
|
+
get: (row) => row.withSessionAffinity ? "Yes" : "No"
|
|
76
|
+
},
|
|
77
|
+
contactAddr: {
|
|
78
|
+
header: "Contact Address",
|
|
79
|
+
extended: true
|
|
80
|
+
},
|
|
81
|
+
enabled: {
|
|
82
|
+
header: "Enabled",
|
|
83
|
+
get: (row) => (row.enabled ? "Yes" : "No"),
|
|
84
|
+
extended: true
|
|
85
|
+
},
|
|
86
|
+
accessControlList: {
|
|
87
|
+
header: "IP Access Control List",
|
|
88
|
+
get: (row) => { var _a; return ((_a = row.accessControlList) === null || _a === void 0 ? void 0 : _a.name) || "None"; },
|
|
89
|
+
extended: true
|
|
90
|
+
},
|
|
91
|
+
credentials: {
|
|
92
|
+
header: "Credentials Name",
|
|
93
|
+
get: (row) => { var _a; return ((_a = row.credentials) === null || _a === void 0 ? void 0 : _a.name) || "None"; },
|
|
94
|
+
extended: true
|
|
95
|
+
},
|
|
96
|
+
createdAt: {
|
|
97
|
+
header: "Created",
|
|
98
|
+
get: (row) => new Date(row.createdAt * 1000),
|
|
99
|
+
extended: true
|
|
100
|
+
},
|
|
101
|
+
updatedAt: {
|
|
102
|
+
header: "Updated",
|
|
103
|
+
get: (row) => new Date(row.updatedAt * 1000),
|
|
104
|
+
extended: true
|
|
105
|
+
},
|
|
106
|
+
extended: {
|
|
107
|
+
header: "Extended",
|
|
108
|
+
get: (row) => row.extended || {},
|
|
109
|
+
extended: true
|
|
110
|
+
},
|
|
111
|
+
apiVersion: {
|
|
112
|
+
header: "API",
|
|
113
|
+
extended: true
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
"no-header": !showHeader,
|
|
117
|
+
printLine: self.log.bind(self),
|
|
118
|
+
...flags // parsed flags
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
await (0, utils_1.showPaginatedList)({
|
|
122
|
+
showTable,
|
|
123
|
+
args,
|
|
124
|
+
flags,
|
|
125
|
+
kind: common_1.CommonConnect.Kind.PEER,
|
|
126
|
+
self: this
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async catch(error) {
|
|
130
|
+
// To be handled globally
|
|
131
|
+
if ("code" in error && error.code === grpc.status.NOT_FOUND) {
|
|
132
|
+
const { args } = await this.parse(GetCommand);
|
|
133
|
+
throw new errors_1.CLIError("the Peer you are looking for does not exist: " + args.ref);
|
|
134
|
+
}
|
|
135
|
+
throw new errors_1.CLIError(error.message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.default = GetCommand;
|
|
139
|
+
GetCommand.description = "Shows a list of paginated Peers or a single Peer if ref is provided";
|
|
140
|
+
GetCommand.examples = [
|
|
141
|
+
`<%= config.bin %> <%= command.id %>
|
|
142
|
+
Ref Name Username AOR Balancing Algorithm Session Affinity
|
|
143
|
+
6f941c63-880c-419a-a72a-4a107cbaf5c5 Asterisk Conference conference backend:conference ROUND_ROBIN Yes
|
|
144
|
+
`
|
|
145
|
+
];
|
|
146
|
+
GetCommand.flags = {
|
|
147
|
+
size: core_1.Flags.integer({
|
|
148
|
+
char: "s",
|
|
149
|
+
description: "the number of items to return",
|
|
150
|
+
default: 50
|
|
151
|
+
})
|
|
152
|
+
};
|
|
153
|
+
GetCommand.args = [
|
|
154
|
+
{
|
|
155
|
+
name: "ref",
|
|
156
|
+
required: false,
|
|
157
|
+
description: "optional reference to a Peer"
|
|
158
|
+
}
|
|
159
|
+
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base";
|
|
2
|
+
export default class UpdatePeerCommand 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,156 @@
|
|
|
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 validators_1 = require("../../validators");
|
|
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
|
+
class UpdatePeerCommand extends base_1.BaseCommand {
|
|
35
|
+
async run() {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const { args, flags } = await this.parse(UpdatePeerCommand);
|
|
38
|
+
const { endpoint, insecure } = flags;
|
|
39
|
+
const api = new sdk_1.default.Peers({ endpoint, insecure });
|
|
40
|
+
this.log("This utility will help you update an existing Peer.");
|
|
41
|
+
this.log("Press ^C at any time to quit.");
|
|
42
|
+
const peerFromDB = await api.getPeer(args.ref);
|
|
43
|
+
// TODO: Fix hardcoded pageSize
|
|
44
|
+
const acls = await new sdk_1.default.ACL({ endpoint, insecure }).listACLs({
|
|
45
|
+
pageSize: 25,
|
|
46
|
+
pageToken: ""
|
|
47
|
+
});
|
|
48
|
+
// TODO: Fix hardcoded pageSize
|
|
49
|
+
const credentials = await new sdk_1.default.Credentials({
|
|
50
|
+
endpoint,
|
|
51
|
+
insecure
|
|
52
|
+
}).listCredentials({
|
|
53
|
+
pageSize: 25,
|
|
54
|
+
pageToken: ""
|
|
55
|
+
});
|
|
56
|
+
const aclList = ((_a = acls.items) === null || _a === void 0 ? void 0 : _a.map((acl) => {
|
|
57
|
+
return { name: acl.name, value: acl.ref };
|
|
58
|
+
})) || [];
|
|
59
|
+
const credentialsList = ((_b = credentials.items) === null || _b === void 0 ? void 0 : _b.map((credential) => {
|
|
60
|
+
return { name: credential.name, value: credential.ref };
|
|
61
|
+
})) || [];
|
|
62
|
+
const answers = await inquirer_1.default.prompt([
|
|
63
|
+
{
|
|
64
|
+
name: "name",
|
|
65
|
+
message: "Friendly Name",
|
|
66
|
+
type: "input",
|
|
67
|
+
default: peerFromDB.name,
|
|
68
|
+
validate: validators_1.nameValidator
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "aor",
|
|
72
|
+
message: "Adress of Record",
|
|
73
|
+
type: "input",
|
|
74
|
+
default: peerFromDB.aor,
|
|
75
|
+
validate: validators_1.aorValidator
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "contactAddr",
|
|
79
|
+
message: "Contact Address",
|
|
80
|
+
type: "input",
|
|
81
|
+
default: peerFromDB.contactAddr || undefined,
|
|
82
|
+
validate: validators_1.contactAddrValidator
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "accessControlListRef",
|
|
86
|
+
message: "IP Access Control List",
|
|
87
|
+
choices: [{ name: "None", value: undefined }, ...aclList],
|
|
88
|
+
type: "list",
|
|
89
|
+
default: peerFromDB.accessControlListRef
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "credentialsRef",
|
|
93
|
+
message: "Credentials Name",
|
|
94
|
+
choices: [{ name: "None", value: undefined }, ...credentialsList],
|
|
95
|
+
type: "list",
|
|
96
|
+
default: peerFromDB.credentialsRef
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "withSessionAffinity",
|
|
100
|
+
message: "Enable Session Affinity?",
|
|
101
|
+
type: "confirm",
|
|
102
|
+
default: peerFromDB.withSessionAffinity,
|
|
103
|
+
when: (answers) => answers.aor.startsWith("backend:")
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "balancingAlgorithm",
|
|
107
|
+
message: "Balancing Algorithm",
|
|
108
|
+
choices: [
|
|
109
|
+
{ name: "Round Robin", value: common_1.CommonTypes.LoadBalancingAlgorithm.ROUND_ROBIN },
|
|
110
|
+
{
|
|
111
|
+
name: "Least Sessions",
|
|
112
|
+
value: common_1.CommonTypes.LoadBalancingAlgorithm.LEAST_SESSIONS
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
type: "list",
|
|
116
|
+
default: peerFromDB.balancingAlgorithm,
|
|
117
|
+
when: (answers) => answers.aor.startsWith("backend:")
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "confirm",
|
|
121
|
+
message: "Ready?",
|
|
122
|
+
type: "confirm"
|
|
123
|
+
}
|
|
124
|
+
]);
|
|
125
|
+
answers.ref = args.ref;
|
|
126
|
+
if (!answers.confirm) {
|
|
127
|
+
this.warn("Aborted");
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
try {
|
|
131
|
+
core_1.CliUx.ux.action.start(`Updating Peer ${answers.name}`);
|
|
132
|
+
const acl = await api.updatePeer(answers);
|
|
133
|
+
await core_1.CliUx.ux.wait(1000);
|
|
134
|
+
core_1.CliUx.ux.action.stop(acl.ref);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
core_1.CliUx.ux.action.stop();
|
|
138
|
+
throw new errors_1.CLIError(e.message);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.default = UpdatePeerCommand;
|
|
144
|
+
UpdatePeerCommand.description = "Updates an existing Peer";
|
|
145
|
+
UpdatePeerCommand.examples = [
|
|
146
|
+
`<%= config.bin %> <%= command.id %>
|
|
147
|
+
Updating Peer Asterisk Conf... 80181ca6-d4aa-4575-9375-8f72b07d5555
|
|
148
|
+
`
|
|
149
|
+
];
|
|
150
|
+
UpdatePeerCommand.args = [
|
|
151
|
+
{
|
|
152
|
+
name: "ref",
|
|
153
|
+
required: true,
|
|
154
|
+
description: "reference to an existing Peer"
|
|
155
|
+
}
|
|
156
|
+
];
|
|
@@ -0,0 +1,231 @@
|
|
|
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 sdk_1 = __importDefault(require("@routr/sdk"));
|
|
55
|
+
// NOTE: Newer versions of inquirer have a bug that causes the following error:
|
|
56
|
+
// (node:75345) [ERR_REQUIRE_ESM] Error Plugin: @routr/ctl [ERR_REQUIRE_ESM]: require() of ES Module
|
|
57
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
58
|
+
class CreateTrunkCommand extends base_1.BaseCommand {
|
|
59
|
+
async run() {
|
|
60
|
+
const { flags } = await this.parse(CreateTrunkCommand);
|
|
61
|
+
const { endpoint, insecure } = flags;
|
|
62
|
+
this.log("This utility will help you create a new Trunk.");
|
|
63
|
+
this.log("Press ^C at any time to quit.");
|
|
64
|
+
// TODO: Add support for pagination
|
|
65
|
+
const acls = await new sdk_1.default.ACL({ endpoint, insecure }).listACLs({
|
|
66
|
+
pageSize: 25,
|
|
67
|
+
pageToken: ""
|
|
68
|
+
});
|
|
69
|
+
const aclChoices = acls.items.map((acl) => {
|
|
70
|
+
return {
|
|
71
|
+
name: acl.name,
|
|
72
|
+
value: acl.ref
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
const credentials = await new sdk_1.default.Credentials({
|
|
76
|
+
endpoint,
|
|
77
|
+
insecure
|
|
78
|
+
}).listCredentials({
|
|
79
|
+
pageSize: 25,
|
|
80
|
+
pageToken: ""
|
|
81
|
+
});
|
|
82
|
+
const credentialsChoice = credentials.items.map((acl) => {
|
|
83
|
+
return {
|
|
84
|
+
name: acl.name,
|
|
85
|
+
value: acl.ref
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const group1 = await inquirer_1.default.prompt([
|
|
89
|
+
{
|
|
90
|
+
name: "name",
|
|
91
|
+
message: "Friendly Name",
|
|
92
|
+
type: "input",
|
|
93
|
+
validate: validators_1.nameValidator
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "inboundUri",
|
|
97
|
+
message: "Inbound SIP URI",
|
|
98
|
+
type: "input",
|
|
99
|
+
validate: validators_1.inboundUriValidator
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "accessControlListRef",
|
|
103
|
+
message: "IP Access Control List",
|
|
104
|
+
type: "list",
|
|
105
|
+
choices: [{ name: "None", value: undefined }, ...aclChoices]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "inboundCredentialsRef",
|
|
109
|
+
message: "Inbound Credentials",
|
|
110
|
+
type: "list",
|
|
111
|
+
choices: [{ name: "None", value: undefined }, ...credentialsChoice]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "outboundCredentialsRef",
|
|
115
|
+
message: "Outbound Credentials",
|
|
116
|
+
type: "list",
|
|
117
|
+
choices: [{ name: "None", value: undefined }, ...credentialsChoice]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "addOutboundUri",
|
|
121
|
+
message: "Add an Outbound SIP URI?",
|
|
122
|
+
type: "confirm",
|
|
123
|
+
default: false
|
|
124
|
+
}
|
|
125
|
+
]);
|
|
126
|
+
const group2Questions = [
|
|
127
|
+
{
|
|
128
|
+
name: "host",
|
|
129
|
+
message: "Host",
|
|
130
|
+
type: "input",
|
|
131
|
+
validate: validators_1.hostValidator
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "port",
|
|
135
|
+
message: "Post",
|
|
136
|
+
type: "input",
|
|
137
|
+
default: "5060",
|
|
138
|
+
validate: validators_1.portValidator
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "transport",
|
|
142
|
+
message: "Transport",
|
|
143
|
+
type: "list",
|
|
144
|
+
choices: [common_1.CommonTypes.Transport.UDP, common_1.CommonTypes.Transport.TCP, common_1.CommonTypes.Transport.TLS],
|
|
145
|
+
default: common_1.CommonTypes.Transport.UDP
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: "user",
|
|
149
|
+
message: "User Part",
|
|
150
|
+
type: "input",
|
|
151
|
+
validate: validators_1.optionalUsernameValidator
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "priority",
|
|
155
|
+
message: "Priority",
|
|
156
|
+
type: "input",
|
|
157
|
+
default: "10",
|
|
158
|
+
validate: validators_1.priorityValidator
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: "weight",
|
|
162
|
+
message: "Weight",
|
|
163
|
+
type: "input",
|
|
164
|
+
default: "10",
|
|
165
|
+
validate: validators_1.weightValidator
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "addOutboundUri",
|
|
169
|
+
message: "Add another Outbound SIP URI?",
|
|
170
|
+
type: "confirm",
|
|
171
|
+
default: false
|
|
172
|
+
}
|
|
173
|
+
];
|
|
174
|
+
let addOutboundUri = group1.addOutboundUri;
|
|
175
|
+
const uris = [];
|
|
176
|
+
// eslint-disable-next-line no-loops/no-loops
|
|
177
|
+
while (addOutboundUri) {
|
|
178
|
+
const group2 = await inquirer_1.default.prompt(group2Questions);
|
|
179
|
+
if (group2.numberRef) {
|
|
180
|
+
uris.push({
|
|
181
|
+
host: group2.host,
|
|
182
|
+
port: group2.port,
|
|
183
|
+
transport: group2.transport,
|
|
184
|
+
user: group2.user,
|
|
185
|
+
priority: group2.priority,
|
|
186
|
+
weight: group2.weight,
|
|
187
|
+
enabled: true
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
addOutboundUri = group2.addOutboundUri;
|
|
191
|
+
}
|
|
192
|
+
const group3 = await inquirer_1.default.prompt([
|
|
193
|
+
{
|
|
194
|
+
name: "confirm",
|
|
195
|
+
message: "Ready?",
|
|
196
|
+
type: "confirm"
|
|
197
|
+
}
|
|
198
|
+
]);
|
|
199
|
+
if (!group3.confirm) {
|
|
200
|
+
this.warn("Aborted");
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
try {
|
|
204
|
+
core_1.CliUx.ux.action.start(`Creating Trunk ${group1.name}`);
|
|
205
|
+
const api = new sdk_1.default.Trunks({ endpoint, insecure });
|
|
206
|
+
const trunk = await api.createTrunk({
|
|
207
|
+
...group1,
|
|
208
|
+
uris
|
|
209
|
+
});
|
|
210
|
+
await core_1.CliUx.ux.wait(1000);
|
|
211
|
+
core_1.CliUx.ux.action.stop(trunk.ref);
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
core_1.CliUx.ux.action.stop();
|
|
215
|
+
if (e.code === grpc.status.ALREADY_EXISTS) {
|
|
216
|
+
throw new errors_1.CLIError("This Trunk already exist");
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
throw new errors_1.CLIError(e.message);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.default = CreateTrunkCommand;
|
|
226
|
+
CreateTrunkCommand.description = "Creates a new Trunk";
|
|
227
|
+
CreateTrunkCommand.examples = [
|
|
228
|
+
`<%= config.bin %> <%= command.id %>
|
|
229
|
+
Creating Trunk T01... b148b4b4-6884-4c06-bb7e-bd098f5fe793
|
|
230
|
+
`
|
|
231
|
+
];
|
|
@@ -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 DeleteTrunkCommand extends delete_1.default {
|
|
28
|
+
async run() {
|
|
29
|
+
const { flags } = await this.parse(DeleteTrunkCommand);
|
|
30
|
+
const { endpoint, insecure } = flags;
|
|
31
|
+
await super.deleteResource(new sdk_1.default.Trunks({ endpoint, insecure }), "deleteTrunk");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = DeleteTrunkCommand;
|
|
35
|
+
DeleteTrunkCommand.description = "Deletes a Trunk";
|
|
36
|
+
DeleteTrunkCommand.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 GetTrunksCommand 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
|
+
}
|