/// <summary> /// Create an Instance of a CredentialService /// </summary> /// <param name="dragonchainId">dragonchainId associated with these credentials</param> /// <param name="authKey">authKey to use with these credentials</param> /// <param name="authKeyId">authKeyId to use with these credentials</param> /// <param name="hmacAlgo">hmac algorithm to use</param> /// <param name="credentialManager">manager to retrieve Dragonchain credentials from config provider</param> /// <param name="logger"></param> public CredentialService(string dragonchainId, string authKey = "", string authKeyId = "", HmacAlgorithm hmacAlgo = HmacAlgorithm.SHA256, ICredentialManager credentialManager = null, ILogger <DragonchainClient> logger = null) { _logger = logger ?? new NullLogger <DragonchainClient>(); DragonchainId = dragonchainId; if (!string.IsNullOrWhiteSpace(authKey) && !string.IsNullOrWhiteSpace(authKeyId)) { _logger.LogDebug("Auth Key/Id provided explicitly, will not search env/disk"); _credentials = new DragonchainCredentials { AuthKey = authKey, AuthKeyId = authKeyId }; } else { try { _credentials = credentialManager.GetDragonchainCredentials(dragonchainId); } catch { // don't require credentials to be present on construction _credentials = new DragonchainCredentials { AuthKey = string.Empty, AuthKeyId = string.Empty }; } } _hmacAlgo = hmacAlgo; }
/// <summary> /// Manually override the credentials for this instance /// </summary> public void OverrideCredentials(string authKeyId, string authKey) { _credentials = new DragonchainCredentials { AuthKey = authKey, AuthKeyId = authKeyId }; }