About

In the Partner Portal, Keyvault is used to store the credentials used for communicating with the SonWin Client. 

Most of the data related to communication can be maintained in the egadmin page of the application. 

This page descripes how to use the client in the code.

KeyVaultClient

About KeyVaultClient

When one is in need of interacting with teh KeyVault in Partner Portal, this should ALWAYS be done by invoking the KeyVaultClient, either directly or indirectly. 

NEVER make code that does not go through this entity. 

There are two main reasons for using the KeyVaultClient: 

  • Logic is given
    • The KeyVaultClient have logic for interacting witht the keyvault, so that you yourself does not need to create any.
  • Cache
    • The KeyVaultClient have been creted with a memmory cache wich prevents the system from invoking the keyvault multiple times when asking for the same piece of data. 
      This is created this way because the keyvault is payed for pr transaction, and we dont want to pay more than we need. 

How to use the KeyVaultClient

Initialization

The first thing one must do before using the KeyVaultClient is to initialize it. 

From the above, we see that the client needs the following two pieces of information in order to work: 

  • ClientSecretCredentials
    • Credentials consisting of the following:
      • TennantId
      • ClientId
      • ClientSecret
      • Options
  • KeyVaultUri
    • Endpoint of the keyvault in order to communicate with it

The info is usually taken from teh environment variables

Initializing the client could look like this (Look in the :

Using the client

When using the client, one have the following options: 

  • async Task<string> TestConnection()
    Testing if the keyvault can be reached with the given information for connection.
  • async Task<string> GetSecret(string key)
    If a secret with the corresponding key is found, this is returned.
    Be aware that the client will look in the cache for a match before asking keyvault
    If a key is found in the keyvaulkt but not in the cache, the cache will be updated
  • async Task<bool> SetSecret(string key, string secret)
    Update the secret in the keyvault and update cache
  • async Task<bool> KeyExists(string key)
    Return bool indicating if a given key is found
  • async Task<bool> ForceReloadKey(string key)
    When invoked, this method forces the cache to be reloaded regarding the key input. 
    Do NOT use this unless it is nessesary as it will ruin the purpose of the cache itself.
  • No labels