Exemple #1
0
        public async Task<bool> SaveCredentialAsync(CredentialModelProxy credential)
        {
            var dict = new Dictionary<string, object>();
            var properties = new Dictionary<string, object>();
            properties.Add("userName", credential.UserName);
            properties.Add("password", credential.RawValue);
            dict.Add("properties", properties);

            if (credential.CredentialID == Guid.Empty)
            {
                // New variable
                await SendRequestAsync("credentials/" + credential.Name.ToUrlSafeString(), HttpMethod.Put, JsonConvert.SerializeObject(dict), "application/json");
            }
            else
            {
                await SendRequestAsync("credentials/" + credential.Name.ToUrlSafeString(), new HttpMethod("PATCH"), JsonConvert.SerializeObject(dict), "application/json");
            }

            return true;
        }
        public async Task<bool> SaveCredentialAsync(CredentialModelProxy credential)
        {
            var credToSave = new CredentialCreateOrUpdateParameters();
            credToSave.Name = credential.Name;

            credToSave.Properties = new CredentialCreateOrUpdateProperties();
            credToSave.Properties.UserName = credential.UserName;
            credToSave.Properties.Password = credential.RawValue;

            var response = await _client.PsCredentials.CreateOrUpdateAsync(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, credToSave);

            if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
            {
                _output.AppendLine("Unable to save the credential at the moment, please verify your connectivity and try again.");
                return false;
            }

            credential.RawValue = string.Empty;

            return true;
        }
Exemple #3
0
        public Task<bool> SaveCredentialAsync(CredentialModelProxy credential)
        {
            Logger.DebugFormat("SaveSmaCredential(...)");

            var context = GetConnection();
            var rawCredential = credential.Model as SMA.Credential;

            if (credential.CredentialID == Guid.Empty)
            {
                context.AddToCredentials(rawCredential);
            }
            else
            {
                var foundCredential = context.Credentials.Where(c => c.CredentialID == credential.CredentialID).FirstOrDefault();

                if (foundCredential == null)
                {
                    // The variable doesn't exist
                    // NOTE: This suggests that the credential may be created in another
                    // environment and then reconnected to another SMA instance. How should this be handled?
                    context.AddToCredentials(rawCredential);
                }

                foundCredential.Name = credential.Name;
                foundCredential.UserName = credential.UserName;
                foundCredential.RawValue = credential.RawValue;

                context.UpdateObject(foundCredential);
            }

            context.SaveChanges();

            return new Task<bool>(() =>
            {
                return true;
            });
        }