Skip to content

Commit

Permalink
Make url parameter optional when generating registration
Browse files Browse the repository at this point in the history
The bridge may instead choose to let the user configure the url.

Fixes #182

Signed-off-by: Dexter Chua <[email protected]>
  • Loading branch information
dalcde committed Sep 2, 2020
1 parent ad6458d commit 4afaf45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/217.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make url parameter optional when generating registration.
25 changes: 16 additions & 9 deletions src/components/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ interface CliOpts<ConfigType extends Record<string, unknown>> {
enableRegistration?: boolean;
enableLocalpart: boolean;
port: number;
urlFromConfig?: boolean;
}

interface CliArgs {
"generate-registration": boolean;
config: string;
url: string;
url?: string;
localpart: string;
port: number;
file: string;
Expand All @@ -69,6 +70,8 @@ export class Cli<ConfigType extends Record<string, unknown>> {
* (string) or the parsed schema file (Object).
* @param opts.bridgeConfig.defaults The default options for the
* config file.
* @param opts.urlFromConfig Appservice url is set in config file instead
* of cli parameter.
* @param opts.enableRegistration Enable '--generate-registration'.
* Default True.
* @param opts.registrationPath The path to write the registration
Expand Down Expand Up @@ -147,11 +150,16 @@ export class Cli<ConfigType extends Record<string, unknown>> {
}

if (this.opts.enableRegistration && this.args["generate-registration"]) {
if (!this.args.url) {
if (!this.args.url && !this.opts.urlFromConfig) {
this.printHelp();
console.log("Missing --url [-u]");
process.exit(1);
}
else if (this.args.url && this.opts.urlFromConfig) {
this.printHelp();
console.log("--url [-u] is not valid option for this bridge.");
process.exit(1);
}
if (this.args.port) {
this.printHelp();
console.log("--port [-p] is not valid when generating a registration file.");
Expand Down Expand Up @@ -210,11 +218,8 @@ export class Cli<ConfigType extends Record<string, unknown>> {
return validator.validate(cfg, this.opts.bridgeConfig.defaults) as ConfigType;
}

private generateRegistration(appServiceUrl: string, localpart: string) {
if (!appServiceUrl) {
throw Error("Missing app service URL");
}
let reg = new AppServiceRegistration(appServiceUrl);
private generateRegistration(appServiceUrl: string | undefined, localpart: string) {
let reg = new AppServiceRegistration(appServiceUrl || "");
if (localpart) {
reg.setSenderLocalpart(localpart);
}
Expand Down Expand Up @@ -256,8 +261,10 @@ export class Cli<ConfigType extends Record<string, unknown>> {
if (this.opts.enableRegistration) {
help["--generate-registration -r"] = "Create a registration YAML file " +
"for this application service";
help["--url -u"] = "Registration Option. Required if -r is set. The URL " +
"where the application service is listening for HS requests";
if (!this.opts.urlFromConfig) {
help["--url -u"] = "Registration Option. Required if -r is set. The " +
"URL where the application service is listening for HS requests";
}
if (this.opts.enableLocalpart) {
help["--localpart -l"] = "Registration Option. Valid if -r is set. " +
"The user_id localpart to assign to the AS.";
Expand Down

0 comments on commit 4afaf45

Please sign in to comment.