示例#1
0
 public static BitGoUserNoSqlEntity Create(BitGoUser user)
 {
     return(new BitGoUserNoSqlEntity
     {
         PartitionKey = GeneratePartitionKey(user.BrokerId),
         RowKey = GenerateRowKey(user.Id, user.CoinId),
         User = user
     });
 }
示例#2
0
        private async Task SetUserId(BitGoUser user)
        {
            var client      = _bitGoClientService.GetByUser(user.BrokerId, user.Id, user.CoinId, user.ApiKey);
            var userDetails = await client.GetUserAsync("me");

            if (!userDetails.Success)
            {
                _logger.LogError("Cannot add BitGo user: {requestJson}. Error: {error}",
                                 JsonConvert.SerializeObject(user, new ApiKeyHiddenJsonConverter(typeof(BitGoUser))),
                                 JsonConvert.SerializeObject(userDetails.Error));
            }

            user.BitGoId = userDetails.Data.User.UserId;
        }
示例#3
0
 private static void ValidateUser(BitGoUser user)
 {
     if (string.IsNullOrEmpty(user.BrokerId))
     {
         throw new Exception("Cannot add user with empty broker");
     }
     if (string.IsNullOrEmpty(user.Id))
     {
         throw new Exception("Cannot add user with empty id");
     }
     if (string.IsNullOrEmpty(user.BitGoId))
     {
         throw new Exception("Cannot add user with empty BitGoId");
     }
 }
示例#4
0
        public void HideApiKey()
        {
            var data = new BitGoUser()
            {
                Id           = "UserId",
                ApiKey       = "TestApiKey",
                BrokerId     = "Broker",
                RegisterDate = DateTime.Now,
                UpdatedBy    = "Test",
                UpdatedDate  = DateTime.Now,
                BitGoId      = "BitGoId"
            };

            string json = JsonConvert.SerializeObject(data, new ApiKeyHiddenJsonConverter(typeof(BitGoUser)));

            Console.WriteLine(json);
            Assert.False(json.Contains("TestApiKey"));
        }
示例#5
0
        public async Task UpdateBitGoUser(BitGoUser user)
        {
            using var action = MyTelemetry.StartActivity("Update BitGo user");
            try
            {
                _logger.LogInformation("Update BitGoUser: {jsonText}",
                                       JsonConvert.SerializeObject(user, new ApiKeyHiddenJsonConverter(typeof(BitGoUser))));

                user.UpdatedDate = DateTime.Now;
                await SetUserId(user);

                user.ApiKey = _encryptionService.Encrypt(user.ApiKey);

                ValidateUser(user);

                var entity = BitGoUserNoSqlEntity.Create(user);

                var existingItem = await _writer.GetAsync(entity.PartitionKey, entity.RowKey);

                if (existingItem == null)
                {
                    throw new Exception("Cannot update BitGo user. Do not exist");
                }

                await _writer.InsertOrReplaceAsync(entity);

                _logger.LogInformation("Updated BitGo user: {jsonText}",
                                       JsonConvert.SerializeObject(user, new ApiKeyHiddenJsonConverter(typeof(BitGoUser))));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Cannot update BitGo user: {requestJson}",
                                 JsonConvert.SerializeObject(user, new ApiKeyHiddenJsonConverter(typeof(BitGoUser))));
                ex.FailActivity();
                throw;
            }
        }