Skip to content

Commit

Permalink
Type config mappings to ensure keys exist
Browse files Browse the repository at this point in the history
In the process, remove mappings for keys that no longer exist, and
add missing mappings for keys that do exist.
  • Loading branch information
unflxw committed Feb 1, 2023
1 parent e5b2e21 commit 77b9ff8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe("Configuration", () => {
"content-length",
"range"
],
sendEnvironmentMetadata: true,
sendParams: true,
sendSessionData: true
}
Expand Down
3 changes: 1 addition & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Configuration {
*
* @private
*/
private _defaultValues(): { [key: string]: any } {
private _defaultValues(): Partial<AppsignalOptions> {
return {
active: false,
caFilePath: path.join(__dirname, "../cert/cacert.pem"),
Expand Down Expand Up @@ -125,7 +125,6 @@ export class Configuration {
"content-length",
"range"
],
sendEnvironmentMetadata: true,
sendParams: true,
sendSessionData: true
}
Expand Down
16 changes: 6 additions & 10 deletions src/config/configmap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const ENV_TO_KEY_MAPPING: { [key: string]: string } = {
import type { AppsignalOptions } from "./options"

export const ENV_TO_KEY_MAPPING: Record<string, keyof AppsignalOptions> = {
APPSIGNAL_ACTIVE: "active",
APPSIGNAL_APP_ENV: "environment",
APPSIGNAL_APP_NAME: "name",
Expand All @@ -10,17 +12,13 @@ export const ENV_TO_KEY_MAPPING: { [key: string]: string } = {
APPSIGNAL_ENABLE_STATSD: "enableStatsd",
APPSIGNAL_ENABLE_NGINX_METRICS: "enableNginxMetrics",
APPSIGNAL_FILES_WORLD_ACCESSIBLE: "filesWorldAccessible",
APPSIGNAL_FILTER_DATA_KEYS: "filterDataKeys",
APPSIGNAL_FILTER_PARAMETERS: "filterParameters",
APPSIGNAL_FILTER_SESSION_DATA: "filterSessionData",
APPSIGNAL_HOSTNAME: "hostname",
APPSIGNAL_HTTP_PROXY: "httpProxy",
APPSIGNAL_IGNORE_ACTIONS: "ignoreActions",
APPSIGNAL_IGNORE_ERRORS: "ignoreErrors",
APPSIGNAL_IGNORE_NAMESPACES: "ignoreNamespaces",
APPSIGNAL_INSTRUMENT_HTTP: "instrumentHttp",
APPSIGNAL_INSTRUMENT_PG: "instrumentPg",
APPSIGNAL_INSTRUMENT_REDIS: "instrumentRedis",
APPSIGNAL_LOG: "log",
APPSIGNAL_LOG_LEVEL: "logLevel",
APPSIGNAL_LOG_PATH: "logPath",
Expand All @@ -29,14 +27,13 @@ export const ENV_TO_KEY_MAPPING: { [key: string]: string } = {
APPSIGNAL_PUSH_API_KEY: "pushApiKey",
APPSIGNAL_REQUEST_HEADERS: "requestHeaders",
APPSIGNAL_RUNNING_IN_CONTAINER: "runningInContainer",
APPSIGNAL_SEND_ENVIRONMENT_METADATA: "sendEnvironmentMetadata",
APPSIGNAL_SEND_PARAMS: "sendParams",
APPSIGNAL_SEND_SESSION_DATA: "sendSessionData",
APPSIGNAL_WORKING_DIRECTORY_PATH: "workingDirectoryPath",
APP_REVISION: "revision"
}

export const PRIVATE_ENV_MAPPING: { [key: string]: string } = {
export const PRIVATE_ENV_MAPPING: Record<string, keyof AppsignalOptions> = {
_APPSIGNAL_ACTIVE: "active",
_APPSIGNAL_APP_NAME: "name",
_APPSIGNAL_CA_FILE_PATH: "caFilePath",
Expand All @@ -59,14 +56,13 @@ export const PRIVATE_ENV_MAPPING: { [key: string]: string } = {
_APPSIGNAL_PUSH_API_ENDPOINT: "endpoint",
_APPSIGNAL_PUSH_API_KEY: "pushApiKey",
_APPSIGNAL_RUNNING_IN_CONTAINER: "runningInContainer",
_APPSIGNAL_SEND_ENVIRONMENT_METADATA: "sendEnvironmentMetadata",
_APPSIGNAL_SEND_PARAMS: "sendParams",
_APPSIGNAL_SEND_SESSION_DATA: "sendSessionData",
_APPSIGNAL_WORKING_DIRECTORY_PATH: "workingDirectoryPath",
_APP_REVISION: "revision"
}

export const JS_TO_RUBY_MAPPING: { [key: string]: string } = {
export const JS_TO_RUBY_MAPPING: Record<keyof AppsignalOptions, string> = {
active: "active",
pushApiKey: "push_api_key",
caFilePath: "ca_file_path",
Expand All @@ -82,6 +78,7 @@ export const JS_TO_RUBY_MAPPING: { [key: string]: string } = {
filterParameters: "filter_parameters",
filterSessionData: "filter_session_data",
hostname: "hostname",
httpProxy: "http_proxy",
ignoreActions: "ignore_actions",
ignoreErrors: "ignore_errors",
ignoreNamespaces: "ignore_namespaces",
Expand All @@ -93,7 +90,6 @@ export const JS_TO_RUBY_MAPPING: { [key: string]: string } = {
requestHeaders: "request_headers",
revision: "revision",
runningInContainer: "running_in_container",
sendEnvironmentMetadata: "send_environment_metadata",
sendParams: "send_params",
sendSessionData: "send_session_data",
workingDirectoryPath: "working_directory_path"
Expand Down
2 changes: 1 addition & 1 deletion src/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class DiagnoseTool {
const config: { [key: string]: any } = {}

Object.keys(options).forEach(key => {
const newKey = JS_TO_RUBY_MAPPING[key]
const newKey = (JS_TO_RUBY_MAPPING as Record<string, any>)[key]
if (newKey) {
config[newKey] = (options as Record<string, any>)[key]
}
Expand Down

0 comments on commit 77b9ff8

Please sign in to comment.