Example #1
0
        private static HttpStatusCode UploadNewManagementCert(string subscriptionId, X509Certificate2 existingCertificate, string newCertificateCerFilePath)
        {
            var statusCode = HttpStatusCode.Unused;
            var newCertificate = new X509Certificate2(newCertificateCerFilePath);

            var creds = new CertificateCloudCredentials(subscriptionId, existingCertificate);
            var client = new ManagementClient(creds);

            var parm = new ManagementCertificateCreateParameters()
            {
                Data = newCertificate.RawData,
                PublicKey = newCertificate.GetPublicKey(),
                Thumbprint = newCertificate.Thumbprint
            };

            //Hyak throws an exception for a Created result, which is actually  the success code
            try
            {
                var response = client.ManagementCertificates.Create(parm);
            }
            catch (CloudException ex)
            {
                statusCode = ex.Response.StatusCode;
            }

            return statusCode;
        }
 /// <summary>
 /// The Create Management Certificate operation adds a certificate to
 /// the list of management certificates. Management certificates,
 /// which are also known as subscription certificates, authenticate
 /// clients attempting to connect to resources associated with your
 /// Azure subscription.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154123.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.IManagementCertificateOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Management Certificate
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Create(this IManagementCertificateOperations operations, ManagementCertificateCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IManagementCertificateOperations)s).CreateAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// The Add Management Certificate operation adds a certificate to the
 /// list of management certificates. Management certificates, which
 /// are also known as subscription certificates, authenticate clients
 /// attempting to connect to resources associated with your Windows
 /// Azure subscription.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154123.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.IManagementCertificateOperations.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Management Certificate operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse Create(this IManagementCertificateOperations operations, ManagementCertificateCreateParameters parameters)
 {
     try
     {
         return operations.CreateAsync(parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
 /// <summary>
 /// The Create Management Certificate operation adds a certificate to
 /// the list of management certificates. Management certificates,
 /// which are also known as subscription certificates, authenticate
 /// clients attempting to connect to resources associated with your
 /// Azure subscription.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154123.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.IManagementCertificateOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Management Certificate
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> CreateAsync(this IManagementCertificateOperations operations, ManagementCertificateCreateParameters parameters)
 {
     return operations.CreateAsync(parameters, CancellationToken.None);
 }