-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
15,250 additions
and
14,750 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,16 +54,18 @@ prog | |
.command('rebuild <url>') | ||
.option('-v, --verbose', 'Enable verbose output') | ||
.option('-u, --user', 'The email address to use for authentication.') | ||
.option('-l, --local', 'Build from locally served OpenAPI spec.') | ||
.describe('Rebuilds the the SDK after entities have been updated.') | ||
.example('rebuild http://localhost:8080 -u [email protected]') | ||
.action((url, opts) => { | ||
const user = opts.user || opts.u; | ||
if (!user) { | ||
const local = opts.local || opts.l; | ||
if (!user && !local) { | ||
console.log('The user param is required.'); | ||
return; | ||
} | ||
const run = async () => { | ||
const password = await handlePassword('password:'); | ||
const password = !local ? await handlePassword('password:') : ''; | ||
await rebuild(url, opts, password); | ||
}; | ||
|
||
|
@@ -73,38 +75,41 @@ prog | |
async function rebuild(url, opts, password) { | ||
const verbose = opts.verbose || opts.v; | ||
const user = opts.user || opts.u; | ||
const local = opts.local || opts.l; | ||
|
||
const headers = {}; | ||
if (verbose) { | ||
console.log('logging in to', url); | ||
} | ||
|
||
const tokenRes = await fetch(`${url}/auth/login`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ email: String(user), password: String(password) }), | ||
}).then((res) => res.json()); | ||
if (!local) { | ||
headers.Authorization = `Bearer ${tokenRes.token}`; | ||
const tokenRes = await fetch(`${url}/auth/login`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ email: String(user), password: String(password) }), | ||
}).then((res) => res.json()); | ||
|
||
if (!tokenRes.token) { | ||
if (verbose) { | ||
console.log(tokenRes); | ||
} | ||
|
||
if (!tokenRes.token) { | ||
if (verbose) { | ||
console.log(tokenRes); | ||
console.log('Invalid credentials'); | ||
return; | ||
} | ||
|
||
console.log('Invalid credentials'); | ||
return; | ||
} | ||
|
||
if (verbose) { | ||
console.log('token retrieved', String(tokenRes.token)); | ||
console.log('fetching from ', url); | ||
if (verbose) { | ||
console.log('token retrieved', String(tokenRes.token)); | ||
console.log('fetching from ', url); | ||
} | ||
} | ||
|
||
console.log('fetching latest spec...'); | ||
const response = await fetch(url, { | ||
headers: { | ||
Authorization: `Bearer ${tokenRes.token}`, | ||
}, | ||
headers, | ||
}); | ||
|
||
const text = await response.text(); | ||
|
@@ -139,7 +144,11 @@ async function rebuild(url, opts, password) { | |
|
||
if (err) { | ||
console.error(err); | ||
console.log('for additional information, add --verbose to the command.'); | ||
if (!verbose) { | ||
console.log( | ||
'for additional information, add --verbose to the command.' | ||
); | ||
} | ||
return; | ||
} | ||
|
||
|
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
allOf: | ||
- $ref: './Instance.yaml' | ||
- type: object | ||
properties: | ||
email: | ||
type: string | ||
password: | ||
type: string | ||
writeOnly: true |
Oops, something went wrong.