Skip to content

Commit

Permalink
fix: ensure maxContacts in mods/ctl defaults to -1
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Feb 24, 2024
1 parent 3af2e35 commit 4d290d5
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 6 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions mods/ctl/src/commands/agents/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { CliUx } from "@oclif/core"
import { BaseCommand } from "../../base"
import { CLIError } from "@oclif/core/lib/errors"
import { CommonTypes as CT, CommonConnect as CC } from "@routr/common"
import { nameValidator, usernameValidator } from "../../validators"
import {
nameValidator,
usernameValidator,
maxContactsValidator
} from "../../validators"
import SDK from "@routr/sdk"

// NOTE: Newer versions of inquirer have a bug that causes the following error:
Expand Down Expand Up @@ -111,7 +115,8 @@ Creating Agent Jhon Doe... b148b4b4-6884-4c06-bb7e-bd098f5fe793
{
name: "maxContacts",
message: "Max Contacts",
type: "input"
type: "input",
validate: maxContactsValidator
},
{
name: "privacy",
Expand Down Expand Up @@ -151,6 +156,11 @@ Creating Agent Jhon Doe... b148b4b4-6884-4c06-bb7e-bd098f5fe793
} else {
CliUx.ux.action.start(`Creating Agent ${answers.name}`)
const api = new SDK.Agents({ endpoint, insecure, cacert })

answers.maxContacts = answers.maxContacts
? parseInt(answers.maxContacts)
: -1

const agent = await api.createAgent(answers)

await CliUx.ux.wait(1000)
Expand Down
10 changes: 8 additions & 2 deletions mods/ctl/src/commands/agents/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { CliUx } from "@oclif/core"
import { BaseCommand } from "../../base"
import { CLIError } from "@oclif/core/lib/errors"
import { CommonTypes as CT, CommonConnect as CC } from "@routr/common"
import { nameValidator } from "../../validators"
import { maxContactsValidator, nameValidator } from "../../validators"
import SDK from "@routr/sdk"

// NOTE: Newer versions of inquirer have a bug that causes the following error:
Expand Down Expand Up @@ -111,7 +111,9 @@ Updating Agent John Doe... 80181ca6-d4aa-4575-9375-8f72b07d5555
name: "maxContacts",
message: "Max Contacts",
type: "input",
default: agentFromDB.maxContacts === -1 ? "" : agentFromDB.maxContacts
default:
agentFromDB.maxContacts === -1 ? "" : agentFromDB.maxContacts,
validate: maxContactsValidator
},
{
name: "privacy",
Expand Down Expand Up @@ -148,6 +150,10 @@ Updating Agent John Doe... 80181ca6-d4aa-4575-9375-8f72b07d5555

answers.ref = args.ref

answers.maxContacts = answers.maxContacts
? parseInt(answers.maxContacts)
: -1

if (!answers.confirm) {
this.warn("Aborted")
} else {
Expand Down
8 changes: 7 additions & 1 deletion mods/ctl/src/commands/peers/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import inquirer from "inquirer"
import {
aorValidator,
contactAddrValidator,
maxContactsValidator,
nameValidator,
usernameValidator
} from "../../validators"
Expand Down Expand Up @@ -109,7 +110,8 @@ Creating Peer Asterisk Conference... b148b4b4-6884-4c06-bb7e-bd098f5fe793
{
name: "maxContacts",
message: "Max Contacts",
type: "input"
type: "input",
validate: maxContactsValidator
},
{
name: "accessControlListRef",
Expand Down Expand Up @@ -164,6 +166,10 @@ Creating Peer Asterisk Conference... b148b4b4-6884-4c06-bb7e-bd098f5fe793
CliUx.ux.action.start(`Creating Peer ${answers.name}`)
const api = new SDK.Peers({ endpoint, insecure, cacert })

answers.maxContacts = answers.maxContacts
? parseInt(answers.maxContacts)
: -1

const peer = await api.createPeer(answers)

await CliUx.ux.wait(1000)
Expand Down
9 changes: 8 additions & 1 deletion mods/ctl/src/commands/peers/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CommonConnect as CC, CommonTypes as CT } from "@routr/common"
import {
aorValidator,
contactAddrValidator,
maxContactsValidator,
nameValidator
} from "../../validators"
import SDK from "@routr/sdk"
Expand Down Expand Up @@ -112,7 +113,8 @@ Updating Peer Asterisk Conf... 80181ca6-d4aa-4575-9375-8f72b07d5555
name: "maxContacts",
message: "Max Contacts",
type: "input",
default: peerFromDB.maxContacts === -1 ? "" : peerFromDB.maxContacts
default: peerFromDB.maxContacts === -1 ? "" : peerFromDB.maxContacts,
validate: maxContactsValidator
},
{
name: "accessControlListRef",
Expand Down Expand Up @@ -168,6 +170,11 @@ Updating Peer Asterisk Conf... 80181ca6-d4aa-4575-9375-8f72b07d5555
this.warn("Aborted")
} else {
CliUx.ux.action.start(`Updating Peer ${answers.name}`)

answers.maxContacts = answers.maxContacts
? parseInt(answers.maxContacts)
: -1

const acl = await api.updatePeer(answers)
await CliUx.ux.wait(1000)
CliUx.ux.action.stop(acl.ref)
Expand Down
7 changes: 7 additions & 0 deletions mods/ctl/src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,10 @@ export function domainUriValidator(value: string) {

return true
}

export function maxContactsValidator(value: string) {
if (!value) return true
if (isNaN(Number(value))) return "maxContacts must be a number"
if (Number(value) < 0) return "maxContacts must be 0 or greater"
return true
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4d290d5

Please sign in to comment.