From 518060d24dd1bf9b310f6a2c6f97f42969160748 Mon Sep 17 00:00:00 2001 From: Marquise Rosier Date: Fri, 13 Sep 2019 17:21:12 -0700 Subject: [PATCH] feat(pub): protect X-Debug with key --- src/publish.js | 3 +++ src/remotepublish.cmd.js | 7 +++++++ src/yargs-debug.js | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/yargs-debug.js diff --git a/src/publish.js b/src/publish.js index ebdfd57ef..a6fc13687 100644 --- a/src/publish.js +++ b/src/publish.js @@ -14,6 +14,7 @@ const yargsOpenwhisk = require('./yargs-openwhisk.js'); const yargsFastly = require('./yargs-fastly.js'); +const yargsDebug = require('./yargs-debug.js'); const yargsGithub = require('./yargs-github.js'); const { makeLogger } = require('./log-common.js'); @@ -29,6 +30,7 @@ module.exports = function strain() { builder: (yargs) => { yargsOpenwhisk(yargs); yargsFastly(yargs); + yargsDebug(yargs); yargsGithub(yargs); yargs .option('dry-run', { @@ -116,6 +118,7 @@ module.exports = function strain() { .withWskHost(argv.wskHost) .withWskNamespace(argv.wskNamespace) .withFastlyNamespace(argv.fastlyNamespace) + .withDebugKey(argv.debugKey) .withFastlyAuth(argv.fastlyAuth) .withDryRun(argv.dryRun) .withPublishAPI(argv.apiPublish) diff --git a/src/remotepublish.cmd.js b/src/remotepublish.cmd.js index 2025bca60..99dcd285b 100644 --- a/src/remotepublish.cmd.js +++ b/src/remotepublish.cmd.js @@ -32,6 +32,7 @@ class RemotePublishCommand extends AbstractCommand { this._wsk_namespace = null; this._wsk_host = null; this._fastly_namespace = null; + this._debug_key = null; this._fastly_auth = null; this._dryRun = false; this._publishAPI = 'https://adobeioruntime.net/api/v1/web/helix/helix-services/publish@v2'; @@ -127,6 +128,11 @@ class RemotePublishCommand extends AbstractCommand { return this; } + withDebugKey(value) { + this._debug_key = value; + return this; + } + withFilter(only, exclude) { if (!(only || exclude)) { return this; @@ -293,6 +299,7 @@ ${e}`); configuration: this.config.toJSON(), service: this._fastly_namespace, token: this._fastly_auth, + debugKey: this._debug_key || this._fastly_namespace, version: this._version, }; diff --git a/src/yargs-debug.js b/src/yargs-debug.js new file mode 100644 index 000000000..051a31043 --- /dev/null +++ b/src/yargs-debug.js @@ -0,0 +1,20 @@ +/* + * Copyright 2019 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +module.exports = function commonArgs(yargs) { + return yargs + .option('debug-key', { + alias: 'debugKey', + describe: 'The key to enable the X-Debug header (default is the fastly service id)', + type: 'string', + }); +};