/// <summary>
        /// Upserts a managed instance
        /// </summary>
        /// <param name="model">The managed instance to upsert</param>
        /// <returns>The updated managed instance model</returns>
        public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanceModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstance()
            {
                Location                   = model.Location,
                Tags                       = model.Tags,
                AdministratorLogin         = model.AdministratorLogin,
                AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null,
                Sku                       = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null,
                LicenseType               = model.LicenseType,
                StorageSizeInGB           = model.StorageSizeInGB,
                SubnetId                  = model.SubnetId,
                VCores                    = model.VCores,
                Identity                  = model.Identity,
                Collation                 = model.Collation,
                PublicDataEndpointEnabled = model.PublicDataEndpointEnabled,
                ProxyOverride             = model.ProxyOverride,
                TimezoneId                = model.TimezoneId,
                DnsZonePartner            = model.DnsZonePartner,
                InstancePoolId            = model.InstancePoolName != null ?
                                            string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/instancePools/{2}",
                                                          Context.Subscription.Id, model.ResourceGroupName, model.InstancePoolName): null
            });

            return(CreateManagedInstanceModelFromResponse(resp));
        }
Exemple #2
0
        /// <summary>
        /// Upserts a managed instance
        /// </summary>
        /// <param name="model">The managed instance to upsert</param>
        /// <returns>The updated managed instance model</returns>
        public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanceModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstance()
            {
                Location                   = model.Location,
                Tags                       = model.Tags,
                AdministratorLogin         = model.AdministratorLogin,
                AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null,
                Sku                       = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null,
                LicenseType               = model.LicenseType,
                StorageSizeInGB           = model.StorageSizeInGB,
                SubnetId                  = model.SubnetId,
                VCores                    = model.VCores,
                Identity                  = model.Identity,
                Collation                 = model.Collation,
                PublicDataEndpointEnabled = model.PublicDataEndpointEnabled,
                ProxyOverride             = model.ProxyOverride,
                TimezoneId                = model.TimezoneId,
                DnsZonePartner            = model.DnsZonePartner,
                InstancePoolId            = model.InstancePoolName != null ?
                                            string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/instancePools/{2}",
                                                          Context.Subscription.Id, model.ResourceGroupName, model.InstancePoolName) : null,
                MinimalTlsVersion             = model.MinimalTlsVersion,
                StorageAccountType            = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
                MaintenanceConfigurationId    = MaintenanceConfigurationHelper.ConvertMaintenanceConfigurationIdArgument(model.MaintenanceConfigurationId, Context.Subscription.Id),
                Administrators                = GetActiveDirectoryInformation(model.Administrators),
                PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId,
                KeyId = model.KeyId
            });

            return(CreateManagedInstanceModelFromResponse(resp));
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (ShouldProcess(VirtualMachineADDomainExtensionContext.ExtensionDefaultName, VerbsCommon.Set))
            {
                ExecuteClientAction(() =>
                {
                    Hashtable publicSettings = new Hashtable();
                    publicSettings.Add(nameKey, this.DomainName);

                    if (this.OUPath != null)
                    {
                        publicSettings.Add(ouPathKey, this.OUPath);
                    }

                    if (this.JoinOption != null)
                    {
                        publicSettings.Add(optionKey, this.JoinOption);
                    }

                    publicSettings.Add(restartKey, Restart.IsPresent);

                    Hashtable privateSettings = new Hashtable();
                    if (Credential != null)
                    {
                        publicSettings.Add(userKey, Credential.UserName);
                        privateSettings.Add(passwordKey, ConversionUtilities.SecureStringToString(this.Credential.Password));
                    }

                    if (string.IsNullOrEmpty(this.Location))
                    {
                        this.Location = GetLocationFromVm(this.ResourceGroupName, this.VMName);
                    }

                    var parameters = new VirtualMachineExtension
                    {
                        Location  = this.Location,
                        Publisher = VirtualMachineADDomainExtensionContext.ExtensionDefaultPublisher,
                        VirtualMachineExtensionType = VirtualMachineADDomainExtensionContext.ExtensionDefaultName,
                        TypeHandlerVersion          = this.TypeHandlerVersion ?? VirtualMachineADDomainExtensionContext.ExtensionDefaultVersion,
                        AutoUpgradeMinorVersion     = !this.DisableAutoUpgradeMinorVersion.IsPresent,
                        ForceUpdateTag    = this.ForceRerun,
                        Settings          = publicSettings,
                        ProtectedSettings = privateSettings
                    };

                    var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
                        this.ResourceGroupName,
                        this.VMName,
                        this.Name ?? VirtualMachineADDomainExtensionContext.ExtensionDefaultName,
                        parameters).GetAwaiter().GetResult();

                    var result = Mapper.Map <PSAzureOperationResponse>(op);
                    WriteObject(result);
                });
            }
        }
