public async Task<IActionResult> FullFlow(string user, string password)
        {
            Devon4NetLogger.Debug("Executing FullFlow from controller AnsibleTowerController");
            var token = await AnsibleTowerHandler.Login(user, password);
            var organizations = await AnsibleTowerHandler.GetOrganizations(token.Token);

            // Organizations
            Devon4NetLogger.Debug("Organization count: " + organizations.count);
            if (organizations.results.Length == 0 || organizations.results[0].name != "devapps2")
            {
                return BadRequest();
            }
            var devapps2 = organizations.results[0];

            // Credentials
            var credentialsList = await AnsibleTowerHandler.GetCredentials(token.Token, "fakecredential");
            if (credentialsList.results.Length == 0 || credentialsList.results[0].name != "fakecredential")
            {
                var fakeCredential = new CreateCredentialRequestDto { name = "fakecredential", description = "none", organization = 3, credential_type = 2, inputs = new Dictionary<string, string>(), user = 5 };
                fakeCredential.inputs.Add("username", "fakeuser");
                fakeCredential.inputs.Add("password", "fakepassword");

                var newCredential = await AnsibleTowerHandler.CreateCredential(token.Token, fakeCredential);
            }

            return Ok(await AnsibleTowerHandler.Login(user, password));
        }
示例#2
0
        public async Task <IActionResult> FullFlow(string ansibleUser, string ansiblePassword, string organizationName,
                                                   string credentialName, string credentialDescription, string credentialUserName, string credentialPassword,
                                                   int idOrganization, int idCredentialType, int idUser)
        {
            var result = new StringBuilder();

            Devon4NetLogger.Debug("Executing FullFlow from controller AnsibleTowerController");
            result.AppendLine($"");
            result.AppendLine($"Perform login with the user; {ansibleUser} and password: {ansiblePassword}");
            var token = await AnsibleTowerHandler.Login(ansibleUser, ansiblePassword);

            result.AppendLine($"The user token is: {token.token}");
            var organizations = await AnsibleTowerHandler.GetOrganizations(token.token);

            // Organizations
            Devon4NetLogger.Debug("Organization count: " + organizations.count);
            if (organizations.results != null && organizations.results.Any() && organizations.results.FirstOrDefault()?.name != organizationName)
            {
                return(BadRequest());
            }

            var organization = organizations.results?.FirstOrDefault();

            result.AppendLine($"The retreived organization is: name: {organization?.name}, id: {organization?.id}");

            // Credentials
            var credentialsList = await AnsibleTowerHandler.GetCredentials(token.token, credentialName);

            if (credentialsList?.results != null && credentialsList.results.Any() || credentialsList?.results?.FirstOrDefault()?.name != credentialName)
            {
                result.AppendLine($"The credentials with name {credentialName} has been retreived");
                var credential = new CreateCredentialRequestDto
                {
                    name            = credentialName,
                    description     = credentialDescription,
                    organization    = idOrganization,
                    credential_type = idCredentialType,
                    inputs          = new Dictionary <string, string> {
                        { "username", credentialUserName }, { "password", credentialPassword }
                    },
                    user = idUser
                };
                result.AppendLine($"Storing the credential...");
                var savedCredential = await AnsibleTowerHandler.CreateCredential(token.token, credential);

                result.AppendLine($"The credential has been created in Ansible Tower. id: {savedCredential.id}, name: {savedCredential.name}, created: {savedCredential.created}");
            }
            else
            {
                result.AppendLine($"ERROR! The credentials with name {credentialName} has NOT been retreived");
            }

            return(Ok(result.ToString()));
        }
示例#3
0
 /// <summary>
 /// Creates a Credential object in Ansible Tower
 /// </summary>
 /// <param name="authenticationToken"></param>
 /// <param name="credentialRequest"></param>
 /// <returns></returns>
 public Task <GetCredentialsResponseDto> CreateCredential(string authenticationToken, CreateCredentialRequestDto credentialRequest)
 {
     return(PostAnsible <GetCredentialsResponseDto>(authenticationToken, AnsibleTowerInstance.ApiDefinition.credentials, credentialRequest));
 }
 public Task <ResultOrganizationDto> CreateCredential(string authenticationToken, CreateCredentialRequestDto credentialRequest)
 {
     return(PostAnsible <ResultOrganizationDto>(authenticationToken, AnsibleTowerInstance.ApiDefinition.credentials, credentialRequest));
 }
示例#5
0
 public async Task <IActionResult> Credentials([FromHeader] string authenticationToken, CreateCredentialRequestDto createCredentialRequest)
 {
     Devon4NetLogger.Debug("Executing Login from controller AnsibleTowerController");
     return(Ok(await AnsibleTowerHandler.CreateCredential(authenticationToken, createCredentialRequest)));
 }