/// <summary>
 /// Create a credential.  (see
 /// http://aka.ms/azureautomationsdk/credentialoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.ICredentialOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create or update
 /// credential operation.
 /// </param>
 /// <returns>
 /// The response model for the create or update credential operation.
 /// </returns>
 public static CredentialCreateOrUpdateResponse CreateOrUpdate(this ICredentialOperations operations, string resourceGroupName, string automationAccount, CredentialCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ICredentialOperations)s).CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        public CredentialInfo CreateCredential(string resourceGroupName, string automationAccountName, string name, string userName,
            string password,
            string description)
        {
            var credentialCreateParams = new AutomationManagement.Models.CredentialCreateOrUpdateParameters();
            credentialCreateParams.Name = name;
            credentialCreateParams.Properties = new AutomationManagement.Models.CredentialCreateOrUpdateProperties();
            if (description != null) credentialCreateParams.Properties.Description = description;

            Requires.Argument("userName", userName).NotNull();
            Requires.Argument("password", password).NotNull();

            credentialCreateParams.Properties.UserName = userName;
            credentialCreateParams.Properties.Password = password;

            var createdCredential = this.automationManagementClient.PsCredentials.CreateOrUpdate(resourceGroupName, automationAccountName,
                credentialCreateParams);

            if (createdCredential == null || createdCredential.StatusCode != HttpStatusCode.Created)
            {
                throw new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Create",
                    "credential", name, automationAccountName));
            }
            return new CredentialInfo(resourceGroupName, automationAccountName, createdCredential.Credential);
        }
 /// <summary>
 /// Create a credential.  (see
 /// http://aka.ms/azureautomationsdk/credentialoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.ICredentialOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create or update
 /// credential operation.
 /// </param>
 /// <returns>
 /// The response model for the create or update credential operation.
 /// </returns>
 public static Task<CredentialCreateOrUpdateResponse> CreateOrUpdateAsync(this ICredentialOperations operations, string resourceGroupName, string automationAccount, CredentialCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None);
 }