question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to set CosmosClientOptions - helpful with local Docker Emulator usage

See original GitHub issue

Is your feature request related to a problem? Please describe. When attempting to use the repository in a containerised application the following error occurs: “System.InvalidOperationException: Cannot create Collection Information for Drivers in database drivers with lease leases in database drivers : The SSL connection could not be established, see inner exception. —> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.”

The lack of configurability is preventing me from using this really useful repository as part of our microservice solution

Describe the solution you’d like Looking at this link it seems we can override certificate config, so the ability pass these options through (or the repo’s own version of) would be a suggestion? https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator?tabs=ssl-netstd21#disable-ssl-validation

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
{
    HttpClientFactory = () =>
    {
        HttpMessageHandler httpMessageHandler = new HttpClientHandler()
        {
            ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
        };

        return new HttpClient(httpMessageHandler);
    },
    ConnectionMode = ConnectionMode.Gateway
};


CosmosClient client = new CosmosClient(endpoint, authKey, cosmosClientOptions);

Additional context Unless there is currently a way of achieving local, containerised development already within the project I’m unaware of, I think solving this problem would open up the repository to another level of software.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
totalitydevelopmentcommented, Nov 2, 2021

@mumby0168 @IEvangelist this is what I ended up with after being able to override the cosmos client options as discussed.

s.AddCosmosRepository(options =>
          {
              ... options setup
          },
          cosmosClientOptions => //todo this absolutely only needs to occur in dev mode!!!
          {
              cosmosClientOptions.HttpClientFactory = () =>
                  {
                      HttpMessageHandler httpMessageHandler = new HttpClientHandler()
                      {
                          ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
                      };
                      return new HttpClient(httpMessageHandler);
                  };

              cosmosClientOptions.ConnectionMode = ConnectionMode.Gateway;
          }
1reaction
totalitydevelopmentcommented, Nov 1, 2021

@mumby0168 we’re using a load of new technologies within the team for a greenfield project. Our first run at a microservice architecture using K8, Docker, Azure Functions and the like. Also a first run with Cosmos and we found ourselves writing a lot of repetitive code. I watched part of the Cosmos Conf and saw @IEvangelist video so dived straight onto it as it saves sooo much repetition in our cosmos related data layer. Great work guys.

@totalitydevelopment we were in a very similar position this has been great for us 👍 Hope all goes well

Likewise, good luck with the project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run the Azure Cosmos DB Emulator on Docker for Linux
This article describes how to install and use the emulator on macOS and Linux environments. Note. The Azure Cosmos DB Linux Emulator is ......
Read more >
How to use V3 CosmosClient with Emulator while ignoring ...
So just to trust the cert locally in my container, am I supposed to generate my own cert that's valid for Cosmos Db...
Read more >
Cosmos with EFCore - can we bypass the SSL check?
I've inspected context.Database.GetCosmosClient() and it appears HttpClientFactory is null, but even if I try to set it there before calling ...
Read more >
Local Dev With CosmosDB and devcontainers - Aaron Powell
Setting up the emulator. The emulator is available as a Docker image, which means it's pretty easy to setup, just pull the image: ......
Read more >
How to create a local test playground for Cosmos Db for .NET ...
You should be able to access it while you Azure Cosmos Db Emulator docker instance is running. You need to open your browser;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found