public async Task <IActionResult> GetPassword(string id)
        {
            try
            {
                if (!HttpContext.Request.IsHttps)//if request is not https, then throw unauthorized exception
                {
                    throw new UnauthorizedAccessException("Request must be HTTPS");
                }

                var        credentialId       = new Guid(id);
                Credential existingCredential = _credentialRepository.GetOne(credentialId);

                if (existingCredential == null)
                {
                    throw new EntityDoesNotExistException("No Credential was found for the specified id");
                }

                var passwordString = _credentialManager.GetPassword(existingCredential);

                return(Ok(passwordString));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
        public Credential DeleteCredential(string id)
        {
            var existingCredential = _repo.GetOne(Guid.Parse(id));

            if (existingCredential == null)
            {
                throw new EntityDoesNotExistException("Credential cannot be found or does not exist");
            }

            if (existingCredential.AgentId == null)//credential is a global credential
            {
                var childCredentials = _repo.Find(null, a => a.Name == existingCredential.Name && a.AgentId != null)?.Items;

                if (childCredentials.Count > 0)
                {
                    throw new EntityOperationException("Child credentials exist for this credential, please delete those first");
                }
            }

            return(existingCredential);
        }
Exemplo n.º 3
0
        public AgentViewModel GetAgentDetails(AgentViewModel agentView)
        {
            agentView.UserName       = usersRepo.Find(null, u => u.Name == agentView.Name).Items?.FirstOrDefault()?.UserName;
            agentView.CredentialName = credentialRepo.GetOne(agentView.CredentialId ?? Guid.Empty)?.Name;

            AgentHeartbeat agentHeartBeat = agentHeartbeatRepo.Find(0, 1).Items?.Where(a => a.AgentId == agentView.Id).OrderByDescending(a => a.CreatedOn).FirstOrDefault();

            if (agentHeartBeat != null)
            {
                agentView.LastReportedOn      = agentHeartBeat.LastReportedOn;
                agentView.LastReportedStatus  = agentHeartBeat.LastReportedStatus;
                agentView.LastReportedWork    = agentHeartBeat.LastReportedWork;
                agentView.LastReportedMessage = agentHeartBeat.LastReportedMessage;
                agentView.IsHealthy           = agentHeartBeat.IsHealthy;
            }

            return(agentView);
        }