Exemple #4
0
        /// <summary>
        /// Upserts an elastic job credential to the control database
        /// </summary>
        /// <param name="model">The job credential object</param>
        /// <returns>The job credential object</returns>
        public AzureSqlElasticJobCredentialModel UpsertJobCredential(AzureSqlElasticJobCredentialModel model)
        {
            var param = new JobCredential
            {
                Username = model.UserName,
                Password = model.Password != null?ConversionUtilities.SecureStringToString(model.Password) : null
            };

            var resp = Communicator.CreateOrUpdateJobCredential(model.ResourceGroupName, model.ServerName, model.AgentName, model.CredentialName, param);

            return(CreateAgentCredentialModelFromResponse(model.ResourceGroupName, model.ServerName, model.AgentName, resp));
        }
Exemple #5
0
        private AuthenticationResult AcquireTokenWithSecret(AdalConfiguration config, string appId, SecureString appKey)
        {
            if (appKey == null)
            {
                return(RenewWithSecret(config, appId));
            }

            StoreAppKey(appId, config.AdDomain, appKey);
            var context    = GetContext(config);
            var credential = new ClientCredential(appId, ConversionUtilities.SecureStringToString(appKey));

            return(context.AcquireTokenAsync(config.ResourceClientUri, credential).ConfigureAwait(false).GetAwaiter().GetResult());
        }
Exemple #6
0
        private WsfcDomainProfile updateWsfcDomainProfile(WsfcDomainProfile profile)
        {
            profile.ClusterBootstrapAccount = ClusterBootstrapAccount ?? profile.ClusterBootstrapAccount;
            profile.ClusterOperatorAccount  = ClusterOperatorAccount ?? profile.ClusterOperatorAccount;
            profile.SqlServiceAccount       = SqlServiceAccount ?? profile.SqlServiceAccount;
            profile.DomainFqdn           = DomainFqdn ?? profile.DomainFqdn;
            profile.StorageAccountUrl    = StorageAccountUrl ?? profile.StorageAccountUrl;
            profile.FileShareWitnessPath = FileShareWitnessPath ?? profile.FileShareWitnessPath;
            profile.OuPath = OuPath ?? profile.OuPath;

            profile.StorageAccountPrimaryKey = StorageAccountPrimaryKey != null?ConversionUtilities.SecureStringToString(StorageAccountPrimaryKey) : profile.StorageAccountPrimaryKey;

            return(profile);
        }
        /// <summary>
        /// Upserts a managed instance
        /// </summary>
        /// <param name="model">The managed instance to upsert</param>
        /// <returns>The updated managed instance model</returns>
        public AzureSqlManagedInstanceModel UpdateManagedInstance(AzureSqlManagedInstanceModel model)
        {
            var resp = Communicator.Update(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstanceUpdate()
            {
                Tags = model.Tags,
                AdministratorLogin         = model.AdministratorLogin,
                AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null,
                Sku             = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null,
                LicenseType     = model.LicenseType,
                StorageSizeInGB = model.StorageSizeInGB,
                SubnetId        = model.SubnetId,
                VCores          = model.VCores
            });

            return(CreateManagedInstanceModelFromResponse(resp));
        }
        /// <summary>
        /// Authenticate using the secret for the specified client from the key store
        /// </summary>
        /// <param name="clientId">The active directory client id for the application.</param>
        /// <param name="audience">The intended audience for authentication</param>
        /// <param name="context">The AD AuthenticationContext to use</param>
        /// <returns></returns>
        public async Task <AuthenticationResult> AuthenticateAsync(string clientId, string audience, AuthenticationContext context)
        {
            var task = new Task <SecureString>(() =>
            {
                return(ServicePrincipalKeyStore.GetKey(clientId, _tenantId));
            });

            task.Start();
            var key = await task.ConfigureAwait(false);

#if !NETSTANDARD
            return(await context.AcquireTokenAsync(audience, new ClientCredential(clientId, key)));
#else
            return(await context.AcquireTokenAsync(audience, new ClientCredential(clientId,
                                                                                  ConversionUtilities.SecureStringToString(key))));
#endif
        }
