-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support private registry options in asyncapi generate fromTemplate
command
#1091
Changes from all commits
ce425d2
3e30ace
208a82e
286f6c8
1cae5f6
8898f2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ interface IMapBaseUrlToFlag { | |
interface ParsedFlags { | ||
params: Record<string, string>, | ||
disableHooks: Record<string, string>, | ||
mapBaseUrlToFolder: IMapBaseUrlToFlag | ||
mapBaseUrlToFolder: IMapBaseUrlToFlag, | ||
registryUrl: string | ||
} | ||
|
||
const templatesNotSupportingV3: Record<string, string> = { | ||
|
@@ -100,6 +101,16 @@ export default class Template extends Command { | |
'map-base-url': Flags.string({ | ||
description: 'Maps all schema references from base url to local folder' | ||
}), | ||
'registry-url': Flags.string({ | ||
default: 'https://registry.npmjs.org', | ||
description: 'Specifies the URL of the private registry for fetching templates and dependencies' | ||
}), | ||
'registry-auth': Flags.string({ | ||
description: 'The registry username and password encoded with base64, formatted as username:password' | ||
}), | ||
'registry-token': Flags.string({ | ||
description: 'The npm registry authentication token, that can be passed instead of base64 encoded username and password' | ||
}) | ||
}; | ||
|
||
static args = [ | ||
|
@@ -115,7 +126,7 @@ export default class Template extends Command { | |
const asyncapi = args['asyncapi']; | ||
const template = args['template']; | ||
const output = flags.output || process.cwd(); | ||
const parsedFlags = this.parseFlags(flags['disable-hook'], flags['param'], flags['map-base-url']); | ||
const parsedFlags = this.parseFlags(flags['disable-hook'], flags['param'], flags['map-base-url'], flags['registry-url']); | ||
const options = { | ||
forceWrite: flags['force-write'], | ||
install: flags.install, | ||
|
@@ -124,6 +135,9 @@ export default class Template extends Command { | |
noOverwriteGlobs: flags['no-overwrite'], | ||
mapBaseUrlToFolder: parsedFlags.mapBaseUrlToFolder, | ||
disabledHooks: parsedFlags.disableHooks, | ||
registryUrl: parsedFlags.registryUrl, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the default URL of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
registryAuth: flags['registry-auth'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. registry auth should be change with base 64 value as mentioned in this const registryAuth = registryUsername && registryPassword
? Buffer.from(`${registryUsername}:${registryPassword}`).toString('base64')
: undefined; |
||
registryToken: flags['registry-token'] | ||
}; | ||
const asyncapiInput = (await load(asyncapi)) || (await load()); | ||
|
||
|
@@ -149,11 +163,12 @@ export default class Template extends Command { | |
} | ||
} | ||
|
||
private parseFlags(disableHooks?: string[], params?: string[], mapBaseUrl?: string): ParsedFlags { | ||
private parseFlags(disableHooks?: string[], params?: string[], mapBaseUrl?: string, registryUrl?: string): ParsedFlags { | ||
return { | ||
params: this.paramParser(params), | ||
disableHooks: this.disableHooksParser(disableHooks), | ||
mapBaseUrlToFolder: this.mapBaseURLParser(mapBaseUrl), | ||
registryUrl: this.registryURLParser(registryUrl), | ||
} as ParsedFlags; | ||
} | ||
|
||
|
@@ -204,6 +219,15 @@ export default class Template extends Command { | |
return mapBaseURLToFolder; | ||
} | ||
|
||
private registryURLParser(input?: string) { | ||
if (!input) { return; } | ||
const isURL = /^https?:/; | ||
if (!isURL.test(input.toLowerCase())) { | ||
throw new Error('Invalid --registry-url flag. The param requires a valid http/https url.'); | ||
} | ||
return input; | ||
} | ||
|
||
private async generate(asyncapi: string | undefined, template: string, output: string, options: any, genOption: any) { | ||
let specification: Specification; | ||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it will make more sense if we take
registryUsername
andregistryPassword
as input from the userThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that was also my initial concern I raised under the issue. Though in the example described here we are directly providing the base64 encoded value, wouldn't it make sense to do the same here too?