public async Task RemoveBitGoUser(RemoveBitGoUserRequest request) { using var action = MyTelemetry.StartActivity("Remove BitGo user"); request.AddToActivityAsJsonTag("request"); try { _logger.LogInformation("Remove BitGo user: {jsonText}", JsonConvert.SerializeObject(request)); var entity = await _writer.DeleteAsync(BitGoUserNoSqlEntity.GeneratePartitionKey(request.BrokerId), BitGoUserNoSqlEntity.GenerateRowKey(request.UserId, request.CoinId)); if (entity != null) { _logger.LogInformation("Removed BitGo user: {jsonText}", JsonConvert.SerializeObject(entity, new ApiKeyHiddenJsonConverter(typeof(BitGoUser)))); } else { _logger.LogInformation("Unable to remove BitGo user, do not exist: {jsonText}", JsonConvert.SerializeObject(request)); } } catch (Exception ex) { _logger.LogError(ex, "Cannot remove BitGo user: {requestJson}", JsonConvert.SerializeObject(request)); ex.FailActivity(); throw; } }
public async Task <BitGoUser> GetBitGoUser(GetBitGoUserRequest request) { var user = (await _writer.GetAsync(BitGoUserNoSqlEntity.GeneratePartitionKey(request.BrokerId), BitGoUserNoSqlEntity.GenerateRowKey(request.UserId, request.CoinId))).User; if (user != null) { user.ApiKey = "***"; } return(user); }
public IBitGoApi GetByUser(string brokerId, string userId, string coinId, string newApiKey) { var bitGoUser = _bitgoUserReader.Get( BitGoUserNoSqlEntity.GeneratePartitionKey(brokerId), BitGoUserNoSqlEntity.GenerateRowKey(BitGoUserNoSqlEntity.TechSignerId, coinId)) ?? _bitgoUserReader.Get( BitGoUserNoSqlEntity.GeneratePartitionKey(brokerId), BitGoUserNoSqlEntity.GenerateRowKey(BitGoUserNoSqlEntity.TechSignerId, BitGoUserNoSqlEntity.DefaultCoin)); var apiKeyEnc = bitGoUser?.User?.ApiKey; if (string.IsNullOrEmpty(apiKeyEnc) && string.IsNullOrEmpty(newApiKey)) { _logger.LogError("Tech account is not configured, id = {techSignerName}", BitGoUserNoSqlEntity.TechSignerId); return(null); } lock (_clients) { if (!string.IsNullOrEmpty(apiKeyEnc) && _clients.TryGetValue(apiKeyEnc, out var api)) { return(api); } } var coin = _bitgoCointReader.Get(BitgoCoinEntity.GeneratePartitionKey(), BitgoCoinEntity.GenerateRowKey(coinId)); if (coin == null) { _logger.LogError("Cannot fond bitgo coin id = {symbol}", coinId); return(null); } var apiKey = string.IsNullOrEmpty(apiKeyEnc) ? newApiKey : _encryptionService.Decrypt(apiKeyEnc); var client = new BitGoClient( apiKey, Program.Settings.BitgoExpressUrlMainNet, apiKey, Program.Settings.BitgoExpressUrlTestNet); lock (_clients) { _clients[apiKey] = coin.IsMainNet ? client.MainNet : client.TestNet; return(_clients[apiKey]); } }