Exemple #9
0
        /// <summary>
        /// Creates and returns <see cref="KeyVaultCredentialSettings"/> object.
        /// </summary>
        protected override void ProcessRecord()
        {
            string target = "Azure Key Vault";
            string action = "Creation";

            if (ShouldProcess(target, action))
            {
                KeyVaultCredentialSettings settings = new KeyVaultCredentialSettings();
                settings.ResourceGroupName      = (this.ResourceGroupName == null) ? null : this.ResourceGroupName;
                settings.Enable                 = (this.Enable.IsPresent) ? this.Enable.ToBool() : false;
                settings.CredentialName         = (this.CredentialName == null) ? null : this.CredentialName;
                settings.ServicePrincipalName   = (this.ServicePrincipalName == null) ? null : this.ServicePrincipalName;
                settings.ServicePrincipalSecret = (this.ServicePrincipalSecret == null) ?
                                                  null : ConversionUtilities.SecureStringToString(ServicePrincipalSecret);
                settings.AzureKeyVaultUrl = (this.AzureKeyVaultUrl == null) ? null : this.AzureKeyVaultUrl;
                WriteObject(settings);
            }
        }
        /// <summary>
        /// Upserts a managed instance
        /// </summary>
        /// <param name="model">The managed instance to upsert</param>
        /// <returns>The updated managed instance model</returns>
        public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanceModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstance()
            {
                Location                   = model.Location,
                Tags                       = model.Tags,
                AdministratorLogin         = model.AdministratorLogin,
                AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null,
                Sku                       = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null,
                LicenseType               = model.LicenseType,
                StorageSizeInGB           = model.StorageSizeInGB,
                SubnetId                  = model.SubnetId,
                VCores                    = model.VCores,
                Identity                  = model.Identity,
                Collation                 = model.Collation,
                PublicDataEndpointEnabled = model.PublicDataEndpointEnabled,
                ProxyOverride             = model.ProxyOverride
            });

            return(CreateManagedInstanceModelFromResponse(resp));
        }
