From 0c8fa3283b6041059ce4fcdb001b8cd8d59c0fee Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 15 Feb 2022 14:59:19 +0100 Subject: [PATCH 1/4] Allow the Skynet-API-Key header. Add a health-check command for fetching the test user's API key. --- docker/nginx/conf.d/include/cors-headers | 4 ++-- packages/health-check/bin/cli | 10 ++++++++++ packages/health-check/src/utils.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docker/nginx/conf.d/include/cors-headers b/docker/nginx/conf.d/include/cors-headers index 58369b65..873cb4c9 100644 --- a/docker/nginx/conf.d/include/cors-headers +++ b/docker/nginx/conf.d/include/cors-headers @@ -1,5 +1,5 @@ more_set_headers 'Access-Control-Allow-Origin: $http_origin'; more_set_headers 'Access-Control-Allow-Credentials: true'; more_set_headers 'Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE'; -more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,If-None-Match,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location'; -more_set_headers 'Access-Control-Expose-Headers: Content-Length,Content-Range,ETag,Skynet-File-Metadata,Skynet-Skylink,Skynet-Proof,Skynet-Portal-Api,Skynet-Server-Api,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location'; +more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,If-None-Match,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location,Skynet-API-Key'; +more_set_headers 'Access-Control-Expose-Headers: Content-Length,Content-Range,ETag,Skynet-File-Metadata,Skynet-Skylink,Skynet-Proof,Skynet-Portal-Api,Skynet-Server-Api,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location,Skynet-API-Key'; diff --git a/packages/health-check/bin/cli b/packages/health-check/bin/cli index dbf39344..5788b0be 100755 --- a/packages/health-check/bin/cli +++ b/packages/health-check/bin/cli @@ -16,6 +16,16 @@ require("yargs/yargs")(process.argv.slice(2)) console.log(await getAuthCookie(true)); } ) + .command( + "apikey", + "Get test user's API key", + () => {}, + async () => { + const { getAPIKey } = require("../src/utils"); + + console.log(await getAPIKey()); + } + ) .command( "enable", "Mark portal as enabled", diff --git a/packages/health-check/src/utils.js b/packages/health-check/src/utils.js index 8dbab0de..929fae5f 100644 --- a/packages/health-check/src/utils.js +++ b/packages/health-check/src/utils.js @@ -61,6 +61,19 @@ function getRequiredEnvironmentVariable(name) { return value; } +/** + * Fetches test user's API key from the environment. Raises an error if that + * is not possible. + * @returns {string} API key + */ +function getAPIKey() { + const apiKey = getRequiredEnvironmentVariable("ACCOUNTS_TEST_USER_API_KEY"); + if (!apiKey) { + throw new Error("Missing or empty environment variable ACCOUNTS_TEST_USER_API_KEY."); + } + return apiKey; +} + /** * Authenticate with given credentials and return auth cookie * Creates new account if username does not exist @@ -138,6 +151,7 @@ module.exports = { getResponseContent, ensureValidJSON, getAuthCookie, + getAPIKey, isPortalModuleEnabled, ipCheckService, ipRegex, From 6371ee57e52e9f4d8d7f63e9a2bb5a22d42cdddf Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 15 Feb 2022 15:21:03 +0100 Subject: [PATCH 2/4] Update docker/nginx/conf.d/include/cors-headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Karol Wypchło --- docker/nginx/conf.d/include/cors-headers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/nginx/conf.d/include/cors-headers b/docker/nginx/conf.d/include/cors-headers index 873cb4c9..0f0bb328 100644 --- a/docker/nginx/conf.d/include/cors-headers +++ b/docker/nginx/conf.d/include/cors-headers @@ -2,4 +2,4 @@ more_set_headers 'Access-Control-Allow-Origin: $http_origin'; more_set_headers 'Access-Control-Allow-Credentials: true'; more_set_headers 'Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE'; more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,If-None-Match,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location,Skynet-API-Key'; -more_set_headers 'Access-Control-Expose-Headers: Content-Length,Content-Range,ETag,Skynet-File-Metadata,Skynet-Skylink,Skynet-Proof,Skynet-Portal-Api,Skynet-Server-Api,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location,Skynet-API-Key'; +more_set_headers 'Access-Control-Expose-Headers: Content-Length,Content-Range,ETag,Skynet-File-Metadata,Skynet-Skylink,Skynet-Proof,Skynet-Portal-Api,Skynet-Server-Api,upload-offset,upload-metadata,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,upload-concat,location'; From 4177ed74d6936f7bcd95015085655aef47d4f1ff Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 15 Feb 2022 15:22:36 +0100 Subject: [PATCH 3/4] Remove unneeded methods. --- packages/health-check/bin/cli | 10 ---------- packages/health-check/src/utils.js | 13 ------------- 2 files changed, 23 deletions(-) diff --git a/packages/health-check/bin/cli b/packages/health-check/bin/cli index 5788b0be..dbf39344 100755 --- a/packages/health-check/bin/cli +++ b/packages/health-check/bin/cli @@ -16,16 +16,6 @@ require("yargs/yargs")(process.argv.slice(2)) console.log(await getAuthCookie(true)); } ) - .command( - "apikey", - "Get test user's API key", - () => {}, - async () => { - const { getAPIKey } = require("../src/utils"); - - console.log(await getAPIKey()); - } - ) .command( "enable", "Mark portal as enabled", diff --git a/packages/health-check/src/utils.js b/packages/health-check/src/utils.js index 929fae5f..00e8f86d 100644 --- a/packages/health-check/src/utils.js +++ b/packages/health-check/src/utils.js @@ -61,19 +61,6 @@ function getRequiredEnvironmentVariable(name) { return value; } -/** - * Fetches test user's API key from the environment. Raises an error if that - * is not possible. - * @returns {string} API key - */ -function getAPIKey() { - const apiKey = getRequiredEnvironmentVariable("ACCOUNTS_TEST_USER_API_KEY"); - if (!apiKey) { - throw new Error("Missing or empty environment variable ACCOUNTS_TEST_USER_API_KEY."); - } - return apiKey; -} - /** * Authenticate with given credentials and return auth cookie * Creates new account if username does not exist From 52f231dc1c1ac6f1e4370151044300b7d343cf62 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 15 Feb 2022 15:28:43 +0100 Subject: [PATCH 4/4] Remove unneeded methods. --- packages/health-check/src/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/health-check/src/utils.js b/packages/health-check/src/utils.js index 00e8f86d..8dbab0de 100644 --- a/packages/health-check/src/utils.js +++ b/packages/health-check/src/utils.js @@ -138,7 +138,6 @@ module.exports = { getResponseContent, ensureValidJSON, getAuthCookie, - getAPIKey, isPortalModuleEnabled, ipCheckService, ipRegex,