micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.07k stars 1.07k forks source link

Object Storage doesn't work with environment variables #10726

Open burtbeckwith opened 6 months ago

burtbeckwith commented 6 months ago

Expected Behavior

I should be able to specify object storage properties as env vars, e.g. MICRONAUT_OBJECT_STORAGE_ORACLE_CLOUD_DEFAULT_BUCKET for micronaut.object-storage.oracle-cloud.default.bucket and MICRONAUT_OBJECT_STORAGE_ORACLE_CLOUD_DEFAULT_NAMESPACE for micronaut.object-storage.oracle-cloud.default.namespace

Actual Behaviour

Values are only resolved from config files.

I discussed this with Alvaro and although this affects Object Storage, it's likely a core bug.

Steps To Reproduce

Create an app

mn create-app --build=gradle --features=object-storage-oracle-cloud com.example.objstoragebug

Add printlns to Application.java to display resolved values (see attached project)

Specify bucket and namespace as env vars, either with

export MICRONAUT_OBJECT_STORAGE_ORACLE_CLOUD_DEFAULT_BUCKET=foo
export MICRONAUT_OBJECT_STORAGE_ORACLE_CLOUD_DEFAULT_NAMESPACE=bar
./gradlew run

or

MICRONAUT_OBJECT_STORAGE_ORACLE_CLOUD_DEFAULT_BUCKET=foo MICRONAUT_OBJECT_STORAGE_ORACLE_CLOUD_DEFAULT_NAMESPACE=bar ./gradlew run

In both cases the properties are correctly read and available from the ApplicationContext, but there is no enabled ObjectStorageOperations bean (should be io.micronaut.objectstorage.oraclecloud.OracleCloudStorageOperations)

If you hard code the values in application.properties, or in application-foo.properties and run with the "foo" env enabled, it works.

One other weird combination works. If I specify env vars and have one or more related properties in application.properties, it works. Uncomment

micronaut.object-storage.oracle-cloud.default.enabled=true

in application.properties in the attached app and run with env vars and everything works as expected. Note that any of the 3 properties will cause this, it's not related to the value being true since the default is true.

Environment Information

No response

Example Application

No response

Version

4.3.8

burtbeckwith commented 6 months ago

objstoragebug.zip