-
-
Notifications
You must be signed in to change notification settings - Fork 262
feat: add new custom resolver to fetch the reference from private repo #1810
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
Closed
Closed
Changes from 38 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
0213926
Add new custom resolver to fetch the reference from private template …
AayushSaini101 c685ac2
chore: add changeset for PR #1810
181dbb9
Merge branch 'master' into 1796-b
asyncapi-bot 82ac26b
Merge branch 'master' into 1796-b
asyncapi-bot 0a4c2ed
Merge branch 'master' into 1796-b
asyncapi-bot 26037eb
Merge remote-tracking branch 'remote/master' into 1796-b
Shurtu-gal 6473326
chore: separate cli and api
Shurtu-gal b18cd33
chore: add changeset for PR #1810
7e72056
Merge branch 'master' into 1796-b
asyncapi-bot cccf712
Merge branch 'master' into 1796-b
asyncapi-bot 0572240
Merge branch 'master' into 1796-b
AayushSaini101 d484f2f
update
AayushSaini101 ab58365
remove invalid changes
AayushSaini101 932c09c
update package-lock.json
AayushSaini101 ec5eb66
update package-lock.json
AayushSaini101 7e4b523
fix github jobs
AayushSaini101 c7501a1
Fix elint issue
AayushSaini101 925b90a
remove uncessary files
AayushSaini101 5d651f7
remove invalid file
AayushSaini101 5d76066
update-changeset
AayushSaini101 5d89ce7
update-doc
AayushSaini101 3461288
update-suggestions
AayushSaini101 4f63af9
add new testcase
AayushSaini101 5d83ac7
add new testcases
AayushSaini101 22c180a
Merge branch 'master' into 1796-b
asyncapi-bot 7e0a666
chore: add changeset for PR #1810
ca35a23
Merge branch 'master' into 1796-b
asyncapi-bot d3989d5
Merge branch 'master' into 1796-b
asyncapi-bot baadf95
Merge branch 'master' into 1796-b
asyncapi-bot f1a4d39
add new test case for the validationService
AayushSaini101 f729636
chore: add changeset for PR #1810
af11ce4
update test case
AayushSaini101 824bdb9
update changeset
AayushSaini101 0211fed
chore: add changeset for PR #1810
cf4d070
Update src/domains/services/validation.service.ts
AayushSaini101 95df8d3
chore: add changeset for PR #1810
150865c
update validation service for the github
AayushSaini101 e04600f
chore: add changeset for PR #1810
4c5be56
Update src/domains/services/validation.service.ts
AayushSaini101 fcc864d
Update src/apps/api/middlewares/validation.middleware.ts
AayushSaini101 6c66199
chore: add changeset for PR #1810
2f69485
Update src/domains/services/validation.service.ts
AayushSaini101 5328d62
Update src/domains/services/validation.service.ts
AayushSaini101 407bacc
Update src/domains/services/validation.service.ts
AayushSaini101 3b7159b
Update src/domains/services/validation.service.ts
AayushSaini101 f601cf7
Update src/domains/services/validation.service.ts
AayushSaini101 25860cc
chore: add changeset for PR #1810
8943766
updateValidationservice
AayushSaini101 aa37d14
remove invalid comment
AayushSaini101 edb659c
chore: add changeset for PR #1810
14dc382
Merge branch 'master' into 1796-b
asyncapi-bot 704d261
Merge branch 'master' into 1796-b
asyncapi-bot 3b882ed
Add new custom resolver to fetch the reference from private template …
AayushSaini101 811bc08
update
AayushSaini101 bb0fb6c
remove config service test file
aayushRedHat 32298a9
remove invalid statements
AayushSaini101 ad3b3b8
add missing dependencies
AayushSaini101 7662fca
remove warnings
AayushSaini101 40b4b50
update validation-service
AayushSaini101 d7db432
remove invalid file
AayushSaini101 98dfd4c
fix lint issue
AayushSaini101 75dda7b
update validation-service
AayushSaini101 5c23530
fix lint issue
AayushSaini101 d6d0402
chore: add changeset for PR #1810
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| '@asyncapi/cli': minor | ||
| --- | ||
|
|
||
| feat: add new custom resolver to fetch the reference from private repo | ||
|
|
||
| - 0213926: Add new custom resolver to fetch the reference from private template and add new command auth add | ||
| - 26037eb: Merge remote-tracking branch 'remote/master' into 1796-b | ||
| - 6473326: chore: separate cli and api | ||
|
|
||
| Signed-off-by: Shurtu-gal <[email protected]> | ||
| - d484f2f: update | ||
| - ab58365: remove invalid changes | ||
| - 932c09c: update package-lock.json | ||
| - ec5eb66: update package-lock.json | ||
| - 7e4b523: fix github jobs | ||
| - c7501a1: Fix elint issue | ||
| - 925b90a: remove uncessary files | ||
| - 5d651f7: remove invalid file | ||
| - 5d76066: update-changeset | ||
| - 5d89ce7: update-doc | ||
| - 3461288: update-suggestions | ||
| - 4f63af9: add new testcase | ||
| - 5d83ac7: add new testcases | ||
| - f1a4d39: add new test case for the validationService | ||
| - af11ce4: update test case | ||
| - 824bdb9: update changeset | ||
| - cf4d070: Update src/domains/services/validation.service.ts | ||
|
|
||
| Co-authored-by: Fran Méndez <[email protected]> | ||
| - 150865c: update validation service for the github | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { Args, Flags } from '@oclif/core'; | ||
| import Command from '@cli/internal/base'; | ||
| import { blueBright } from 'picocolors'; | ||
| import { ConfigService, AuthEntry } from '@/domains/services/config.service'; | ||
|
|
||
| export default class AuthAdd extends Command { | ||
| static description = | ||
| 'Add an authentication config for resolving $ref files requiring HTTP Authorization.'; | ||
|
|
||
| static args = { | ||
| pattern: Args.string({ | ||
| required: true, | ||
| description: | ||
| 'Glob pattern for matching protected URLs (e.g. github.com/org/repo/**/*.*)', | ||
| }), | ||
| token: Args.string({ | ||
| required: true, | ||
| description: | ||
| 'Authentication token or environment variable reference (prefix with $, e.g. $GITHUB_TOKEN)', | ||
| }), | ||
| }; | ||
|
|
||
| static flags = { | ||
| 'auth-type': Flags.string({ | ||
| char: 'a', | ||
| description: 'Authentication type (default is "Bearer")', | ||
| }), | ||
| header: Flags.string({ | ||
| char: 'h', | ||
| description: | ||
| 'Additional header in key=value format; can be used multiple times', | ||
| multiple: true, | ||
| }), | ||
| }; | ||
|
|
||
| async run() { | ||
| const { args, flags } = await this.parse(AuthAdd); | ||
|
|
||
| const isEnvVar = args.token.startsWith('$'); | ||
| const tokenValue = isEnvVar ? args.token.slice(1) : args.token; | ||
|
|
||
| // Parse headers into an object | ||
| const headers: Record<string, string> = {}; | ||
| if (flags.header) { | ||
| for (const headerEntry of flags.header) { | ||
| const [key, value] = headerEntry.split('='); | ||
| if (key && value) { | ||
| headers[key.trim()] = value.trim(); | ||
| } else { | ||
| this.warn(`⚠️ Ignored invalid header format: ${headerEntry}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const entry: AuthEntry = { | ||
| pattern: args.pattern, | ||
| token: tokenValue, | ||
| authType: flags['auth-type'] || 'Bearer', | ||
| headers: Object.keys(headers).length ? headers : undefined, | ||
| }; | ||
|
|
||
| try { | ||
| await ConfigService.addAuthEntry(entry); | ||
| this.log( | ||
| `✅ Auth config added for ${blueBright(args.pattern)} using ${ | ||
| isEnvVar ? `env var (${tokenValue})` : 'raw token' | ||
| } with auth type ${blueBright(entry.authType || 'Bearer')}` | ||
| ); | ||
| if (entry.headers) { | ||
| this.log(`Headers: ${JSON.stringify(entry.headers, null, 2)}`); | ||
| } | ||
| } catch (err) { | ||
| this.error(`❌ Failed to add auth config: ${(err as Error).message}`); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import path from 'path'; | ||
| import os from 'os'; | ||
| import { promises as fs } from 'fs'; | ||
| import minimatch from 'minimatch'; | ||
|
|
||
| const CONFIG_DIR = path.join(os.homedir(), '.asyncapi'); | ||
| const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json'); | ||
|
|
||
| export interface AuthEntry { | ||
| pattern: string; | ||
| token: string; | ||
| authType?: string; | ||
| headers?: Record<string, string>; | ||
| } | ||
|
|
||
| export interface AuthResult { | ||
| token: string; | ||
| authType: string; | ||
| headers: Record<string, string>; | ||
| } | ||
|
|
||
| interface Config { | ||
| auth?: AuthEntry[]; | ||
| } | ||
|
|
||
| export class ConfigService { | ||
| /** | ||
| * Load config file (~/.asyncapi/config.json) | ||
| */ | ||
| static async loadConfig(): Promise<Config> { | ||
| try { | ||
| const content = await fs.readFile(CONFIG_FILE, 'utf8'); | ||
| return JSON.parse(content) as Config; | ||
| } catch (err: any) { | ||
| if (err.code === 'ENOENT') { | ||
| return {}; // no config yet | ||
| } | ||
| throw new Error(`Error reading config file: ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Save config back to file | ||
| */ | ||
| static async saveConfig(config: Config): Promise<void> { | ||
| await fs.mkdir(CONFIG_DIR, { recursive: true }); | ||
| await fs.writeFile(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8'); | ||
| } | ||
|
|
||
| /** | ||
| * Add or update an auth entry by merging with existing entry if present | ||
| */ | ||
| static async addAuthEntry(entry: AuthEntry): Promise<void> { | ||
| const config = await this.loadConfig(); | ||
|
|
||
| // Ensure config.auth is initialized as an array | ||
| config.auth ??= []; | ||
|
|
||
| // Find existing entry by pattern | ||
| const existingEntry = config.auth.find(e => e.pattern === entry.pattern); | ||
|
|
||
| if (existingEntry) { | ||
| // Merge new entry into existing one | ||
| Object.assign(existingEntry, entry); | ||
| } else { | ||
| // No existing entry, add new one | ||
| config.auth.push(entry); | ||
| } | ||
|
|
||
| await this.saveConfig(config); | ||
| } | ||
|
|
||
| /** | ||
| * Reads auth config from ~/.asyncapi/config.json and | ||
| * returns auth info matching the given URL, or null if no match. | ||
| * | ||
| * @param url - URL to match against auth patterns | ||
| * @returns Auth info or null if no match found | ||
| */ | ||
| static async getAuthForUrl(url: string): Promise<AuthResult | null> { | ||
| const config = await this.loadConfig(); | ||
|
|
||
| if (!config.auth || !Array.isArray(config.auth)) { | ||
| console.warn('⚠️ No valid "auth" array found in config'); | ||
| return null; | ||
| } | ||
|
|
||
| for (const entry of config.auth) { | ||
| try { | ||
| if (minimatch(url, entry.pattern)) { | ||
| return { | ||
| token: entry.token, | ||
| authType: entry.authType || 'Bearer', | ||
| headers: entry.headers || {} | ||
| }; | ||
| } | ||
| } catch (err: any) { | ||
| console.warn(`⚠️ Invalid pattern "${entry.pattern}": ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.