From 0e7728861db0e8092d5b66d0ca267d7843e19f1e Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Sun, 17 Mar 2019 11:18:49 +0900 Subject: [PATCH] Allow credentials to be retrieved from the environment. --- README.md | 8 ++++++++ tasks/patch_wordpress.js | 18 +++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 98f2813..4e52e39 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,14 @@ After you've made changes to your local WordPress develop repository, you can up grunt upload_patch:2907 ``` +You can also store your WordPress.org credentials in environment variables. Please exercise caution when using this option, as it may cause your credentials to be leaked! + +```bash +export WPORG_USERNAME=matt +export WPORG_PASSWORD=MyPasswordIsVerySecure12345 +grunt uploadPatch:40000 +``` + ## Using the file_mappings option If you'd like to map old file paths in your patch to new file paths during the patching process, you can pass a file mappings object as an option. Using this option can be helpful when the file paths in the project have been changed since you've created your patch. diff --git a/tasks/patch_wordpress.js b/tasks/patch_wordpress.js index c38f6ff..cf0620a 100644 --- a/tasks/patch_wordpress.js +++ b/tasks/patch_wordpress.js @@ -326,13 +326,17 @@ module.exports = function( grunt ) { ); } ); }; - 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 ); + 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 ); + } + ); } - ); } ); };