-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Postman Authorization via API Key (#52)
* Add support for Postman Authorization via API key * fix: adjust auth header * fix: pass auth header to introspection * fix: allheaders --------- Co-authored-by: nohehf <[email protected]>
- Loading branch information
Showing
7 changed files
with
98 additions
and
148 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
"ci": "deno fmt --check && deno lint" | ||
}, | ||
"fmt": { | ||
"files": { | ||
"exclude": ["out"] | ||
} | ||
"exclude": ["out"] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { parseHeaders, saveJsonFormatted } from "./lib.ts"; | ||
import { parseHeader, parseHeaders, saveJsonFormatted } from "./lib.ts"; | ||
import { | ||
ensureDirSync, | ||
ensureFileSync, | ||
|
@@ -11,21 +11,31 @@ import { createPostmanCollection } from "./index.ts"; | |
function help() { | ||
console.log(`Error: not enough arguments. | ||
Usage: | ||
deno run index.ts <GRAPHQL_ENDPOINT_URL> | ||
deno run index.ts <GRAPHQL_ENDPOINT_URL> | ||
Options: | ||
--out=OUTPUT_FILE Output file path | ||
-H="header: value" Header to add to the request, the flag can be used multiple times. | ||
--AuthHeader="header: value", -A="header: value" Global header for Postman collection authorization. | ||
Help: | ||
deno run index.ts [--help | -h] | ||
`); | ||
} | ||
|
||
const args = parse(Deno.args, { boolean: ["help", "h"], collect: ["H"] }) as { | ||
const args = parse(Deno.args, { | ||
boolean: ["help", "h"], | ||
collect: ["H"], | ||
string: ["AuthHeader", "A"], | ||
alias: { | ||
AuthHeader: "A", | ||
}, | ||
}) as { | ||
_: [string]; | ||
help?: boolean; | ||
h?: boolean; | ||
out?: string; | ||
H?: [string]; | ||
AuthHeader?: string; | ||
A?: string; | ||
}; | ||
|
||
if (Deno.args.length < 1 || args.help || args.h) { | ||
|
@@ -35,19 +45,28 @@ if (Deno.args.length < 1 || args.help || args.h) { | |
|
||
const url = args._[0]; | ||
let path = args.out; | ||
const headers = parseHeaders(args.H); | ||
|
||
const headers = parseHeaders(args.H || []); | ||
|
||
// Handle the AuthHeader separately | ||
const authHeaderRaw = args.AuthHeader ?? args.A; | ||
let authHeader: [string, string] | undefined; | ||
if (authHeaderRaw) { | ||
authHeader = parseHeader(authHeaderRaw); | ||
} | ||
|
||
const urlRegexp = /https?:\/\/*/; | ||
if (!urlRegexp.test(url)) { | ||
console.error(`${url} is not a valid url`); | ||
Deno.exit(1); | ||
} | ||
|
||
console.log(`Creating the postman collection for ${url}`); | ||
console.log(`Creating the Postman collection for ${url}`); | ||
|
||
const { postmanCollection } = await createPostmanCollection( | ||
const postmanCollection = await createPostmanCollection( | ||
url, | ||
headers, | ||
authHeader, | ||
); | ||
|
||
path = path || | ||
|
@@ -62,4 +81,4 @@ try { | |
saveJsonFormatted(postmanCollection, path); | ||
console.log(`Collection saved at ${path}`); | ||
|
||
console.log(`Import it in postman and complete the queries ! 🚀`); | ||
console.log(`Import it in Postman and complete the queries! 🚀`); |
Oops, something went wrong.