Exemple #11
0
        /// <summary>
        /// Creates and returns <see cref="AutoBackupSettings"/> object.
        /// </summary>
        protected override void ProcessRecord()
        {
            AutoBackupSettings autoBackupSettings = new AutoBackupSettings();

            autoBackupSettings.Enable           = (Enable.IsPresent) ? Enable.ToBool() : false;
            autoBackupSettings.EnableEncryption = (EnableEncryption.IsPresent) ? EnableEncryption.ToBool() : false;
            autoBackupSettings.RetentionPeriod  = RetentionPeriodInDays;

            switch (ParameterSetName)
            {
            case StorageContextParamSetName:
                autoBackupSettings.StorageUrl       = StorageContext.BlobEndPoint;
                autoBackupSettings.StorageAccessKey = this.GetStorageKey();
                break;

            case StorageUriParamSetName:
                autoBackupSettings.StorageUrl       = (StorageUri == null) ? null : StorageUri.ToString();
                autoBackupSettings.StorageAccessKey = (StorageKey == null) ? null : ConversionUtilities.SecureStringToString(StorageKey);
                break;
            }

            // Check if certificate password was set
            autoBackupSettings.Password = (CertificatePassword == null) ? null : ConversionUtilities.SecureStringToString(CertificatePassword);

            autoBackupSettings.BackupSystemDbs    = BackupSystemDbs.IsPresent ? BackupSystemDbs.ToBool() : false;
            autoBackupSettings.BackupScheduleType = BackupScheduleType;

            // Set other Backup schedule settings only if BackUpSchedule type is Manual.
            if (!string.IsNullOrEmpty(BackupScheduleType) && string.Equals(BackupScheduleType, ValidateSetValues.Manual, StringComparison.InvariantCultureIgnoreCase))
            {
                ValidateBackupScheduleSettings();

                autoBackupSettings.FullBackupFrequency   = FullBackupFrequency;
                autoBackupSettings.FullBackupStartTime   = FullBackupStartHour;
                autoBackupSettings.FullBackupWindowHours = FullBackupWindowInHours;
                autoBackupSettings.LogBackupFrequency    = LogBackupFrequencyInMinutes;
            }

            WriteObject(autoBackupSettings);
        }
        public override void ExecuteCmdlet()
        {
            this.VM.OSProfile = new OSProfile
            {
                ComputerName  = this.ComputerName,
                AdminUsername = this.Credential.UserName,
                AdminPassword = ConversionUtilities.SecureStringToString(this.Credential.Password),
                CustomData    = string.IsNullOrWhiteSpace(this.CustomData) ? null : Convert.ToBase64String(Encoding.UTF8.GetBytes(this.CustomData)),
            };

            if (this.ParameterSetName == LinuxParamSet)
            {
                if (this.VM.OSProfile.WindowsConfiguration != null)
                {
                    throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
                }

                if (this.VM.OSProfile.LinuxConfiguration == null)
                {
                    this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration();
                }

                this.VM.OSProfile.LinuxConfiguration.DisablePasswordAuthentication =
                    (this.DisablePasswordAuthentication.IsPresent)
                    ? (bool?)true
                    : null;
            }
            else
            {
                if (this.VM.OSProfile.LinuxConfiguration != null)
                {
                    throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
                }

                if (this.VM.OSProfile.WindowsConfiguration == null)
                {
                    this.VM.OSProfile.WindowsConfiguration = new WindowsConfiguration();
                    this.VM.OSProfile.WindowsConfiguration.AdditionalUnattendContent = null;
                }

                var listenerList = new List <WinRMListener>();

                if (this.WinRMHttp.IsPresent)
                {
                    listenerList.Add(new WinRMListener
                    {
                        Protocol       = ProtocolTypes.Http,
                        CertificateUrl = null,
                    });
                }

                if (this.WinRMHttps.IsPresent)
                {
                    listenerList.Add(new WinRMListener
                    {
                        Protocol       = ProtocolTypes.Https,
                        CertificateUrl = this.WinRMCertificateUrl.ToString(),
                    });
                }

                // OS Profile
                this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = this.ProvisionVMAgent.IsPresent;

                this.VM.OSProfile.WindowsConfiguration.EnableAutomaticUpdates = this.EnableAutoUpdate.IsPresent;

                this.VM.OSProfile.WindowsConfiguration.TimeZone = this.TimeZone;

                this.VM.OSProfile.WindowsConfiguration.WinRM =
                    !(this.WinRMHttp.IsPresent || this.WinRMHttps.IsPresent)
                    ? null
                    : new WinRMConfiguration
                {
                    Listeners = listenerList,
                };
            }

            WriteObject(this.VM);
        }
        public string GetAadAuthenticatedToken(AsAzureContext asAzureContext, SecureString password, PromptBehavior promptBehavior, string clientId, string resourceUri, Uri resourceRedirectUri)
