OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.23k stars 2.34k forks source link

Media.AmazonS3 requires AccessKeyId if NuGet package is used #12570

Open quickstar opened 1 year ago

quickstar commented 1 year ago

Describe the bug

I'm experiencing a very strange behaviour. I'm implementing the OrchardCore.Media.AmazonS3 storage provider. If I clone the OrchardCore repository and create a config entry like this:

"OrchardCore_Media_AmazonS3": {
    "Region": "eu-west-3",
    "Credentials": {
        "SecretKey": "*****",
        "AccessKey": "***"
    },
    "CreateBucket": false,
    "BucketName": "mybucket"
}

everthing seems to work just fine.

If I however create a new decoupledCMS project and add a plain MVC Project and add just the following NuGet packages

  <ItemGroup>
    <PackageReference Include="OrchardCore.Application.Cms.Core.Targets" Version="1.4.0" />
    <PackageReference Include="OrchardCore.Media.AmazonS3" Version="1.4.0" />
  </ItemGroup>

I get the following error message:

OrchardCore.Media.AmazonS3.Startup[0]
      S3 Media configuration validation failed with errors: AccessKeyId is required attribute for S3 Media, make sure it exists in Credentials section or ProfileName you specified fallback to local file storage.
OrchardCore.Media.AmazonS3.Startup: Error: S3 Media configuration validation failed with errors: AccessKeyId is required attribute for S3 Media, make sure it exists in Credentials section or ProfileName you specified fallback to local 
file storage.

Eventhough I use the exact same config as mentioned obove, any ideas what I might missing?

hishamco commented 1 year ago

/cc @neglectedvalue

neglectedvalue commented 1 year ago

Hello seems like the issue is in configuration files in decoupled mode, I was able to reproduce this bug with AWS and Azure modules.

  "OrchardCore": {
  "OrchardCore_Media_Azure":
  {
    "ConnectionString": "1212", 
    "ContainerName": "somecontainer", 
    "BasePath": "some/base/path", 
    "CreateContainer": false 
  }
}
fail: OrchardCore.Media.Azure.Startup[0]
      Azure Media Storage is enabled but not active because the 'ConnectionString' is missing or empty in application configuration.
fail: OrchardCore.Media.Azure.Startup[0]
      Azure Media Storage is enabled but not active because the 'ContainerName' is missing or empty in application configuration.

Upd: So far after small investigation I can say that in decoupled mode Orchard doesn't use appsettings.json of the project but it uses only App_Data\Sites{TenantName}\appsettings.json , is it correct behavior @hishamco ?

hishamco commented 1 year ago

@jtkech your though?

quickstar commented 1 year ago

So far after small investigation I can say that in decoupled mode Orchard doesn't use appsettings.json of the project but it uses only App_Data\Sites{TenantName}\appsettings.json , is it correct behavior @hishamco ?

I guess it does use the appsettings.json from the project, but only partially because the media provider itself is recognized during the bootstrap process.

neglectedvalue commented 1 year ago

I guess it does use the appsettings.json from the project, but only partially because the media provider itself is recognized during the bootstrap process.

What do you mean by media provider itself? If you are talking about S3/Azure media storages - they are using appsettings only to get storage configuration, their bootstrap happens only if you are enabled them in admin->features or created a custom recipe.

hishamco commented 1 year ago

I remember the configuration could came from different sources, but there should be an order and fallback in case one of the configuration provider is missing

quickstar commented 1 year ago

What do you mean by media provider itself? If you are talking about S3/Azure media storages - they are using appsettings only to get storage configuration, their bootstrap happens only if you are enabled them in admin->features or created a custom recipe.

Yes, sorry my bad. Off course you're right 🤦🏽‍♂️

quickstar commented 1 year ago

Is this a general bug then, that in decoupled mode using the NuGet packages, the appsettings.json hierarchy is not respected?

sebastienros commented 1 year ago

Decoupled (not front-end theme, no layout shapes) should have nothing to do with appsettings. Maybe you could debug the source to understand where this makes a difference.

jtkech commented 1 year ago

@quickstar

If you reference OC.Application.Cms.Core.Targets normally you don't need to reference OrchardCore.Media.AmazonS3. Then can you share some code to see how you activate the feature and then in which context you use it.

Piedone commented 1 month ago

Closing due to no reply from the author.

quickstar commented 1 month ago

@Piedone, I didn't answer because I thought it's out of my hand. Since @neglectedvalue was able to reproduce it:

So far after small investigation I can say that in decoupled mode Orchard doesn't use appsettings.json of the project but it uses only App_Data\Sites{TenantName}\appsettings.json , is it correct behavior @hishamco ?

@hishamco and @jtkech should probably decide what the correct behavior should be.

Piedone commented 1 month ago

Please follow up from here: https://github.com/OrchardCMS/OrchardCore/issues/12570#issuecomment-1286202255

JT, sadly, won't help anymore: https://github.com/OrchardCMS/OrchardCore/issues/14954.

quickstar commented 1 month ago

JT, sadly, won't help anymore: https://github.com/OrchardCMS/OrchardCore/issues/14954.

My condolences 🫶

In my opinion, the correct behavior should be as follows:

If a setting is present in both appsettings.json files, the more specific App_Data\Sites\{TenantName}\appsettings.json should take precedence.

Piedone commented 1 month ago

That's what indeed should happen.

What you see is I think less related to NuGet, and should more lie in how the app is initialized (and thus how it loads configuration). Can you share your Program.cs and compare it with the one in OC's OrchardCore.Cms.Web?