From 739c7d0c73386164260fe1fc1cfcfb0887db3a9b Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sun, 9 Feb 2020 14:49:52 -0700 Subject: [PATCH 1/3] Try adding keytar to store credentials See: https://core.trac.wordpress.org/ticket/49390 Previusly: #40 --- package.json | 1 + tasks/patch_wordpress.js | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6561686..5b415ec 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/tasks/patch_wordpress.js b/tasks/patch_wordpress.js index 5568f44..ad15cb0 100644 --- a/tasks/patch_wordpress.js +++ b/tasks/patch_wordpress.js @@ -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' ); @@ -335,17 +336,27 @@ 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 ); + } + } + ); + } + }); } ); }; From 6d295f65f48ca5049fa741d5fd4aff79f45aaa81 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sun, 9 Feb 2020 14:59:26 -0700 Subject: [PATCH 2/3] install libsecret for build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2ef2d48..40d3f9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ node_js: - '12' before_install: - npm install -g grunt-cli + - sudo apt-get -y install libsecret-1-dev From 42054d22e9dcacabebc1f0e65fd30d270902a012 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sun, 9 Feb 2020 15:05:37 -0700 Subject: [PATCH 3/3] fix lint --- tasks/patch_wordpress.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tasks/patch_wordpress.js b/tasks/patch_wordpress.js index ad15cb0..a40e699 100644 --- a/tasks/patch_wordpress.js +++ b/tasks/patch_wordpress.js @@ -13,7 +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 keytar = require( 'keytar' ); const url = require( 'url' ); const fs = require( 'fs' ); const trac = require( '../lib/trac.js' ); @@ -337,11 +337,10 @@ module.exports = function( grunt ) { } ); }; 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 ) { + 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( @@ -351,12 +350,12 @@ module.exports = function( grunt ) { { 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 ); - } + if ( answers.saveCredentials ) { + keytar.setPassword( 'wporg_patch', answers.username, answers.password ); + } } ); } - }); + } ); } ); };