/// <summary>
 /// Initializes a new instance of the
 /// CertificateCreateOrUpdateParameters class with required arguments.
 /// </summary>
 public CertificateCreateOrUpdateParameters(string name, CertificateCreateOrUpdateProperties properties)
     : this()
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (properties == null)
     {
         throw new ArgumentNullException("properties");
     }
     this.Name = name;
     this.Properties = properties;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the
 /// CertificateCreateOrUpdateParameters class with required arguments.
 /// </summary>
 public CertificateCreateOrUpdateParameters(string name, CertificateCreateOrUpdateProperties properties)
     : this()
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (properties == null)
     {
         throw new ArgumentNullException("properties");
     }
     this.Name       = name;
     this.Properties = properties;
 }
        private Certificate CreateCertificateInternal(string resourceGroupName, string automationAccountName, string name, string path,
            SecureString password, string description, bool exportable)
        {
            var cert = (password == null)
                ? new X509Certificate2(path, String.Empty,
                    X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet |
                    X509KeyStorageFlags.MachineKeySet)
                : new X509Certificate2(path, password,
                    X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet |
                    X509KeyStorageFlags.MachineKeySet);

            var ccprop = new CertificateCreateOrUpdateProperties()
            {
                Description = description,
                Base64Value = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12)),
                Thumbprint = cert.Thumbprint,
                IsExportable = exportable
            };

            var ccparam = new CertificateCreateOrUpdateParameters() {Name = name, Properties = ccprop};

            var certificate =
                this.automationManagementClient.Certificates.CreateOrUpdate(resourceGroupName, automationAccountName, ccparam).Certificate;

            return new Certificate(resourceGroupName, automationAccountName, certificate);
        }
        public static async Task UploadToCloud(ICollection<AutomationAsset> assetsToUpload, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName)
        {
            var jss = new JavaScriptSerializer();

            foreach (var assetToUpload in assetsToUpload)
            {
                CancellationTokenSource cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                if (assetToUpload is AutomationVariable)
                {
                    var asset = (AutomationVariable)assetToUpload;

                    var properties = new VariableCreateOrUpdateProperties();
                    properties.IsEncrypted = asset.Encrypted;

                    var stringBuilder = new StringBuilder();
                    jss.Serialize(asset.getValue(), stringBuilder);
                    properties.Value = stringBuilder.ToString();

                    await automationApi.Variables.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new VariableCreateOrUpdateParameters(asset.Name, properties), cts.Token);
                }
                else if(assetToUpload is AutomationCredential)
                {
                    var asset = (AutomationCredential)assetToUpload;

                    var properties = new CredentialCreateOrUpdateProperties();
                    properties.UserName = asset.getUsername();
                    properties.Password = asset.getPassword();

                    await automationApi.PsCredentials.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new CredentialCreateOrUpdateParameters(asset.Name, properties), cts.Token);
                }
                else if (assetToUpload is AutomationConnection)
                {
                    var asset = (AutomationConnection)assetToUpload;

                    var properties = new ConnectionCreateOrUpdateProperties();
                    var connectionFieldsAsJson = new Dictionary<string, string>();

                    foreach(KeyValuePair<string, object> field in asset.getFields())
                    {
                        connectionFieldsAsJson.Add(field.Key, field.Value.ToString());
                    }

                    properties.FieldDefinitionValues = connectionFieldsAsJson;
                    properties.ConnectionType = new ConnectionTypeAssociationProperty();
                    properties.ConnectionType.Name = asset.ConnectionType;

                    await automationApi.Connections.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new ConnectionCreateOrUpdateParameters(asset.Name, properties), cts.Token);
                }
                else if (assetToUpload is AutomationCertificate)
                {
                    var asset = (AutomationCertificate)assetToUpload;

                    var cert = (asset.getPassword() == null)
                                ? new X509Certificate2(asset.getCertPath(), String.Empty,
                                    X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet |
                                    X509KeyStorageFlags.MachineKeySet)
                                : new X509Certificate2(asset.getCertPath(), asset.getPassword(),
                                    X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet |
                                    X509KeyStorageFlags.MachineKeySet);

                    var properties = new CertificateCreateOrUpdateProperties()
                    {
                        Base64Value = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12)),
                        Thumbprint = cert.Thumbprint,
                        IsExportable = asset.getExportable()
                    };

                    await automationApi.Certificates.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new CertificateCreateOrUpdateParameters(asset.Name, properties), cts.Token);
                }
            }
        }