#endif
        {
            var authUriBuilder = new UriBuilder((string)asAzureContext.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.AdAuthorityBaseUrl]);

            authUriBuilder.Path = string.IsNullOrEmpty(asAzureContext.Account.Tenant)
                ? "common"
                : asAzureContext.Account.Tenant;

            var authenticationContext = new AuthenticationContext(
                authUriBuilder.ToString(),
                AsAzureClientSession.TokenCache);

            AuthenticationResult result = null;
            string accountType          = string.IsNullOrEmpty(asAzureContext.Account.Type) ? AsAzureAccount.AccountType.User : asAzureContext.Account.Type;

            if (password == null && accountType == AsAzureAccount.AccountType.User)
            {
                if (asAzureContext.Account.Id != null)
                {
#if NETSTANDARD
                    result = authenticationContext.AcquireTokenAsync(
                        resourceUri,
                        clientId,
                        resourceRedirectUri,
                        new PlatformParameters(),
                        new UserIdentifier(asAzureContext.Account.Id, UserIdentifierType.OptionalDisplayableId)).Result;
#else
                    result = authenticationContext.AcquireToken(
                        resourceUri,
                        clientId,
                        resourceRedirectUri,
                        promptBehavior,
                        new UserIdentifier(asAzureContext.Account.Id, UserIdentifierType.OptionalDisplayableId));
#endif
                }
                else
                {
#if NETSTANDARD
                    result = authenticationContext.AcquireTokenAsync(
                        resourceUri,
                        clientId,
                        resourceRedirectUri,
                        new PlatformParameters()).Result;
#else
                    result = authenticationContext.AcquireToken(
                        resourceUri,
                        clientId,
                        resourceRedirectUri,
                        promptBehavior);
#endif
                }

                asAzureContext.Account.Id       = result.UserInfo.DisplayableId;
                asAzureContext.Account.Tenant   = result.TenantId;
                asAzureContext.Account.UniqueId = result.UserInfo.UniqueId;
            }
            else
            {
                if (accountType == AsAzureAccount.AccountType.User)
                {
#if NETSTANDARD
                    //https://stackoverflow.com/a/39393039/294804
                    //https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/482
                    //https://github.com/Azure-Samples/active-directory-dotnet-deviceprofile/blob/5d5499d09c918ae837810d457822474df97600e9/DirSearcherClient/Program.cs#L206-L210
                    // Note: More robust implementation in UserTokenProvider.Netcore.cs in DoAcquireToken
                    DeviceCodeResult codeResult = authenticationContext.AcquireDeviceCodeAsync(resourceUri, clientId).Result;
                    promptAction(codeResult?.Message);
                    result = authenticationContext.AcquireTokenByDeviceCodeAsync(codeResult).Result;
#else
                    UserCredential userCredential = new UserCredential(asAzureContext.Account.Id, password);
                    result = authenticationContext.AcquireToken(resourceUri, clientId, userCredential);
#endif

                    asAzureContext.Account.Id       = result.UserInfo.DisplayableId;
                    asAzureContext.Account.Tenant   = result.TenantId;
                    asAzureContext.Account.UniqueId = result.UserInfo.UniqueId;
                }
                else if (accountType == AsAzureAccount.AccountType.ServicePrincipal)
                {
                    if (string.IsNullOrEmpty(asAzureContext.Account.CertificateThumbprint))
                    {
#if NETSTANDARD
                        ClientCredential credential = new ClientCredential(asAzureContext.Account.Id, ConversionUtilities.SecureStringToString(password));
                        result = authenticationContext.AcquireTokenAsync(resourceUri, credential).Result;
#else
                        ClientCredential credential = new ClientCredential(asAzureContext.Account.Id, password);
                        result = authenticationContext.AcquireToken(resourceUri, credential);
#endif
                    }
                    else
                    {
                        DiskDataStore dataStore   = new DiskDataStore();
                        var           certificate = dataStore.GetCertificate(asAzureContext.Account.CertificateThumbprint);
                        if (certificate == null)
                        {
                            throw new ArgumentException(string.Format(Resources.CertificateNotFoundInStore, asAzureContext.Account.CertificateThumbprint));
                        }
#if NETSTANDARD
                        result = authenticationContext.AcquireTokenAsync(resourceUri, new ClientAssertionCertificate(asAzureContext.Account.Id, certificate)).Result;
#else
                        result = authenticationContext.AcquireToken(resourceUri, new ClientAssertionCertificate(asAzureContext.Account.Id, certificate));
#endif
                    }
                }
            }

            return(result?.AccessToken);
        }
        protected override IEnumerable <AzureSqlVMModel> ApplyUserInputToModel(IEnumerable <AzureSqlVMModel> model)
        {
            List <AzureSqlVMModel> newEntity = new List <AzureSqlVMModel>();

            SqlVM.SqlVirtualMachineGroup = SqlVMGroup;
            SqlVM.WsfcDomainCredentials  = new WsfcDomainCredentials()
            {
                ClusterBootstrapAccountPassword = ClusterBootstrapAccountPassword != null?ConversionUtilities.SecureStringToString(ClusterBootstrapAccountPassword) : null,
                                                      ClusterOperatorAccountPassword = ClusterOperatorAccountPassword != null?ConversionUtilities.SecureStringToString(ClusterOperatorAccountPassword) : null,
                                                                                           SqlServiceAccountPassword = SqlServiceAccountPassword != null?ConversionUtilities.SecureStringToString(SqlServiceAccountPassword) : null,
            };
            newEntity.Add(SqlVM);
            return(newEntity);
        }
        public override void ExecuteCmdlet()
        {
            if (this.VM.OSProfile == null)
            {
                this.VM.OSProfile = new OSProfile
                {
                    ComputerName  = this.ComputerName,
                    AdminUsername = this.Credential.UserName,
                    AdminPassword = ConversionUtilities.SecureStringToString(this.Credential.Password),
                    CustomData    = string.IsNullOrWhiteSpace(this.CustomData) ? null : Convert.ToBase64String(Encoding.UTF8.GetBytes(this.CustomData)),
                };
            }
            // These two checks below are present to allow users to change the OS type in the VM object.
            // This behavior may change in the future.
            else if ((this.ParameterSetName == LinuxParamSet) & this.VM.OSProfile.WindowsConfiguration != null)
            {
                this.VM.OSProfile.WindowsConfiguration = null;
            }
            else if ((this.ParameterSetName == WindowsParamSet) & this.VM.OSProfile.LinuxConfiguration != null)
            {
                this.VM.OSProfile.LinuxConfiguration = null;
            }

            if (this.ParameterSetName == LinuxParamSet)
            {
                if (this.VM.OSProfile.WindowsConfiguration != null)
                {
                    throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
                }

                if (this.VM.OSProfile.LinuxConfiguration == null)
                {
                    this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration();
                }

                //seting patchmode
                if (this.IsParameterBound(c => c.PatchMode))
                {
                    if (this.VM.OSProfile.LinuxConfiguration.PatchSettings == null)
                    {
                        this.VM.OSProfile.LinuxConfiguration.PatchSettings = new LinuxPatchSettings();
                    }
                    this.VM.OSProfile.LinuxConfiguration.PatchSettings.PatchMode = this.PatchMode;
                }

                this.VM.OSProfile.LinuxConfiguration.DisablePasswordAuthentication =
                    (this.DisablePasswordAuthentication.IsPresent)
                    ? (bool?)true
                    : null;

                if (this.IsParameterBound(c => c.AssessmentMode))
                {
                    if (this.VM.OSProfile.LinuxConfiguration == null)
                    {
                        this.VM.OSProfile.LinuxConfiguration = new LinuxConfiguration();
                    }
                    if (this.VM.OSProfile.LinuxConfiguration.PatchSettings == null)
                    {
                        this.VM.OSProfile.LinuxConfiguration.PatchSettings = new LinuxPatchSettings();
                    }
                    this.VM.OSProfile.LinuxConfiguration.PatchSettings.AssessmentMode = this.AssessmentMode;
                }
            }
            else
            {
                if (this.VM.OSProfile.LinuxConfiguration != null)
                {
                    throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
                }

                if (this.VM.OSProfile.WindowsConfiguration == null)
                {
                    this.VM.OSProfile.WindowsConfiguration = new WindowsConfiguration();
                    this.VM.OSProfile.WindowsConfiguration.AdditionalUnattendContent = null;
                }

                if (this.IsParameterBound(c => c.AssessmentMode))
                {
                    if (this.VM.OSProfile.WindowsConfiguration == null)
                    {
                        this.VM.OSProfile.WindowsConfiguration = new WindowsConfiguration();
                    }
                    if (this.VM.OSProfile.WindowsConfiguration.PatchSettings == null)
                    {
                        this.VM.OSProfile.WindowsConfiguration.PatchSettings = new PatchSettings();
                    }
                    this.VM.OSProfile.WindowsConfiguration.PatchSettings.AssessmentMode = this.AssessmentMode;
                }

                var listenerList = new List <WinRMListener>();

                if (this.WinRMHttp.IsPresent)
                {
                    listenerList.Add(new WinRMListener
                    {
                        Protocol       = ProtocolTypes.Http,
                        CertificateUrl = null,
                    });
                }

                if (this.WinRMHttps.IsPresent)
                {
                    listenerList.Add(new WinRMListener
                    {
                        Protocol       = ProtocolTypes.Https,
                        CertificateUrl = this.WinRMCertificateUrl.ToString(),
                    });
                }

                if (this.ProvisionVMAgent.IsPresent)
                {
                    this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = true;
                }

                if (this.DisableVMAgent.IsPresent)
                {
                    this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = false;
                }

                if (this.IsParameterBound(c => c.EnableAutoUpdate))
                {
                    this.VM.OSProfile.WindowsConfiguration.EnableAutomaticUpdates = this.EnableAutoUpdate;
                }

                //adam tmp removal, if (this.IsParameterBound(c => c.TimeZone))
                //{
                this.VM.OSProfile.WindowsConfiguration.TimeZone = this.TimeZone;
                //}

                this.VM.OSProfile.WindowsConfiguration.WinRM =
                    !(this.WinRMHttp.IsPresent || this.WinRMHttps.IsPresent)
                    ? null
                    : new WinRMConfiguration
                {
                    Listeners = listenerList,
                };

                //seting patchmode
                if (this.IsParameterBound(c => c.PatchMode))
                {
                    if (this.VM.OSProfile.WindowsConfiguration.PatchSettings == null)
                    {
                        this.VM.OSProfile.WindowsConfiguration.PatchSettings = new PatchSettings();
                    }
                    this.VM.OSProfile.WindowsConfiguration.PatchSettings.PatchMode = this.PatchMode;
                }

                if (this.IsParameterBound(c => c.EnableHotpatching))
                {
                    this.VM.OSProfile.WindowsConfiguration.PatchSettings.EnableHotpatching = this.EnableHotpatching;
                }
            }

            WriteObject(this.VM);
        }
