@mcma/client
Version:
Node module with classes and functions used to access services in an MCMA environment
30 lines (29 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.McmaApiKeyAuthenticator = void 0;
const config_variables_ext_1 = require("./config-variables-ext");
const core_1 = require("@mcma/core");
class McmaApiKeyAuthenticator {
config;
constructor(config) {
this.config = config;
if (!this.config.apiKey) {
if (!this.config.secretsProvider) {
throw new core_1.McmaException("McmaAuthenticatorConfig misses property 'secretsProvider'");
}
if (!this.config.apiKeySecretId) {
this.config.apiKeySecretId = (0, config_variables_ext_1.getApiKeySecretId)();
}
}
}
async sign(config) {
if (!this.config.apiKey) {
this.config.apiKey = await this.config.secretsProvider.get(this.config.apiKeySecretId);
}
if (!config.headers) {
config.headers = {};
}
config.headers["x-mcma-api-key"] = this.config.apiKey;
}
}
exports.McmaApiKeyAuthenticator = McmaApiKeyAuthenticator;