-
Notifications
You must be signed in to change notification settings - Fork 187
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
BREAKING CHANGE(cli): Port Logout Command #60
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const BaseCommand = require('../ZapierBaseCommand'); | ||
const { buildFlags } = require('../buildFlags'); | ||
|
||
const { callAPI } = require('../../utils/api'); | ||
const { deleteFile } = require('../../utils/files'); | ||
const { AUTH_LOCATION, AUTH_LOCATION_RAW } = require('../../constants'); | ||
|
||
class LogoutCommand extends BaseCommand { | ||
async perform() { | ||
this.log( | ||
'Preparing to deactivate local deploy key and reset local configs.' | ||
); | ||
this.startSpinner('Deactivating local deploy key'); | ||
try { | ||
await callAPI('/keys', { method: 'DELETE', body: { single: true } }); | ||
} catch (e) { | ||
this.warn( | ||
'Deletion API request failed. If this is unexpected, rerun this command with `--debug` for more info.' | ||
); | ||
} | ||
this.stopSpinner(); | ||
|
||
this.startSpinner(`Destroying \`${AUTH_LOCATION_RAW}\``); | ||
const success = deleteFile(AUTH_LOCATION); | ||
this.debug(`file deletion success?: ${success}`); | ||
this.stopSpinner(); | ||
|
||
this.log('The active deploy key was deactivated'); | ||
} | ||
} | ||
|
||
LogoutCommand.flags = buildFlags({ opts: { format: true } }); | ||
LogoutCommand.examples = ['zapier logout']; | ||
LogoutCommand.description = `Deactivates your acive deploy key and resets \`${AUTH_LOCATION_RAW}\`.`; | ||
|
||
module.exports = LogoutCommand; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,10 +95,15 @@ const callAPI = (route, options, rawError = false) => { | |
debug(`>> ${requestOptions.method} ${requestOptions.url}`); | ||
if (requestOptions.body) { | ||
const replacementStr = 'raw zip removed in logs'; | ||
const cleanedBody = _.assign({}, JSON.parse(requestOptions.body), { | ||
zip_file: replacementStr, | ||
source_zip_file: replacementStr | ||
}); | ||
const requestBody = JSON.parse(requestOptions.body); | ||
const cleanedBody = {}; | ||
for (const k in requestBody) { | ||
if (k.includes('zip_file')) { | ||
cleanedBody[k] = replacementStr; | ||
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. now this won't add |
||
} else { | ||
cleanedBody[k] = requestBody[k]; | ||
} | ||
} | ||
debug(`>> ${JSON.stringify(cleanedBody)}`); | ||
} | ||
debug(`<< ${res.status}`); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,16 +45,14 @@ const writeFile = (fileName, data) => { | |
return fse.writeFile(fixHome(fileName), data); | ||
}; | ||
|
||
// Returns a promise that deletes the file. | ||
const deleteFile = fileName => { | ||
return new Promise(resolve => { | ||
try { | ||
fse.unlinkSync(fileName); | ||
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. I'm not sure why we were wrapping a sync method in a promise (instead of using the async version or no promise at all). Went ahead and did "just plain sync". |
||
} catch (err) { | ||
resolve(); | ||
} | ||
resolve(); | ||
}); | ||
// deletes a file, eats the error | ||
const deleteFile = path => { | ||
try { | ||
fse.unlinkSync(path); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
}; | ||
|
||
// Returns a promise that ensures a directory exists. | ||
|
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.
When the server fails to delete the key and returns an error, should we just exit? I know this follows the original implementation, but maybe it makes more sense not to continue if an error happens.
Another issue I found is when I tested
zapier logout
with.zapierrc
absent, the output formatting is off:I think adding a
this.endSpinner()
before printing the warning message should fix the formatting issue.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.
used a
finally
! good catch.