public async Task <IHttpActionResult> Get(string name)
        {
            try
            {
                var applicationTask       = applicationRepository.GetApplicationAsync(name);
                var activeDeploymentsTask = deploymentRepository.GetActiveDeploymentsAsync(name);
                await Task.WhenAll(applicationTask, activeDeploymentsTask);

                if (applicationTask.Result == null)
                {
                    return(BadRequest("Application " + name + " was not found."));
                }
                var activeDeployments = activeDeploymentsTask.Result;
                if (activeDeployments == null || activeDeployments.Count == 0)
                {
                    return(NotFound());
                }

                var audits = await auditRepository.GetAuditsAsync(activeDeployments.Select(d => d.MostRecentAudit).ToList());

                var response = BuildAuditResponseObject(name, activeDeployments, audits);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                Log.Error("Error in audit controller:", ex);
                return(InternalServerError());
            }
        }
Exemple #2
0
        public async Task <IHttpActionResult> Get(string name, string serverName = null, [FromUri] bool includeInactive = false, [FromUri] bool includeFiles = false)
        {
            try
            {
                var applicationTask       = applicationRepository.GetApplicationAsync(name);
                var activeDeploymentsTask = includeInactive
                    ? deploymentRepository.GetAllDeploymentsAsync(name, serverName)
                    : deploymentRepository.GetActiveDeploymentsAsync(name, serverName);
                await Task.WhenAll(applicationTask, activeDeploymentsTask);

                if (applicationTask.Result == null)
                {
                    return(BadRequest("Application " + name + " was not found."));
                }
                if (activeDeploymentsTask.Result == null)
                {
                    return(NotFound());
                }
                return(Ok(BuildDeploymentResponse(activeDeploymentsTask.Result, name, includeFiles)));
            }
            catch (Exception ex)
            {
                Log.Error("Error in deployment controller:", ex);
                return(InternalServerError());
            }
        }
        private async Task AuditHashApplication(Application application, bool sendAuditEmail = true)
        {
            var activeDeployments = await deploymentRepository.GetActiveDeploymentsAsync(application.Name);

            var failedAudits = new Dictionary <Deployment, DeploymentAudit>();

            foreach (var deployment in activeDeployments)
            {
                var audit = await hashingService.HashDeployment(deployment, application.GetRegularExpressions(), application.HashHiddenFiles, false);

                await auditRepository.CreateAuditAsync(audit);

                if (!audit.ValidHash)
                {
                    failedAudits.Add(deployment, audit);
                }
            }
            if (failedAudits.Count > 0)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("The application {0} has a failed audit on the following servers: \r\n", application.Name);
                foreach (var failedAudit in failedAudits)
                {
                    sb.AppendFormat("Audit UTC:{0},  Server {1}:\r\n", failedAudit.Value.AuditDateTime.ToLongTimeString(), failedAudit.Key.ServerName);
                    foreach (var fileHashMismatch in failedAudit.Value.FileHashMismatches)
                    {
                        sb.AppendFormat("Deployment Hash:{0}, Audit Hash:{1} \r\n", fileHashMismatch.OriginalHash, fileHashMismatch.AuditHash);
                    }
                }

                Log.Error(sb.ToString());
                await mailService.SendAuditEmail("Audit failure for " + application.Name, sb.ToString());
            }
            else
            {
                Log.InfoFormat("All audits passed for application {0}.", application.Name);
            }
        }