This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27069-main-env-underscores in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0b5934380c472de5af84edef9c9b1304eb6f2327 Author: Claus Ibsen <[email protected]> AuthorDate: Mon Nov 16 16:38:03 2026 +0100 CAMEL-27069: camel-main - an environment variable can have underscores between the words of an option camel-main turned each underscore of an OS environment variable into a dot, so the variables the vault components document, such as CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY, were bound as nested properties (camel.vault.gcp.service.account.key) and failed the startup. PrepareCamelMainMojo now also writes the keys of the camel-main options to org/apache/camel/main/main-options.properties. MainHelper maps a variable that matches one of these keys when underscores are ignored to that key, so CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY and CAMEL_VAULT_GCP_SERVICEACCOUNTKEY both set camel.vault.gcp.serviceAccountKey. Any other variable keeps the old mapping. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../org/apache/camel/main/main-options.properties | 599 +++++++++++++++++++++ .../java/org/apache/camel/main/MainHelper.java | 65 ++- .../camel/main/MainEnvVarUnderscoreOptionTest.java | 93 ++++ .../java/org/apache/camel/main/MainHelperTest.java | 21 + .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 12 + .../maven/packaging/PrepareCamelMainMojo.java | 6 + 6 files changed, 794 insertions(+), 2 deletions(-) diff --git a/core/camel-main/src/generated/resources/org/apache/camel/main/main-options.properties b/core/camel-main/src/generated/resources/org/apache/camel/main/main-options.properties new file mode 100644 index 000000000000..b1cecae1e648 --- /dev/null +++ b/core/camel-main/src/generated/resources/org/apache/camel/main/main-options.properties @@ -0,0 +1,599 @@ +camel.aiObservability.enabled +camel.chaos.enabled +camel.chaos.maxDuration +camel.chaos.reportFile +camel.chaos.reportOnShutdown +camel.chaos.rules +camel.chaos.scenario +camel.chaos.seed +camel.cluster.consul.aclToken +camel.cluster.consul.blockSeconds +camel.cluster.consul.configuration +camel.cluster.consul.connectTimeout +camel.cluster.consul.datacenter +camel.cluster.consul.enabled +camel.cluster.consul.id +camel.cluster.consul.password +camel.cluster.consul.readTimeout +camel.cluster.consul.rootPath +camel.cluster.consul.sessionLockDelay +camel.cluster.consul.sessionRefreshInterval +camel.cluster.consul.sessionTtl +camel.cluster.consul.sslContextParameters +camel.cluster.consul.url +camel.cluster.consul.userName +camel.cluster.consul.writeTimeout +camel.cluster.file.acquireLockDelay +camel.cluster.file.acquireLockDelayUnit +camel.cluster.file.acquireLockInterval +camel.cluster.file.acquireLockIntervalUnit +camel.cluster.file.clusterDataTaskMaxAttempts +camel.cluster.file.clusterDataTaskTimeout +camel.cluster.file.clusterDataTaskTimeoutUnit +camel.cluster.file.enabled +camel.cluster.file.heartbeatTimeoutMultiplier +camel.cluster.file.root +camel.cluster.infinispan.cacheContainer +camel.cluster.infinispan.cacheContainerConfiguration +camel.cluster.infinispan.configuration +camel.cluster.infinispan.configurationProperties +camel.cluster.infinispan.configurationUri +camel.cluster.infinispan.enabled +camel.cluster.infinispan.hosts +camel.cluster.infinispan.id +camel.cluster.infinispan.lifespan +camel.cluster.infinispan.lifespanTimeUnit +camel.cluster.infinispan.password +camel.cluster.infinispan.saslMechanism +camel.cluster.infinispan.secure +camel.cluster.infinispan.securityRealm +camel.cluster.infinispan.securityServerName +camel.cluster.infinispan.username +camel.cluster.jgroups-raft.enabled +camel.cluster.jgroups-raft.id +camel.cluster.jgroups-raft.jgroupsClusterName +camel.cluster.jgroups-raft.jgroupsConfig +camel.cluster.jgroups-raft.raftHandle +camel.cluster.kubernetes.clusterLabels +camel.cluster.kubernetes.configuration +camel.cluster.kubernetes.connectionTimeout +camel.cluster.kubernetes.enabled +camel.cluster.kubernetes.groupName +camel.cluster.kubernetes.jitterFactor +camel.cluster.kubernetes.kubernetesResourceName +camel.cluster.kubernetes.kubernetesResourcesNamespace +camel.cluster.kubernetes.leaseDurationMillis +camel.cluster.kubernetes.leaseResourceType +camel.cluster.kubernetes.masterUrl +camel.cluster.kubernetes.namespace +camel.cluster.kubernetes.podName +camel.cluster.kubernetes.renewDeadlineMillis +camel.cluster.kubernetes.retryPeriodMillis +camel.cluster.zookeeper.basePath +camel.cluster.zookeeper.connectTimeout +camel.cluster.zookeeper.enabled +camel.cluster.zookeeper.id +camel.cluster.zookeeper.maxCloseWait +camel.cluster.zookeeper.namespace +camel.cluster.zookeeper.nodes +camel.cluster.zookeeper.reconnectBaseSleepTime +camel.cluster.zookeeper.reconnectMaxRetries +camel.cluster.zookeeper.reconnectMaxSleepTime +camel.cluster.zookeeper.retryPolicy +camel.cluster.zookeeper.sessionTimeout +camel.debug.bodyIncludeFiles +camel.debug.bodyIncludeStreams +camel.debug.bodyMaxChars +camel.debug.breakpoints +camel.debug.enabled +camel.debug.fallbackTimeout +camel.debug.includeException +camel.debug.includeExchangeProperties +camel.debug.includeExchangeVariables +camel.debug.jmxConnectorEnabled +camel.debug.jmxConnectorPort +camel.debug.loggingLevel +camel.debug.singleStepIncludeStartEnd +camel.debug.standby +camel.debug.waitForAttach +camel.errorRegistry.bodyIncludeFiles +camel.errorRegistry.bodyIncludeStreams +camel.errorRegistry.bodyMaxChars +camel.errorRegistry.enabled +camel.errorRegistry.includeExchangeProperties +camel.errorRegistry.includeExchangeVariables +camel.errorRegistry.includeRouteStopping +camel.errorRegistry.maximumEntries +camel.errorRegistry.maximumEntriesPerKind +camel.errorRegistry.timeToLiveSeconds +camel.faulttolerance.bulkheadEnabled +camel.faulttolerance.bulkheadMaxConcurrentCalls +camel.faulttolerance.bulkheadWaitingTaskQueue +camel.faulttolerance.delay +camel.faulttolerance.failureRatio +camel.faulttolerance.requestVolumeThreshold +camel.faulttolerance.successThreshold +camel.faulttolerance.threadOffloadExecutorService +camel.faulttolerance.timeoutDuration +camel.faulttolerance.timeoutEnabled +camel.faulttolerance.typedGuard +camel.health.consumersEnabled +camel.health.enabled +camel.health.excludePattern +camel.health.exposureLevel +camel.health.initialState +camel.health.producersEnabled +camel.health.registryEnabled +camel.health.routesEnabled +camel.lra.allowedCoordinatorUrls +camel.lra.callbackSecret +camel.lra.coordinatorContextPath +camel.lra.coordinatorUrl +camel.lra.enabled +camel.lra.localParticipantContextPath +camel.lra.localParticipantUrl +camel.main.additionalSensitiveKeywords +camel.main.allowUseOriginalMessage +camel.main.autoConfigurationEnabled +camel.main.autoConfigurationEnvironmentVariablesEnabled +camel.main.autoConfigurationFailFast +camel.main.autoConfigurationLogSummary +camel.main.autoConfigurationSystemPropertiesEnabled +camel.main.autoStartup +camel.main.autoStartupExcludePattern +camel.main.autowiredEnabled +camel.main.basePackageScan +camel.main.basePackageScanEnabled +camel.main.beanIntrospectionExtendedStatistics +camel.main.beanIntrospectionLoggingLevel +camel.main.beanPostProcessorEnabled +camel.main.camelEventsTimestampEnabled +camel.main.caseInsensitiveHeaders +camel.main.cloudPropertiesLocation +camel.main.compileWorkDir +camel.main.configurationClasses +camel.main.configurations +camel.main.consumerTemplateCacheSize +camel.main.contextReloadEnabled +camel.main.description +camel.main.devConsoleEnabled +camel.main.dumpRoutes +camel.main.dumpRoutesGeneratedIds +camel.main.dumpRoutesInclude +camel.main.dumpRoutesLog +camel.main.dumpRoutesOutput +camel.main.dumpRoutesResolvePlaceholders +camel.main.dumpRoutesUriAsParameters +camel.main.duration +camel.main.durationHitExitCode +camel.main.durationMaxAction +camel.main.durationMaxIdleSeconds +camel.main.durationMaxMessages +camel.main.durationMaxSeconds +camel.main.endpointBridgeErrorHandler +camel.main.endpointLazyStartProducer +camel.main.endpointRuntimeStatisticsEnabled +camel.main.exchangeFactory +camel.main.exchangeFactoryCapacity +camel.main.exchangeFactoryStatisticsEnabled +camel.main.extraShutdownTimeout +camel.main.fileConfigurations +camel.main.globalOptions +camel.main.groovyPreloadCompiled +camel.main.groovyScriptPattern +camel.main.inflightRepositoryBrowseEnabled +camel.main.javaRoutesExcludePattern +camel.main.javaRoutesIncludePattern +camel.main.jmxEnabled +camel.main.jmxManagementMBeansLevel +camel.main.jmxManagementNamePattern +camel.main.jmxManagementRegisterRoutesCreateByKamelet +camel.main.jmxManagementRegisterRoutesCreateByTemplate +camel.main.jmxManagementStatisticsLevel +camel.main.jmxUpdateRouteEnabled +camel.main.loadHealthChecks +camel.main.loadStatisticsEnabled +camel.main.loadTypeConverters +camel.main.logDebugMaxChars +camel.main.logExhaustedMessageBody +camel.main.logLanguage +camel.main.logMask +camel.main.logName +camel.main.mainListenerClasses +camel.main.mainListeners +camel.main.mdcLoggingKeysPattern +camel.main.messageHistory +camel.main.messageSizeEnabled +camel.main.modeline +camel.main.name +camel.main.producerTemplateCacheSize +camel.main.profile +camel.main.routeFilterExcludePattern +camel.main.routeFilterIncludePattern +camel.main.routesBuilderClasses +camel.main.routesBuilders +camel.main.routesCollectorEnabled +camel.main.routesCollectorIgnoreLoadingError +camel.main.routesExcludePattern +camel.main.routesIncludePattern +camel.main.routesReloadDirectory +camel.main.routesReloadDirectoryRecursive +camel.main.routesReloadEnabled +camel.main.routesReloadInterval +camel.main.routesReloadPattern +camel.main.routesReloadRemoveAllRoutes +camel.main.routesReloadRestartDuration +camel.main.shutdownLogInflightExchangesOnTimeout +camel.main.shutdownNowOnTimeout +camel.main.shutdownRoutesInReverseOrder +camel.main.shutdownSuppressLoggingOnTimeout +camel.main.shutdownTimeout +camel.main.sourceLocationEnabled +camel.main.startupRecorder +camel.main.startupRecorderDir +camel.main.startupRecorderDuration +camel.main.startupRecorderMaxDepth +camel.main.startupRecorderProfile +camel.main.startupRecorderRecording +camel.main.startupRecorderRuntimeEnabled +camel.main.startupSummaryLevel +camel.main.streamCachingAllowClasses +camel.main.streamCachingAnySpoolRules +camel.main.streamCachingBufferSize +camel.main.streamCachingDenyClasses +camel.main.streamCachingEnabled +camel.main.streamCachingRemoveSpoolDirectoryWhenStopping +camel.main.streamCachingSpoolCipher +camel.main.streamCachingSpoolDirectory +camel.main.streamCachingSpoolEnabled +camel.main.streamCachingSpoolRules +camel.main.streamCachingSpoolThreshold +camel.main.streamCachingSpoolUsedHeapMemoryLimit +camel.main.streamCachingSpoolUsedHeapMemoryThreshold +camel.main.streamCachingStatisticsEnabled +camel.main.threadNamePattern +camel.main.tracing +camel.main.tracingLoggingFormat +camel.main.tracingPattern +camel.main.tracingStandby +camel.main.tracingTemplates +camel.main.typeConverterStatisticsEnabled +camel.main.useBreadcrumb +camel.main.useDataType +camel.main.useMdcLogging +camel.main.uuidGenerator +camel.main.virtualThreadsEnabled +camel.main.yamlDslCompactNotationWarn +camel.management.authenticationEnabled +camel.management.authenticationPath +camel.management.authenticationRealm +camel.management.basicPropertiesFile +camel.management.devConsoleEnabled +camel.management.downloadEnabled +camel.management.enabled +camel.management.healthCheckEnabled +camel.management.healthPath +camel.management.host +camel.management.infoEnabled +camel.management.infoPath +camel.management.jolokiaEnabled +camel.management.jolokiaPath +camel.management.jwtAllowMissingIssuerAndAudience +camel.management.jwtAudience +camel.management.jwtIssuer +camel.management.jwtKeystorePassword +camel.management.jwtKeystorePath +camel.management.jwtKeystoreType +camel.management.mcpEnabled +camel.management.mcpPath +camel.management.metricsEnabled +camel.management.openapiUiEnabled +camel.management.openapiUiSpecPath +camel.management.path +camel.management.port +camel.management.sendEnabled +camel.management.uploadEnabled +camel.management.uploadSourceDir +camel.management.useGlobalSslContextParameters +camel.mdc.customExchangeHeaders +camel.mdc.customExchangeProperties +camel.mdc.enabled +camel.metrics.baseEndpointURIExchangeEventNotifier +camel.metrics.binders +camel.metrics.clearOnReload +camel.metrics.enableExchangeEventNotifier +camel.metrics.enableInstrumentedThreadPoolFactory +camel.metrics.enableMessageHistory +camel.metrics.enableRouteEventNotifier +camel.metrics.enableRoutePolicy +camel.metrics.enabled +camel.metrics.logMetricsOnShutdown +camel.metrics.logMetricsOnShutdownFilters +camel.metrics.logMetricsOnShutdownFormat +camel.metrics.namingStrategy +camel.metrics.path +camel.metrics.recordLastExchangeTimestamp +camel.metrics.routePolicyLevel +camel.metrics.skipCamelInfo +camel.metrics.textFormatVersion +camel.opentelemetry.enabled +camel.opentelemetry.encoding +camel.opentelemetry.excludePatterns +camel.opentelemetry.instrumentationName +camel.opentelemetry.traceProcessors +camel.opentelemetry2.enabled +camel.opentelemetry2.encoding +camel.opentelemetry2.excludePatterns +camel.opentelemetry2.includePatterns +camel.opentelemetry2.instrumentationName +camel.opentelemetry2.traceProcessors +camel.resilience4j.asynchronous +camel.resilience4j.automaticTransitionFromOpenToHalfOpenEnabled +camel.resilience4j.bulkheadEnabled +camel.resilience4j.bulkheadFairCallHandlingEnabled +camel.resilience4j.bulkheadMaxConcurrentCalls +camel.resilience4j.bulkheadMaxWaitDuration +camel.resilience4j.circuitBreaker +camel.resilience4j.config +camel.resilience4j.failureRateThreshold +camel.resilience4j.maxWaitDurationInHalfOpenState +camel.resilience4j.micrometerEnabled +camel.resilience4j.minimumNumberOfCalls +camel.resilience4j.permittedNumberOfCallsInHalfOpenState +camel.resilience4j.slidingWindowSize +camel.resilience4j.slidingWindowSynchronizationStrategy +camel.resilience4j.slidingWindowType +camel.resilience4j.slowCallDurationThreshold +camel.resilience4j.slowCallRateThreshold +camel.resilience4j.throwExceptionWhenHalfOpenOrOpenState +camel.resilience4j.timeoutCancelRunningFuture +camel.resilience4j.timeoutDuration +camel.resilience4j.timeoutEnabled +camel.resilience4j.timeoutExecutorService +camel.resilience4j.waitDurationInOpenState +camel.resilience4j.writableStackTraceEnabled +camel.rest.apiComponent +camel.rest.apiContextPath +camel.rest.apiContextRouteId +camel.rest.apiHost +camel.rest.apiProperties +camel.rest.apiVendorExtension +camel.rest.bindingMode +camel.rest.bindingPackageScan +camel.rest.clientRequestValidation +camel.rest.clientResponseValidation +camel.rest.component +camel.rest.componentProperties +camel.rest.consumerProperties +camel.rest.contextPath +camel.rest.corsHeaders +camel.rest.dataFormatProperties +camel.rest.enableCORS +camel.rest.enableNoContentResponse +camel.rest.endpointProperties +camel.rest.host +camel.rest.hostNameResolver +camel.rest.inlineRoutes +camel.rest.jsonDataFormat +camel.rest.port +camel.rest.producerApiDoc +camel.rest.producerComponent +camel.rest.scheme +camel.rest.skipBindingOnErrorCode +camel.rest.useXForwardHeaders +camel.rest.validationLevels +camel.rest.xmlDataFormat +camel.routecontroller.backOffDelay +camel.routecontroller.backOffMaxAttempts +camel.routecontroller.backOffMaxDelay +camel.routecontroller.backOffMaxElapsedTime +camel.routecontroller.backOffMultiplier +camel.routecontroller.enabled +camel.routecontroller.excludeRoutes +camel.routecontroller.includeRoutes +camel.routecontroller.initialDelay +camel.routecontroller.threadPoolSize +camel.routecontroller.unhealthyOnExhausted +camel.routecontroller.unhealthyOnRestarting +camel.sanitizer.checks +camel.sanitizer.enabled +camel.sanitizer.pendingTimeout +camel.sanitizer.reportOnShutdown +camel.sanitizer.stackDepth +camel.security.allowedProperties +camel.security.insecureDevPolicy +camel.security.insecureSerializationPolicy +camel.security.insecureSslPolicy +camel.security.policy +camel.security.secretPolicy +camel.server.authenticationEnabled +camel.server.authenticationPath +camel.server.authenticationRealm +camel.server.basicPropertiesFile +camel.server.enabled +camel.server.fileUploadDirectory +camel.server.fileUploadEnabled +camel.server.host +camel.server.jwtAllowMissingIssuerAndAudience +camel.server.jwtAudience +camel.server.jwtIssuer +camel.server.jwtKeystorePassword +camel.server.jwtKeystorePath +camel.server.jwtKeystoreType +camel.server.maxBodySize +camel.server.mcpAllowedHosts +camel.server.mcpAllowedOrigins +camel.server.mcpEnabled +camel.server.mcpInstructions +camel.server.mcpOauthProfile +camel.server.mcpPath +camel.server.mcpPromptTimeout +camel.server.mcpRequiredScopes +camel.server.mcpResourceTimeout +camel.server.mcpResourceUri +camel.server.mcpServerDescription +camel.server.mcpServerIcons +camel.server.mcpServerName +camel.server.mcpServerTitle +camel.server.mcpServerWebsiteUrl +camel.server.mcpSessionIdleTtl +camel.server.mcpSessionKeepAliveInterval +camel.server.mcpTags +camel.server.mcpToolTimeout +camel.server.mcpTransport +camel.server.path +camel.server.port +camel.server.staticContextPath +camel.server.staticEnabled +camel.server.staticSourceDir +camel.server.useGlobalSslContextParameters +camel.ssl.certAlias +camel.ssl.cipherSuites +camel.ssl.cipherSuitesExclude +camel.ssl.cipherSuitesInclude +camel.ssl.clientAuthentication +camel.ssl.enabled +camel.ssl.keyManagerAlgorithm +camel.ssl.keyManagerProvider +camel.ssl.keyStore +camel.ssl.keyStoreProvider +camel.ssl.keyStoreType +camel.ssl.keystorePassword +camel.ssl.namedGroups +camel.ssl.namedGroupsExclude +camel.ssl.namedGroupsInclude +camel.ssl.provider +camel.ssl.secureRandomAlgorithm +camel.ssl.secureRandomProvider +camel.ssl.secureSocketProtocol +camel.ssl.selfSigned +camel.ssl.selfSignedKeyType +camel.ssl.sessionTimeout +camel.ssl.signatureSchemes +camel.ssl.signatureSchemesExclude +camel.ssl.signatureSchemesInclude +camel.ssl.trustAllCertificates +camel.ssl.trustStore +camel.ssl.trustStorePassword +camel.startupcondition.customClassNames +camel.startupcondition.enabled +camel.startupcondition.environmentVariableExists +camel.startupcondition.fileExists +camel.startupcondition.interval +camel.startupcondition.onTimeout +camel.startupcondition.timeout +camel.telemetryDev.enabled +camel.telemetryDev.excludePatterns +camel.telemetryDev.includePatterns +camel.telemetryDev.traceFormat +camel.telemetryDev.traceProcessors +camel.threadpool.allowCoreThreadTimeOut +camel.threadpool.config +camel.threadpool.keepAliveTime +camel.threadpool.maxPoolSize +camel.threadpool.maxQueueSize +camel.threadpool.poolSize +camel.threadpool.rejectedPolicy +camel.threadpool.timeUnit +camel.trace.backlogSize +camel.trace.bodyIncludeFiles +camel.trace.bodyIncludeStreams +camel.trace.bodyMaxChars +camel.trace.enabled +camel.trace.includeException +camel.trace.includeExchangeProperties +camel.trace.includeExchangeVariables +camel.trace.removeOnDump +camel.trace.standby +camel.trace.traceFilter +camel.trace.tracePattern +camel.trace.traceRests +camel.trace.traceTemplates +camel.vault.aws.accessKey +camel.vault.aws.defaultCredentialsProvider +camel.vault.aws.overrideEndpoint +camel.vault.aws.profileCredentialsProvider +camel.vault.aws.profileName +camel.vault.aws.refreshEnabled +camel.vault.aws.refreshPeriod +camel.vault.aws.region +camel.vault.aws.secretKey +camel.vault.aws.secrets +camel.vault.aws.sqsQueueUrl +camel.vault.aws.uriEndpointOverride +camel.vault.aws.useSqsNotification +camel.vault.azure.azureIdentityEnabled +camel.vault.azure.blobAccessKey +camel.vault.azure.blobAccountName +camel.vault.azure.blobContainerName +camel.vault.azure.clientId +camel.vault.azure.clientSecret +camel.vault.azure.eventhubConnectionString +camel.vault.azure.refreshEnabled +camel.vault.azure.refreshPeriod +camel.vault.azure.secrets +camel.vault.azure.tenantId +camel.vault.azure.vaultName +camel.vault.cyberark.account +camel.vault.cyberark.apiKey +camel.vault.cyberark.authToken +camel.vault.cyberark.certificatePath +camel.vault.cyberark.password +camel.vault.cyberark.secrets +camel.vault.cyberark.url +camel.vault.cyberark.username +camel.vault.cyberark.verifySsl +camel.vault.gcp.projectId +camel.vault.gcp.refreshEnabled +camel.vault.gcp.refreshPeriod +camel.vault.gcp.secrets +camel.vault.gcp.serviceAccountKey +camel.vault.gcp.subscriptionName +camel.vault.gcp.useDefaultInstance +camel.vault.hashicorp.authMountPath +camel.vault.hashicorp.authentication +camel.vault.hashicorp.awsIamServerId +camel.vault.hashicorp.awsRegion +camel.vault.hashicorp.awsStsEndpoint +camel.vault.hashicorp.azureClientId +camel.vault.hashicorp.azureResource +camel.vault.hashicorp.cloud +camel.vault.hashicorp.host +camel.vault.hashicorp.jwt +camel.vault.hashicorp.jwtFile +camel.vault.hashicorp.keyStore +camel.vault.hashicorp.keyStorePassword +camel.vault.hashicorp.namespace +camel.vault.hashicorp.port +camel.vault.hashicorp.refreshEnabled +camel.vault.hashicorp.refreshPeriod +camel.vault.hashicorp.role +camel.vault.hashicorp.roleId +camel.vault.hashicorp.scheme +camel.vault.hashicorp.secretId +camel.vault.hashicorp.secrets +camel.vault.hashicorp.token +camel.vault.hashicorp.trustStore +camel.vault.hashicorp.trustStorePassword +camel.vault.ibm.eventStreamBootstrapServers +camel.vault.ibm.eventStreamConsumerPollTimeout +camel.vault.ibm.eventStreamGroupId +camel.vault.ibm.eventStreamPassword +camel.vault.ibm.eventStreamTopic +camel.vault.ibm.eventStreamUsername +camel.vault.ibm.refreshEnabled +camel.vault.ibm.secrets +camel.vault.ibm.serviceUrl +camel.vault.ibm.token +camel.vault.kubernetes.refreshEnabled +camel.vault.kubernetes.secrets +camel.vault.kubernetescm.configmaps +camel.vault.kubernetescm.refreshEnabled +camel.vault.springConfig.label +camel.vault.springConfig.password +camel.vault.springConfig.profile +camel.vault.springConfig.refreshEnabled +camel.vault.springConfig.refreshPeriod +camel.vault.springConfig.token +camel.vault.springConfig.uris +camel.vault.springConfig.username diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java b/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java index b2b8f73096df..6c79ea6b51f9 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainHelper.java @@ -137,8 +137,7 @@ public final class MainHelper { LOG.trace("Skipping Kubernetes Service OS environment variable: {}", k); } else { if (k.startsWith(pk) || k.startsWith(pk2)) { - String key = k.toLowerCase(Locale.US).replace('_', '.'); - answer.put(key, v); + answer.put(envVariableToKey(k), v); } } }); @@ -147,6 +146,68 @@ public final class MainHelper { return answer; } + /** + * The configuration key for an OS environment variable. A variable that matches the key of a camel-main option when + * underscores are ignored is mapped to that key, so the underscores between the words of an option are optional + * ({@code CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY} and {@code CAMEL_VAULT_GCP_SERVICEACCOUNTKEY} are both + * {@code camel.vault.gcp.serviceaccountkey}). Any other variable has each underscore turned into a dot. + * + * @param name the name of the environment variable + * @return the configuration key, in lower case + */ + static String envVariableToKey(String name) { + String key = MainOptionKeys.KEYS.get(normalizeEnvName(name)); + if (key != null) { + return key; + } + return name.toLowerCase(Locale.US).replace('_', '.'); + } + + private static String normalizeEnvName(String name) { + StringBuilder sb = new StringBuilder(name.length()); + for (int i = 0; i < name.length(); i++) { + char ch = name.charAt(i); + if (ch != '_' && ch != '.' && ch != '-') { + sb.append(Character.toUpperCase(ch)); + } + } + return sb.toString(); + } + + /** + * The keys of the camel-main options (in lower case), by their name without dots, dashes and underscores in upper + * case. Loaded only when an OS environment variable is mapped to a configuration key. + */ + private static final class MainOptionKeys { + private static final Map<String, String> KEYS = load(); + + private static Map<String, String> load() { + Map<String, String> answer = new HashMap<>(); + Set<String> ambiguous = new HashSet<>(); + try (InputStream is = MainHelper.class.getResourceAsStream("/org/apache/camel/main/main-options.properties")) { + if (is == null) { + return answer; + } + for (String line : IOHelper.loadText(is).split("\n")) { + String key = line.trim(); + if (key.isEmpty() || key.startsWith("#")) { + continue; + } + String name = normalizeEnvName(key); + String existing = answer.put(name, key.toLowerCase(Locale.US)); + if (existing != null && !existing.equals(key.toLowerCase(Locale.US))) { + ambiguous.add(name); + } + } + } catch (IOException e) { + LOG.debug("Cannot load the camel-main option keys due to: {}. This exception is ignored.", e.getMessage(), e); + } + // two options that differ only by dots, dashes or underscores keep the default mapping + ambiguous.forEach(answer::remove); + return answer; + } + } + public static Map<String, String> filterEnvVariables(String[] prefixes) { Map<String, String> answer = new HashMap<>(); System.getenv().forEach((k, v) -> { diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainEnvVarUnderscoreOptionTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainEnvVarUnderscoreOptionTest.java new file mode 100644 index 000000000000..045d48bdad16 --- /dev/null +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainEnvVarUnderscoreOptionTest.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.main; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.vault.GcpVaultConfiguration; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.api.parallel.Isolated; +import org.junit.jupiter.api.parallel.ResourceLock; +import org.junit.jupiter.api.parallel.Resources; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * The OS environment variables of camel-main options can have underscores between the words of an option, such as the + * {@code CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY} variable that the GCP vault documents. + */ +@Isolated +@ResourceLock(Resources.SYSTEM_PROPERTIES) +@DisabledOnOs(OS.WINDOWS) +public class MainEnvVarUnderscoreOptionTest { + + private final Map<String, String> previous = new HashMap<>(); + + @Test + public void testVaultAndMainOptionsWithUnderscoresBetweenWords() { + setEnv("CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", "file:/etc/gcp/sa.json"); + setEnv("CAMEL_VAULT_GCP_PROJECT_ID", "myproject"); + setEnv("CAMEL_MAIN_SHUTDOWN_TIMEOUT", "7"); + + Main main = new Main(); + main.start(); + try { + GcpVaultConfiguration gcp = main.getCamelContext().getVaultConfiguration().gcp(); + assertEquals("file:/etc/gcp/sa.json", gcp.getServiceAccountKey()); + assertEquals("myproject", gcp.getProjectId()); + assertEquals(7, main.configure().getShutdownTimeout()); + } finally { + main.stop(); + } + } + + @AfterEach + void tearDown() { + Map<String, String> env = getEditableEnv(); + previous.forEach((k, v) -> { + if (v != null) { + env.put(k, v); + } else { + env.remove(k); + } + }); + } + + private void setEnv(String name, String value) { + Map<String, String> env = getEditableEnv(); + previous.put(name, env.get(name)); + env.put(name, value); + } + + private static Map<String, String> getEditableEnv() { + Class<?> classOfMap = System.getenv().getClass(); + try { + Field field = classOfMap.getDeclaredField("m"); + field.setAccessible(true); + @SuppressWarnings("unchecked") + Map<String, String> m = (Map<String, String>) field.get(System.getenv()); + return m; + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException("Cannot access System.getenv() map", e); + } + } +} diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainHelperTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainHelperTest.java index d073f74dfda1..3d9d0745451e 100644 --- a/core/camel-main/src/test/java/org/apache/camel/main/MainHelperTest.java +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainHelperTest.java @@ -199,4 +199,25 @@ class MainHelperTest { Assertions.assertEquals("false", prop.getProperty("camel.language.exchangeProperty.trim")); } + @Test + void testEnvVariableToKeyWithUnderscoresBetweenWords() { + // the underscores between the words of an option are optional + Assertions.assertEquals("camel.vault.gcp.serviceaccountkey", + MainHelper.envVariableToKey("CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY")); + Assertions.assertEquals("camel.vault.gcp.serviceaccountkey", + MainHelper.envVariableToKey("CAMEL_VAULT_GCP_SERVICEACCOUNTKEY")); + Assertions.assertEquals("camel.vault.gcp.projectid", MainHelper.envVariableToKey("CAMEL_VAULT_GCP_PROJECT_ID")); + Assertions.assertEquals("camel.vault.ibm.eventstreambootstrapservers", + MainHelper.envVariableToKey("CAMEL_VAULT_IBM_EVENTSTREAM_BOOTSTRAP_SERVERS")); + Assertions.assertEquals("camel.main.shutdowntimeout", MainHelper.envVariableToKey("CAMEL_MAIN_SHUTDOWN_TIMEOUT")); + Assertions.assertEquals("camel.main.shutdowntimeout", MainHelper.envVariableToKey("CAMEL_MAIN_SHUTDOWNTIMEOUT")); + // a key with a dash (camel.cluster.jgroups-raft) + Assertions.assertEquals("camel.cluster.jgroups-raft.enabled", + MainHelper.envVariableToKey("CAMEL_CLUSTER_JGROUPS_RAFT_ENABLED")); + // a variable that is not a camel-main option keeps the mapping of each underscore to a dot + Assertions.assertEquals("camel.beans.mybean.name", MainHelper.envVariableToKey("CAMEL_BEANS_MYBEAN_NAME")); + Assertions.assertEquals("camel.vault.gcp.unknown.option", + MainHelper.envVariableToKey("CAMEL_VAULT_GCP_UNKNOWN_OPTION")); + } + } diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index 9e397bf219ab..0cfbd6ccdf97 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -1413,6 +1413,18 @@ consumer cache of a consumer template evicts the polling consumer (see `maximumC queue is still returned. A polling consumer that was never started still waits for a message, as before. A caller that loops on `receive()` should stop on a `null` result. +=== camel-main - OS environment variables can have underscores between the words of an option + +An OS environment variable for a camel-main option can now have underscores between the words of the option name. For +example, `CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY` and `CAMEL_VAULT_GCP_SERVICEACCOUNTKEY` both set +`camel.vault.gcp.serviceAccountKey`, and `CAMEL_MAIN_SHUTDOWN_TIMEOUT` sets `camel.main.shutdownTimeout`. This is how the +`CAMEL_COMPONENT_*` variables already work. + +Before, each underscore was turned into a dot. The variables that the vault components document, such as +`CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY`, `CAMEL_VAULT_AWS_ACCESS_KEY` or `CAMEL_VAULT_AZURE_TENANT_ID`, failed the startup +of a Camel Main application with `Cannot find getter method`. They now configure the matching `camel.vault.*` option. +A variable that matches no camel-main option keeps the old mapping. + === camel-main - a failure to start is logged A Camel Main application that fails to start now logs why, at ERROR: `Error starting Camel: ...` with the stack trace, diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java index d14914a62f02..68b375b0e5aa 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java @@ -631,6 +631,12 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo { String json = JsonMapper.createJsonSchema(model); updateResource(outFolder.toPath(), "META-INF/camel-main-configuration-metadata.json", json); + + // the option keys, one per line, which camel-main uses to map an OS environment variable with underscores + // between the words of an option (such as CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY) to its key + String keys = model.getOptions().stream().map(MainModel.MainOptionModel::getName).sorted() + .collect(Collectors.joining("\n", "", "\n")); + updateResource(outFolder.toPath(), "org/apache/camel/main/main-options.properties", keys); } }
