@routr/ctl 2.0.8-alpha.22 → 2.0.8-alpha.24

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.
@@ -37,106 +37,109 @@ class UpdatePeerCommand extends base_1.BaseCommand {
37
37
  const { args, flags } = await this.parse(UpdatePeerCommand);
38
38
  const { endpoint, insecure } = flags;
39
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"
40
+ try {
41
+ const peerFromDB = await api.getPeer(args.ref);
42
+ // TODO: Fix hardcoded pageSize
43
+ const acls = await new sdk_1.default.ACL({ endpoint, insecure }).listACLs({
44
+ pageSize: 25,
45
+ pageToken: ""
46
+ });
47
+ // TODO: Fix hardcoded pageSize
48
+ const credentials = await new sdk_1.default.Credentials({
49
+ endpoint,
50
+ insecure
51
+ }).listCredentials({
52
+ pageSize: 25,
53
+ pageToken: ""
54
+ });
55
+ const aclList = ((_a = acls.items) === null || _a === void 0 ? void 0 : _a.map((acl) => {
56
+ return { name: acl.name, value: acl.ref };
57
+ })) || [];
58
+ const credentialsList = ((_b = credentials.items) === null || _b === void 0 ? void 0 : _b.map((credential) => {
59
+ return { name: credential.name, value: credential.ref };
60
+ })) || [];
61
+ this.log("This utility will help you update an existing Peer.");
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
+ default: peerFromDB.name,
69
+ validate: validators_1.nameValidator
70
+ },
71
+ {
72
+ name: "aor",
73
+ message: "Adress of Record",
74
+ type: "input",
75
+ default: peerFromDB.aor,
76
+ validate: validators_1.aorValidator
77
+ },
78
+ {
79
+ name: "contactAddr",
80
+ message: "Contact Address",
81
+ type: "input",
82
+ default: peerFromDB.contactAddr || undefined,
83
+ validate: validators_1.contactAddrValidator
84
+ },
85
+ {
86
+ name: "accessControlListRef",
87
+ message: "IP Access Control List",
88
+ choices: [{ name: "None", value: undefined }, ...aclList],
89
+ type: "list",
90
+ default: peerFromDB.accessControlListRef
91
+ },
92
+ {
93
+ name: "credentialsRef",
94
+ message: "Credentials Name",
95
+ choices: [{ name: "None", value: undefined }, ...credentialsList],
96
+ type: "list",
97
+ default: peerFromDB.credentialsRef
98
+ },
99
+ {
100
+ name: "withSessionAffinity",
101
+ message: "Enable Session Affinity?",
102
+ type: "confirm",
103
+ default: peerFromDB.withSessionAffinity,
104
+ when: (answers) => answers.aor.startsWith("backend:")
105
+ },
106
+ {
107
+ name: "balancingAlgorithm",
108
+ message: "Balancing Algorithm",
109
+ choices: [
110
+ {
111
+ name: "Round Robin",
112
+ value: common_1.CommonTypes.LoadBalancingAlgorithm.ROUND_ROBIN
113
+ },
114
+ {
115
+ name: "Least Sessions",
116
+ value: common_1.CommonTypes.LoadBalancingAlgorithm.LEAST_SESSIONS
117
+ }
118
+ ],
119
+ type: "list",
120
+ default: peerFromDB.balancingAlgorithm,
121
+ when: (answers) => answers.aor.startsWith("backend:")
122
+ },
123
+ {
124
+ name: "confirm",
125
+ message: "Ready?",
126
+ type: "confirm"
127
+ }
128
+ ]);
129
+ answers.ref = args.ref;
130
+ if (!answers.confirm) {
131
+ this.warn("Aborted");
123
132
  }
124
- ]);
125
- answers.ref = args.ref;
126
- if (!answers.confirm) {
127
- this.warn("Aborted");
128
- }
129
- else {
130
- try {
133
+ else {
131
134
  core_1.CliUx.ux.action.start(`Updating Peer ${answers.name}`);
132
135
  const acl = await api.updatePeer(answers);
133
136
  await core_1.CliUx.ux.wait(1000);
134
137
  core_1.CliUx.ux.action.stop(acl.ref);
135
138
  }
136
- catch (e) {
137
- core_1.CliUx.ux.action.stop();
138
- throw new errors_1.CLIError(e.message);
139
- }
139
+ }
140
+ catch (e) {
141
+ core_1.CliUx.ux.action.stop();
142
+ throw new errors_1.CLIError(e.message);
140
143
  }
141
144
  }
142
145
  }