Exemple #16
0
        /// <summary>
        /// Generates the model from user input.
        /// </summary>
        /// <param name="model">This is null since the sql virtual machine group doesn't exist yet</param>
        /// <returns>The generated model from user input</returns>
        protected override IEnumerable <AzureSqlVMGroupModel> ApplyUserInputToModel(IEnumerable <AzureSqlVMGroupModel> model)
        {
            List <AzureSqlVMGroupModel> newEntity = new List <AzureSqlVMGroupModel>();

            newEntity.Add(new AzureSqlVMGroupModel(ResourceGroupName)
            {
                Location          = this.Location,
                Name              = this.Name,
                Offer             = this.Offer,
                Sku               = this.Sku,
                WsfcDomainProfile = new WsfcDomainProfile()
                {
                    ClusterBootstrapAccount = this.ClusterBootstrapAccount,
                    ClusterOperatorAccount  = this.ClusterOperatorAccount,
                    DomainFqdn               = this.DomainFqdn,
                    SqlServiceAccount        = this.SqlServiceAccount,
                    StorageAccountUrl        = this.StorageAccountUrl,
                    StorageAccountPrimaryKey = this.StorageAccountPrimaryKey != null ? ConversionUtilities.SecureStringToString(this.StorageAccountPrimaryKey) : null,
                    FileShareWitnessPath     = this.FileShareWitnessPath,
                    OuPath = this.OuPath
                },
                Tag = TagsConversionHelper.CreateTagDictionary(Tag, validate: true)
            });
            return(newEntity);
        }