public static DiscoverySessionInfo GenerateDiscoverySession(AwsAccount acc)
 {
     return(new DiscoverySessionInfo
     {
         AwsAccountId = acc.Id,
         Dependencies = GenerateDependencyFindings(),
         DiscoveryReports = GenerateDependencyReports().ToArray()
     });
 }
示例#2
0
        public void DbContext_Insert_CreatesAudit()
        {
            var(audits, dm) = GetUnitsOfWork();

            var acc = new AwsAccount {
                Name = "foo"
            };

            dm.AwsAccounts.Insert(acc, true);

            var audit = audits.GetAll().Last();

            Assert.AreEqual(FixedDateTimeProvider.DateTime, audit.Date);
            Assert.AreEqual(DefaultUserProvider.UserId, audit.UserId);
            Assert.AreEqual(typeof(AwsAccount).Name, audit.EntityName);
            Assert.IsNull(audit.OldValue);
            Assert.AreEqual($"\"Id\":{acc.Id},\"Name\":\"foo\"", audit.NewValue);
        }
        public async Task <IActionResult> TestAccount(CloudAccountModel account)
        {
            try
            {
                ICloudAccount cloudAccount = null;

                switch (account.AccountType)
                {
                case CloudAccountType.Aws: cloudAccount = new AwsAccount(account.AwsRoleArn, account.AwsExternalId, null); break;

                case CloudAccountType.Azure: cloudAccount = new AzureAccount(account.AzureSubscriptionId, account.AzureTenantId, account.AzureClientId, account.AzureClientSecret); break;

                case CloudAccountType.GoogleCloud:
                    ValidateModelForGoogleCloud(account.GcJsonBody); cloudAccount = new GoogleCloudAccount(account.GcJsonBody, account.GcProjectId, null); break;
                }

                if (cloudAccount != null)
                {
                    var creds = await cloudAccount.GetTemporaryCredentials <dynamic>();

                    if (creds?.CredentialObject == null)
                    {
                        throw new Exception("Sorry! We could not connect to your cloud service provider. Please check your details and try again.");
                    }
                    return(Ok());
                }

                return(Unauthorized(new { Message = "The Account Type  value is not valid." }));
            }
            catch (Exception ex)
            {
                return(Unauthorized(new
                {
                    Message = ex.Message
                }));
            }
        }
        public async Task <AwsAccount> GetOrCreateAwsAccountAsync(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(nameof(name));
            }

            var awsAccount = (await _context.AwsAccounts.FindAllAsync(x => x.Name == name)).SingleOrDefault();

            if (awsAccount != null)
            {
                return(awsAccount);
            }

            var newAcc = new AwsAccount {
                Name = name
            };

            await _context.AwsAccounts.InsertAsync(newAcc);

            await _context.AwsAccounts.CommitAsync();

            return(newAcc);
        }