@@ -59,148 +59,148 @@ class CreateTrunkCommand extends base_1.BaseCommand {
59
59
  async run() {
60
60
  const { flags } = await this.parse(CreateTrunkCommand);
61
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
- });
62
+ try {
63
+ // TODO: Add support for pagination
64
+ const acls = await new sdk_1.default.ACL({ endpoint, insecure }).listACLs({
65
+ pageSize: 25,
66
+ pageToken: ""
67
+ });
68
+ const aclChoices = acls.items.map((acl) => {
69
+ return {
70
+ name: acl.name,
71
+ value: acl.ref
72
+ };
73
+ });
74
+ const credentials = await new sdk_1.default.Credentials({
75
+ endpoint,
76
+ insecure
77
+ }).listCredentials({
78
+ pageSize: 25,
79
+ pageToken: ""
80
+ });
81
+ const credentialsChoice = credentials.items.map((acl) => {
82
+ return {
83
+ name: acl.name,
84
+ value: acl.ref
85
+ };
86
+ });
87
+ this.log("This utility will help you create a new Trunk.");
88
+ this.log("Press ^C at any time to quit.");
89
+ const group1 = await inquirer_1.default.prompt([
90
+ {
91
+ name: "name",
92
+ message: "Friendly Name",
93
+ type: "input",
94
+ validate: validators_1.nameValidator
95
+ },
96
+ {
97
+ name: "inboundUri",
98
+ message: "Inbound SIP URI",
99
+ type: "input",
100
+ validate: validators_1.inboundUriValidator
101
+ },
102
+ {
103
+ name: "accessControlListRef",
104
+ message: "IP Access Control List",
105
+ type: "list",
106
+ choices: [{ name: "None", value: undefined }, ...aclChoices]
107
+ },
108
+ {
109
+ name: "inboundCredentialsRef",
110
+ message: "Inbound Credentials",
111
+ type: "list",
112
+ choices: [{ name: "None", value: undefined }, ...credentialsChoice]
113
+ },
114
+ {
115
+ name: "outboundCredentialsRef",
116
+ message: "Outbound Credentials",
117
+ type: "list",
118
+ choices: [{ name: "None", value: undefined }, ...credentialsChoice]
119
+ },
120
+ {
121
+ name: "addOutboundUri",
122
+ message: "Add an Outbound SIP URI?",
123
+ type: "confirm",
124
+ default: false
125
+ }
126
+ ]);
127
+ const group2Questions = [
128
+ {
129
+ name: "host",
130
+ message: "Host",
131
+ type: "input",
132
+ validate: validators_1.hostValidator
133
+ },
134
+ {
135
+ name: "port",
136
+ message: "Post",
137
+ type: "input",
138
+ default: "5060",
139
+ validate: validators_1.portValidator
140
+ },
141
+ {
142
+ name: "transport",
143
+ message: "Transport",
144
+ type: "list",
145
+ choices: [common_1.CommonTypes.Transport.UDP, common_1.CommonTypes.Transport.TCP, common_1.CommonTypes.Transport.TLS],
146
+ default: common_1.CommonTypes.Transport.UDP
147
+ },
148
+ {
149
+ name: "user",
150
+ message: "User Part",
151
+ type: "input",
152
+ validate: validators_1.optionalUsernameValidator
153
+ },
154
+ {
155
+ name: "priority",
156
+ message: "Priority",
157
+ type: "input",
158
+ default: "10",
159
+ validate: validators_1.priorityValidator
160
+ },
161
+ {
162
+ name: "weight",
163
+ message: "Weight",
164
+ type: "input",
165
+ default: "10",
166
+ validate: validators_1.weightValidator
167
+ },
168
+ {
169
+ name: "addOutboundUri",
170
+ message: "Add another Outbound SIP URI?",
171
+ type: "confirm",
172
+ default: false
173
+ }
174
+ ];
175
+ let addOutboundUri = group1.addOutboundUri;
176
+ const uris = [];
177
+ // eslint-disable-next-line no-loops/no-loops
178
+ while (addOutboundUri) {
179
+ const group2 = await inquirer_1.default.prompt(group2Questions);
180
+ if (group2.numberRef) {
181
+ uris.push({
182
+ host: group2.host,
183
+ port: group2.port,
184
+ transport: group2.transport,
185
+ user: group2.user,
186
+ priority: group2.priority,
187
+ weight: group2.weight,
188
+ enabled: true
189
+ });
190
+ }
191
+ addOutboundUri = group2.addOutboundUri;
189
192
  }
190
- addOutboundUri = group2.addOutboundUri;
191
- }
192
- const group3 = await inquirer_1.default.prompt([
193
- {
194
- name: "confirm",
195
- message: "Ready?",
196
- type: "confirm"
193
+ const group3 = await inquirer_1.default.prompt([
194
+ {
195
+ name: "confirm",
196
+ message: "Ready?",
197
+ type: "confirm"
198
+ }
199
+ ]);
200
+ if (!group3.confirm) {
201
+ this.warn("Aborted");
197
202
  }
198
- ]);
199
- if (!group3.confirm) {
200
- this.warn("Aborted");
201
- }
202
- else {
203
- try {
203
+ else {
204
204
  core_1.CliUx.ux.action.start(`Creating Trunk ${group1.name}`);
205
205
  const api = new sdk_1.default.Trunks({ endpoint, insecure });
206
206
  const trunk = await api.createTrunk({
@@ -210,14 +210,14 @@ class CreateTrunkCommand extends base_1.BaseCommand {
210
210
  await core_1.CliUx.ux.wait(1000);
211
211
  core_1.CliUx.ux.action.stop(trunk.ref);
212
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
- }
213
+ }
214
+ catch (e) {
215
+ core_1.CliUx.ux.action.stop();
216
+ if (e.code === grpc.status.ALREADY_EXISTS) {
217
+ throw new errors_1.CLIError("This Trunk already exist");
218
+ }
219
+ else {
220
+ throw new errors_1.CLIError(e.message);
221
221
  }
222
222
  }
223
223
  }