Allow the Skynet-API-Key header.

Add a health-check command for fetching the test user's API key.
This commit is contained in:
Ivaylo Novakov 2022-02-15 14:59:19 +01:00
parent a13ee347e9
commit 0c8fa3283b
No known key found for this signature in database
GPG Key ID: 06B9354AB08BE9C6
3 changed files with 26 additions and 2 deletions

View File

@ -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';

View File

@ -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",

View File

@ -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,