Skip to content

Try adding keytar to store credentials #82

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_js:
- '12'
before_install:
- npm install -g grunt-cli
- sudo apt-get -y install libsecret-1-dev
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dependencies": {
"grunt": "^1.0.3",
"inquirer": "^5.1.0",
"keytar": "^5.1.0",
"request": "^2.83.0",
"xmlrpc": "^1.3.1"
},
Expand Down
32 changes: 21 additions & 11 deletions tasks/patch_wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const exec = require( 'child_process' ).exec;
const execSync = require( 'child_process' ).execSync;
const spawn = require( 'child_process' ).spawn;
const inquirer = require( 'inquirer' );
const keytar = require( 'keytar' );
const url = require( 'url' );
const fs = require( 'fs' );
const trac = require( '../lib/trac.js' );
Expand Down Expand Up @@ -335,17 +336,26 @@ module.exports = function( grunt ) {
);
} );
};
if ( process.env.WPORG_USERNAME && process.env.WPORG_PASSWORD ) {
uploadPatchWithCredentials( process.env.WPORG_USERNAME, process.env.WPORG_PASSWORD );
} else {
inquirer.prompt(
[
{ type: 'input', name: 'username', message: 'Enter your WordPress.org username' },
{ type: 'password', name: 'password', message: 'Enter your WordPress.org password' },
] ).then( ( answers ) => {
uploadPatchWithCredentials( answers.username, answers.password );
const getCredentials = keytar.findCredentials( 'wporg_patch' );
getCredentials.then( ( savedCredentials ) => {
if ( savedCredentials.length > 0 ) {
uploadPatchWithCredentials( savedCredentials[ 0 ].account, savedCredentials[ 0 ].password );
} else if ( process.env.WPORG_USERNAME && process.env.WPORG_PASSWORD ) {
uploadPatchWithCredentials( process.env.WPORG_USERNAME, process.env.WPORG_PASSWORD );
} else {
inquirer.prompt(
[
{ type: 'input', name: 'username', message: 'Enter your WordPress.org username' },
{ type: 'password', name: 'password', message: 'Enter your WordPress.org password' },
{ type: 'confirm', name: 'saveCredentials', message: 'Save your credentials?' },
] ).then( ( answers ) => {
uploadPatchWithCredentials( answers.username, answers.password );
if ( answers.saveCredentials ) {
keytar.setPassword( 'wporg_patch', answers.username, answers.password );
}
}
);
}
);
}
} );
} );
};