components-contrib icon indicating copy to clipboard operation
components-contrib copied to clipboard

Cosmos State Store - Improve emulator usage - Component configuration

Open perokvist opened this issue 10 months ago • 2 comments

It would be create to either set more meta data, emulator mode, OR support connection strings.

When using the Aspire Cosmos component, I learnt that there are more parameters set through the connection string.

AccountKey=xxx;AccountEndpoint=https://127.0.0.1:65236;DisableServerCertificateValidation=True;

perokvist avatar Apr 26 '24 08:04 perokvist

We use the Cosmos DB Azure SDK for Go. Take a look at their emulator tests: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/data/azcosmos/emulator_tests.go

It appears that simply specifying a host like https://localhost:8903/ end the masterKey (accountKey) for the emulator should work.

That's what the Azure SDK team does. They use this emulator: https://aka.ms/cosmosdb-emulator And here is their script to launch the emulator: https://github.com/Azure/azure-sdk-for-go/blob/84361e7de430729bf174593eba3760b5422359be/eng/common/scripts/Cosmos-Emulator.ps1

The Dapr component lets you specify these properties.

Set the component metadata:

  - name: url
    value: https://localhost:65236
  - name: masterKey
    value: theaccountkey

This Azure SDK for Go does not have an option like DisableServerCertificateValidation

This SDK's method to provide a connection string only can extract accountKey and accountEndpoint from the connection string. So a connectionString option would not give you any additional functionality here. See for yourself:

https://github.com/Azure/azure-sdk-for-go/blob/84361e7de430729bf174593eba3760b5422359be/sdk/data/azcosmos/cosmos_client.go#L81

I believe the Go SDK can already work with the emulator, but given that the Azure SDK for Go does not have any further configuration options, Dapr cannot expand the support for the emulator.

You may consider filing a feature request at https://github.com/Azure/azure-sdk-for-go

berndverst avatar May 01 '24 23:05 berndverst

The scenario I came across was when using the Aspire Cosmos component It uses https://hub.docker.com/r/microsoft/azure-cosmos-emulator-linux as it container for the emulator, that seems to have a certificate or the connectionString setting to work.

I'm guessing this will work with the dapr component if certificates are setup prior to running.

perokvist avatar May 03 '24 10:05 perokvist