diff --git a/config/confd/templates/env.tmpl b/config/confd/templates/env.tmpl index 83904ccae..7a514f1d5 100644 --- a/config/confd/templates/env.tmpl +++ b/config/confd/templates/env.tmpl @@ -36,6 +36,7 @@ IMAGE_STORAGE_ENDPOINT={{getenv "IMAGE_STORAGE_ENDPOINT"}} IMAGE_STORAGE_FORCE_PATH_STYLE={{getenv "IMAGE_STORAGE_FORCE_PATH_STYLE"}} IMAGE_STORAGE_PREFIX={{getenv "IMAGE_STORAGE_PREFIX"}} IMAGE_STORAGE_SECRET_KEY={{getenv "IMAGE_STORAGE_SECRET_KEY"}} +IMAGE_STORAGE_DEBUG_REQUEST_ERRORS={{getenv "IMAGE_STORAGE_DEBUG_REQUEST_ERRORS"}} JSON_WEB_TOKEN_EXPIRY_MINUTES={{getenv "JSON_WEB_TOKEN_EXPIRY_MINUTES"}} JSON_WEB_TOKEN_SECRET='{{getenv "JSON_WEB_TOKEN_SECRET"}}' JSON_WEB_TOKEN_LIMIT_EXPIRY_REFRESH='{{getenv "JSON_WEB_TOKEN_LIMIT_EXPIRY_REFRESH"}}' diff --git a/src/features/device-types/device-types-list.ts b/src/features/device-types/device-types-list.ts index d1bbf0071..320afc988 100644 --- a/src/features/device-types/device-types-list.ts +++ b/src/features/device-types/device-types-list.ts @@ -18,6 +18,7 @@ import { DEVICE_TYPES_CACHE_LOCAL_TIMEOUT, DEVICE_TYPES_CACHE_TIMEOUT, CONTRACT_ALLOWLIST, + IMAGE_STORAGE_DEBUG_REQUEST_ERRORS, } from '../../lib/config.js'; export interface DeviceTypeInfo { @@ -45,10 +46,12 @@ const getFirstValidBuild = async ( try { deviceType = await getDeviceTypeJson(slug, buildId); } catch (err) { - captureException( - err, - `Failed to get device type build data for ${slug}/${buildId}`, - ); + if (IMAGE_STORAGE_DEBUG_REQUEST_ERRORS) { + captureException( + err, + `Failed to get device type build data for ${slug}/${buildId}`, + ); + } } if (deviceType) { const logoUrl = await getLogoUrl(slug, buildId); diff --git a/src/features/device-types/storage/s3.ts b/src/features/device-types/storage/s3.ts index 5c2701a18..6b546645b 100644 --- a/src/features/device-types/storage/s3.ts +++ b/src/features/device-types/storage/s3.ts @@ -10,6 +10,7 @@ import { IMAGE_STORAGE_ENDPOINT, IMAGE_STORAGE_FORCE_PATH_STYLE, IMAGE_STORAGE_SECRET_KEY, + IMAGE_STORAGE_DEBUG_REQUEST_ERRORS, } from '../../../lib/config.js'; export const getKey = (...parts: string[]): string => parts.join('/'); @@ -68,9 +69,11 @@ function isUnauthenticatedError( } function logUnauthenticated(pathS3: string, err: any): void { - console.warn( - `${err.code} (${err.statusCode}): ${pathS3} belongs to a private device type or has incorrect permissions`, - ); + if (IMAGE_STORAGE_DEBUG_REQUEST_ERRORS) { + console.warn( + `${err.code} (${err.statusCode}): ${pathS3} belongs to a private device type or has incorrect permissions`, + ); + } } async function getFileInfo(s3Path: string) { diff --git a/src/lib/config.ts b/src/lib/config.ts index 088cad468..ac6264309 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -182,6 +182,12 @@ export const IMAGE_STORAGE_FORCE_PATH_STYLE = boolVar( 'IMAGE_STORAGE_FORCE_PATH_STYLE', false, ); +export const IMAGE_STORAGE_DEBUG_REQUEST_ERRORS = boolVar( + 'IMAGE_STORAGE_DEBUG_REQUEST_ERRORS', + // Default to false for unauthenticated setups, so that we reduce + // the number of expected unauthorized request errors that get logged. + IMAGE_STORAGE_ACCESS_KEY != null || IMAGE_STORAGE_SECRET_KEY != null, +); export const JSON_WEB_TOKEN_EXPIRY_MINUTES = intVar( 'JSON_WEB_TOKEN_EXPIRY_MINUTES', );