public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { this.WorkspaceName = this.InputObject.WorkspaceName; this.Name = this.InputObject.TriggerName; this.TriggerRunId = this.InputObject.TriggerRunId; } if (ShouldProcess(String.Format(Resources.RerunSynapseTriggerRun, TriggerRunId))) { SynapseAnalyticsClient.RerunTriggerRun(Name, TriggerRunId); } if (PassThru) { WriteObject(true); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = this.InputObject.Name; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } if (this.ShouldProcess(this.WorkspaceName, string.Format(Resources.DisablingAdvancedDataSecurity, this.WorkspaceName))) { var policy = SynapseAnalyticsClient.GetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName); policy.State = SecurityAlertPolicyState.Disabled; SynapseAnalyticsClient.SetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, policy); var result = new WorkspaceAdvancedDataSecurityPolicy() { ResourceGroupName = this.ResourceGroupName, WorkspaceName = this.WorkspaceName, IsEnabled = false }; WriteObject(result); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } var result = new SqlPoolVulnerabilityAssessmentSettingsModel(SynapseAnalyticsClient.GetSqlPoolVulnerabilityAssessmentSettings(this.ResourceGroupName, this.WorkspaceName, this.Name), this.ResourceGroupName, this.WorkspaceName, this.Name); WriteObject(result); }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } var fileExtension = ".kql"; if (this.IsParameterBound(c => c.InputObject)) { WriteToFile(this.InputObject); WriteObject(new FileInfo(Path.Combine(this.OutputFolder, this.InputObject.Name + fileExtension))); } else { if (this.IsParameterBound(c => c.Name)) { var kqlScript = new PSKqlScriptResource(SynapseAnalyticsClient.GetKqlScript(this.Name), this.WorkspaceName); WriteToFile(kqlScript); WriteObject(new FileInfo(Path.Combine(this.OutputFolder, kqlScript.Name + fileExtension))); } else { var infoList = new List <FileInfo>(); var kqlScripts = SynapseAnalyticsClient.GetKqlScriptsByWorkspace() .Select(element => new PSKqlScriptResource(element, this.WorkspaceName)); foreach (var kqlScript in kqlScripts) { WriteToFile(kqlScript); infoList.Add(new FileInfo(Path.Combine(this.OutputFolder, kqlScript.Name + fileExtension))); } WriteObject(infoList, true); } } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.RoleDefinitionName)) { this.RoleDefinitionId = SynapseAnalyticsClient.GetRoleDefinitionIdFromRoleDefinitionName(this.RoleDefinitionName); } if (this.IsParameterBound(c => c.SignInName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromSignInName(this.SignInName); } if (this.IsParameterBound(c => c.ServicePrincipalName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromServicePrincipalName(this.ServicePrincipalName); } if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.CreatingSynapseRoleAssignment, this.WorkspaceName, this.RoleDefinitionId, this.ObjectId))) { PSRoleAssignmentDetails roleAssignmentDetails = new PSRoleAssignmentDetails(SynapseAnalyticsClient.CreateRoleAssignment(this.RoleDefinitionId, this.ObjectId)); WriteObject(roleAssignmentDetails); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = InputObject.ResourceGroupName; this.WorkspaceName = InputObject.WorkspaceName; this.Name = InputObject.Name; } IntegrationRuntimeResource resource = SynapseAnalyticsClient.GetIntegrationRuntimeAsync( ResourceGroupName, WorkspaceName, Name).ConfigureAwait(true).GetAwaiter().GetResult().IntegrationRuntime; Action startIntegrationRuntime = () => { PSManagedIntegrationRuntimeStatus response = null; var cancellationTokenSource = new CancellationTokenSource(); var task = Task.Run(() => { response = this.SynapseAnalyticsClient.StartIntegrationRuntimeAsync( ResourceGroupName, WorkspaceName, Name, resource).ConfigureAwait(true).GetAwaiter().GetResult(); }, cancellationTokenSource.Token); UpdateProgress(task, new ProgressRecord(1, "Start", "Starting Progress")); if (response != null) { WriteObject(response); } }; ConfirmAction( Force.IsPresent, string.Format( CultureInfo.InvariantCulture, Resources.IntegrationRuntimeExists, Name, WorkspaceName), string.Format( CultureInfo.InvariantCulture, Resources.StartingIntegrationRuntime, Name, WorkspaceName), Name, startIntegrationRuntime); }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = this.InputObject.Name; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } var parameters = SynapseAnalyticsClient.GetWorkspaceVulnerabilityAssessmentSettings(this.ResourceGroupName, this.WorkspaceName); if (this.IsParameterBound(c => c.BlobStorageSasUri)) { // In this case the user provided a full BlobStorageSasUri (e.g. "https://mystorage.blob.core.windows.net/vulnerability-assessment?st=XXXXXX" ) var storageContainerArgs = BlobStorageSasUri.AbsoluteUri.ToString().Split('?'); if (storageContainerArgs.Length < 2) { throw new Exception(Resources.InvalidBlobStorageSasUri); } parameters.StorageContainerPath = storageContainerArgs[0]; parameters.StorageContainerSasKey = storageContainerArgs[1]; } else { if (this.IsParameterBound(c => c.StorageAccountName)) { var storageResourceGroupName = SynapseAnalyticsClient.GetStorageResourceGroup(this.StorageAccountName); var storageContainerInfo = SynapseAnalyticsClient.GetStorageContainerInfo(storageResourceGroupName, this.StorageAccountName, this.ScanResultsContainerName); parameters.StorageContainerPath = storageContainerInfo.StorageContainerPath; parameters.StorageAccountAccessKey = storageContainerInfo.StorageAccountAccessKey; } if (string.IsNullOrEmpty(parameters.StorageContainerPath)) { throw new Exception(Resources.NoStorageAccountSpecified); } } if (this.IsParameterBound(c => c.NotificationEmail)) { if (!Utils.AreEmailAddressesInCorrectFormat(this.NotificationEmail)) { throw new Exception(Resources.EmailsAreNotValid); } parameters.RecurringScans.Emails = this.NotificationEmail; } if (this.IsParameterBound(c => c.RecurringScansInterval)) { parameters.RecurringScans.IsEnabled = this.RecurringScansInterval != RecurringScansInterval.None; } if (this.IsParameterBound(c => c.EmailAdmin)) { parameters.RecurringScans.EmailSubscriptionAdmins = this.EmailAdmin; } if (this.ShouldProcess(this.WorkspaceName, string.Format(Resources.UpdatingVulnerabilityAssessmentSetting, this.WorkspaceName))) { var result = new VulnerabilityAssessmentSettingsModel(SynapseAnalyticsClient.CreateOrUpdateWorkspaceVulnerabilityAssessmentSettings(this.ResourceGroupName, this.WorkspaceName, parameters), this.ResourceGroupName, this.WorkspaceName); WriteObject(result); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.RoleDefinitionName)) { this.RoleDefinitionId = SynapseAnalyticsClient.GetRoleDefinitionIdFromRoleDefinitionName(this.RoleDefinitionName); } if (this.IsParameterBound(c => c.SignInName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromSignInName(this.SignInName); } if (this.IsParameterBound(c => c.ServicePrincipalName)) { this.ObjectId = SynapseAnalyticsClient.GetObjectIdFromServicePrincipalName(this.ServicePrincipalName); } string itemType = null; if (this.IsParameterBound(c => c.ItemType)) { itemType = this.ItemType.GetItemTypeString(); } if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.CreatingSynapseRoleAssignment, this.WorkspaceName, this.RoleDefinitionId, this.ObjectId))) { // Item type and item should appear Report error if either item type or item is specified. if ((!this.IsParameterBound(c => c.ItemType) && this.IsParameterBound(c => c.Item)) || (this.IsParameterBound(c => c.ItemType) && !this.IsParameterBound(c => c.Item))) { throw new AzPSInvalidOperationException(String.Format(Resources.WorkspaceItemTypeAndItemNotAppearTogether)); } string roleAssignmentId = Guid.NewGuid().ToString(); string scope = SynapseAnalyticsClient.GetRoleAssignmentScope(this.WorkspaceName, itemType, this.Item); PSRoleAssignmentDetails roleAssignmentDetails = new PSRoleAssignmentDetails(SynapseAnalyticsClient.CreateRoleAssignment(roleAssignmentId, this.RoleDefinitionId, this.ObjectId, scope)); WriteObject(roleAssignmentDetails); } }
public override void ExecuteCmdlet() { this.Language = LanguageType.Parse(this.Language); if (string.IsNullOrEmpty(this.MainClassName)) { if (LanguageType.SparkDotNet == this.Language || LanguageType.Spark == this.Language) { throw new SynapseException(Resources.MissingMainClassName); } } if (this.IsParameterBound(c => c.SparkPoolObject)) { var resourceIdentifier = new ResourceIdentifier(this.SparkPoolObject.Id); this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.SparkPoolName = resourceIdentifier.ResourceName; } this.MainDefinitionFile = Utils.NormalizeUrl(this.MainDefinitionFile); if (this.CommandLineArguments != null) { for (int i = 0; i < this.CommandLineArguments.Length; i++) { this.CommandLineArguments[i] = Utils.NormalizeUrl(this.CommandLineArguments[i]); } } if (this.ReferenceFiles != null) { for (int i = 0; i < this.ReferenceFiles.Length; i++) { this.ReferenceFiles[i] = Utils.NormalizeUrl(this.ReferenceFiles[i]); } } Utils.CategorizedFiles(this.ReferenceFiles, out IList <string> jars, out IList <string> files); bool isSparkDotNet = this.Language == LanguageType.SparkDotNet; var batchRequest = new ExtendedLivyBatchRequest { Name = this.Name, File = isSparkDotNet ? SynapseConstants.SparkDotNetJarFile : this.MainDefinitionFile, ClassName = isSparkDotNet ? SynapseConstants.SparkDotNetClassName : (this.Language == LanguageType.PySpark ? null : this.MainClassName), Args = isSparkDotNet ? new List <string> { this.MainDefinitionFile, this.MainClassName } .Concat(this.CommandLineArguments ?? new string[0]).ToArray() : this.CommandLineArguments, Jars = jars, Files = files, Archives = isSparkDotNet ? new List <string> { $"{this.MainDefinitionFile}#{SynapseConstants.SparkDotNetUdfsFolderName}" } : null, Conf = this.Configuration?.ToDictionary(), ExecutorMemory = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Memory + "g", ExecutorCores = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Cores, DriverMemory = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Memory + "g", DriverCores = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Cores, NumExecutors = this.ExecutorCount }; var jobInformation = SynapseAnalyticsClient.SubmitSparkBatchJob(this.WorkspaceName, this.SparkPoolName, batchRequest, waitForCompletion: false); WriteObject(new PSSynapseSparkJob(jobInformation)); }
public override void ExecuteCmdlet() { WriteObject(SynapseAnalyticsClient.TestWorkspace(ResourceGroupName, Name)); }
public override void ExecuteCmdlet() { this.Language = LanguageType.Parse(this.Language); if (string.IsNullOrEmpty(this.MainClassName)) { if (LanguageType.SparkDotNet == this.Language || LanguageType.Spark == this.Language) { throw new SynapseException(Resources.MissingMainClassName); } } if (this.IsParameterBound(c => c.SparkPoolObject)) { var resourceIdentifier = new ResourceIdentifier(this.SparkPoolObject.Id); this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.SparkPoolName = resourceIdentifier.ResourceName; } this.MainDefinitionFile = Utils.NormalizeUrl(this.MainDefinitionFile); if (this.CommandLineArgument != null) { for (int i = 0; i < this.CommandLineArgument.Length; i++) { this.CommandLineArgument[i] = Utils.NormalizeUrl(this.CommandLineArgument[i]); } } if (this.ReferenceFile != null) { for (int i = 0; i < this.ReferenceFile.Length; i++) { this.ReferenceFile[i] = Utils.NormalizeUrl(this.ReferenceFile[i]); } } Utils.CategorizedFiles(this.ReferenceFile, out IList <string> jars, out IList <string> files); bool isSparkDotNet = this.Language == LanguageType.SparkDotNet; var batchRequest = new SparkBatchJobOptions(this.Name, isSparkDotNet ? SynapseConstants.SparkDotNetJarFile : this.MainDefinitionFile) { ClassName = isSparkDotNet ? SynapseConstants.SparkDotNetClassName : (this.Language == LanguageType.PySpark ? null : this.MainClassName), Arguments = isSparkDotNet ? new List <string> { this.MainDefinitionFile, this.MainClassName } .Concat(this.CommandLineArgument ?? new string[0]).ToArray() : this.CommandLineArgument, Jars = jars, Files = files, Archives = isSparkDotNet ? new List <string> { $"{this.MainDefinitionFile}#{SynapseConstants.SparkDotNetUdfsFolderName}" } : null, Configuration = this.Configuration?.ToDictionary(), ExecutorMemory = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Memory + "g", ExecutorCores = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Cores, DriverMemory = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Memory + "g", DriverCores = SynapseConstants.ComputeNodeSizes[this.ExecutorSize].Cores, ExecutorCount = this.ExecutorCount }; // Ensure the relative path of UDFs is add to "--conf". if (isSparkDotNet) { batchRequest.Configuration = batchRequest.Configuration ?? new Dictionary <string, string>(); string udfsRelativePath = "./" + SynapseConstants.SparkDotNetUdfsFolderName; batchRequest.Configuration.TryGetValue(SynapseConstants.SparkDotNetAssemblySearchPathsKey, out string pathValue); var paths = pathValue?.Split(',').Select(path => path.Trim()).Where(path => !string.IsNullOrEmpty(path)).ToList() ?? new List <string>(); if (!paths.Contains(udfsRelativePath)) { paths.Add(udfsRelativePath); } batchRequest.Configuration[SynapseConstants.SparkDotNetAssemblySearchPathsKey] = string.Join(",", paths); } if (this.ShouldProcess(this.SparkPoolName, string.Format(Resources.SubmittingSynapseSparkJob, this.SparkPoolName, this.WorkspaceName))) { var jobInformation = SynapseAnalyticsClient.SubmitSparkBatchJob(batchRequest, waitForCompletion: false); WriteObject(new PSSynapseSparkJob(jobInformation)); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = this.InputObject.Name; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ResourceName; } WorkspaceAuditModel model = SynapseAnalyticsClient.GetWorkspaceAudit(this.ResourceGroupName, this.WorkspaceName); if (this.IsParameterBound(c => c.AuditActionGroup)) { model.AuditActionGroup = this.AuditActionGroup; } if (this.IsParameterBound(c => c.PredicateExpression)) { model.PredicateExpression = this.PredicateExpression; } if (this.IsParameterBound(c => c.BlobStorageTargetState)) { model.BlobStorageTargetState = this.BlobStorageTargetState == SynapseConstants.Security.Enabled ? AuditStateType.Enabled : AuditStateType.Disabled; } if (this.IsParameterBound(c => c.StorageAccountResourceId)) { model.StorageAccountResourceId = this.StorageAccountResourceId; } if (this.IsParameterBound(c => c.StorageKeyType)) { model.StorageKeyType = (this.StorageKeyType == SynapseConstants.Security.Primary) ? StorageKeyKind.Primary : StorageKeyKind.Secondary; } if (this.IsParameterBound(c => c.RetentionInDays)) { model.RetentionInDays = this.RetentionInDays; } // check parameters if (this.BlobStorageTargetState == SynapseConstants.Security.Enabled && string.IsNullOrEmpty(this.StorageAccountResourceId)) { throw new PSArgumentException(Resources.StorageAccountNameParameterException, "StorageAccountName"); } if (this.ShouldProcess(this.WorkspaceName, string.Format(Resources.SettingSqlAudit, this.WorkspaceName))) { SynapseAnalyticsClient.CreateOrUpdateWorkspaceAudit(model); if (PassThru) { WriteObject(model); } } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.WorkspaceName = this.WorkspaceObject.Name; } if (!this.IsParameterBound(c => c.Name)) { string path = this.TryResolvePath(DefinitionFile); this.Name = Path.GetFileNameWithoutExtension(path); } if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.SettingSynapseSqlScript, this.Name, this.WorkspaceName))) { string query = this.ReadFileAsText(DefinitionFile); SqlConnection currentConnection = new SqlConnection(); if (this.IsParameterBound(c => c.SqlPoolName)) { if (SqlPoolName.ToLower() == "built-in") { currentConnection.PoolName = "Built-in"; currentConnection.Type = SqlConnectionType.SqlOnDemand; currentConnection.DatabaseName = this.SqlDatabaseName; } else { currentConnection.Type = SqlConnectionType.SqlPool; currentConnection.PoolName = this.SqlPoolName; currentConnection.DatabaseName = this.SqlDatabaseName; } } else { currentConnection.PoolName = "Built-in"; currentConnection.Type = SqlConnectionType.SqlOnDemand; currentConnection.DatabaseName = "master"; } SqlScriptMetadata metadata = new SqlScriptMetadata { Language = "sql" }; SqlScriptContent content = new SqlScriptContent(query); content.CurrentConnection = currentConnection; content.Metadata = metadata; content.ResultLimit = ResultLimit; SqlScript sqlscript = new SqlScript(content); sqlscript.Type = SqlScriptType.SqlQuery; if (this.IsParameterBound(c => c.FolderPath)) { SqlScriptFolder folder = new SqlScriptFolder(); folder.Name = FolderPath; sqlscript.Folder = folder; } if (this.IsParameterBound(c => c.Description)) { sqlscript.Description = Description; } SqlScriptResource sqlscriptResource = new SqlScriptResource(this.Name, sqlscript); WriteObject(new PSSqlScriptResource(SynapseAnalyticsClient.CreateOrUpdateSqlScript(this.Name, sqlscriptResource), this.WorkspaceName)); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = InputObject.ResourceGroupName; this.WorkspaceName = InputObject.WorkspaceName; this.Name = InputObject.Name; } if (string.IsNullOrWhiteSpace(KeyName)) { throw new PSArgumentNullException("KeyName"); } PSIntegrationRuntimeKeys authKey = null; Action regenerateIntegrationRuntimeAuthKey = () => { authKey = SynapseAnalyticsClient.RegenerateIntegrationRuntimeAuthKeyAsync( ResourceGroupName, WorkspaceName, Name, KeyName).ConfigureAwait(true).GetAwaiter().GetResult(); }; ConfirmAction( Force.IsPresent, // prompt only if the integration runtime exists string.Format( CultureInfo.InvariantCulture, Resources.ContinueRegenerateAuthKey, KeyName, Name), // Process message, string.Format( CultureInfo.InvariantCulture, Resources.RegenerateAuthKey, KeyName, Name), // Target Name, regenerateIntegrationRuntimeAuthKey, () => SynapseAnalyticsClient.CheckIntegrationRuntimeExistsAsync( ResourceGroupName, WorkspaceName, Name).ConfigureAwait(true).GetAwaiter().GetResult()); WriteObject(authKey); }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = new ResourceIdentifier(this.InputObject.Id).ResourceGroupName; this.Name = this.InputObject.Name; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.Name = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(ResourceGroupName)) { ResourceGroupName = SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(Name); } Workspace existingWorkspace = null; try { existingWorkspace = SynapseAnalyticsClient.GetWorkspace(this.ResourceGroupName, this.Name); } catch { existingWorkspace = null; } if (existingWorkspace == null) { throw new AzPSInvalidOperationException(string.Format(Resources.FailedToDiscoverWorkspace, this.Name, this.ResourceGroupName)); } WorkspacePatchInfo patchInfo = new WorkspacePatchInfo(); patchInfo.Tags = this.IsParameterBound(c => c.Tag) ? TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) : TagsConversionHelper.CreateTagDictionary(this.InputObject?.Tags, validate: true); patchInfo.SqlAdministratorLoginPassword = this.IsParameterBound(c => c.SqlAdministratorLoginPassword) ? this.SqlAdministratorLoginPassword.ConvertToString() : null; patchInfo.ManagedVirtualNetworkSettings = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? this.ManagedVirtualNetwork?.ToSdkObject() : this.InputObject?.ManagedVirtualNetworkSettings?.ToSdkObject(); string encrptionKeyName = this.IsParameterBound(c => c.EncryptionKeyName) ? this.EncryptionKeyName : this.InputObject?.Encryption?.CustomerManagedKeyDetails?.Key?.Name; patchInfo.Encryption = !string.IsNullOrEmpty(encrptionKeyName) ? new EncryptionDetails { Cmk = new CustomerManagedKeyDetails { Key = new WorkspaceKeyDetails { Name = encrptionKeyName } } } : null; patchInfo.WorkspaceRepositoryConfiguration = this.IsParameterBound(c => c.GitRepository) ? this.GitRepository.ToSdkObject() : null; if (ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseWorkspace, this.Name, this.ResourceGroupName))) { var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.UpdateWorkspace( this.ResourceGroupName, this.Name, patchInfo)); this.WriteObject(workspace); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = InputObject.ResourceGroupName; this.WorkspaceName = InputObject.WorkspaceName; this.Name = InputObject.Name; } var status = SynapseAnalyticsClient.GetIntegrationRuntimeStatusAsync(ResourceGroupName, WorkspaceName, IntegrationRuntimeName).ConfigureAwait(false).GetAwaiter().GetResult(); var managedStatus = status as PSManagedIntegrationRuntimeStatus; if (managedStatus != null) { if (IpAddress.IsPresent) { ThrowTerminatingError (new ErrorRecord( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The SSIS-Azure integration runtime does not support getting IP address of node.")), string.Empty, ErrorCategory.ObjectNotFound, null)); } var node = managedStatus.Nodes.FirstOrDefault(n => n.NodeId == Name); if (node == null) { ThrowTerminatingError (new ErrorRecord( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The node with node ID {0} in integration runtime {1} was not found.", Name, IntegrationRuntimeName)), string.Empty, ErrorCategory.ObjectNotFound, null)); } WriteObject(new PSManagedIntegrationRuntimeNode(ResourceGroupName, WorkspaceName, IntegrationRuntimeName, Name, node)); } var selfHostedStatus = status as PSSelfHostedIntegrationRuntimeStatus; if (selfHostedStatus != null) { var node = selfHostedStatus.Nodes.FirstOrDefault(n => n.NodeName == Name); if (node == null) { ThrowTerminatingError (new ErrorRecord( new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The node with node name {0} in integration runtime {1} was not found.", Name, IntegrationRuntimeName)), string.Empty, ErrorCategory.ObjectNotFound, null)); } string ipAddress = null; if (IpAddress.IsPresent) { var ip = SynapseAnalyticsClient.GetIntegrationRuntimeNodeIpAsync( ResourceGroupName, WorkspaceName, IntegrationRuntimeName, Name).ConfigureAwait(false).GetAwaiter().GetResult(); ipAddress = ip.Body.IpAddress; } WriteObject(new PSSelfHostedIntegrationRuntimeNode(ResourceGroupName, WorkspaceName, IntegrationRuntimeName, Name, node, ipAddress)); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } SqlPoolSecurityAlertPolicy policy = SynapseAnalyticsClient.GetSqlPoolThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, this.Name); policy.State = SecurityAlertPolicyState.Enabled; if (this.IsParameterBound(c => c.NotificationRecipientsEmail)) { policy.EmailAddresses = this.NotificationRecipientsEmail.Split(';').Where(mail => !string.IsNullOrEmpty(mail)).ToList(); } if (this.IsParameterBound(c => c.EmailAdmin)) { policy.EmailAccountAdmins = this.EmailAdmin; } if (this.IsParameterBound(c => c.ExcludedDetectionType)) { policy.DisabledAlerts = Utils.ProcessExcludedDetectionTypes(this.ExcludedDetectionType); } if (this.IsParameterBound(c => c.RetentionInDays)) { policy.RetentionDays = Convert.ToInt32(this.RetentionInDays); } if (this.IsParameterBound(c => c.StorageAccountName)) { policy.StorageEndpoint = string.Format("https://{0}.blob.{1}", this.StorageAccountName, DefaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix)); } if (!string.IsNullOrEmpty(policy.StorageEndpoint)) { policy.StorageAccountAccessKey = SynapseAnalyticsClient.GetStorageKeys(policy.StorageEndpoint)[StorageKeyKind.Primary]; } else { policy.StorageEndpoint = null; } if (this.ShouldProcess(this.Name, string.Format(Resources.UpdatingSqlPoolThreatProtectionSetting, this.Name, this.WorkspaceName))) { var result = new PSSqlPoolSecurityAlertPolicy(SynapseAnalyticsClient.SetSqlPoolThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, this.Name, policy), this.ResourceGroupName, this.WorkspaceName, this.Name); WriteObject(result); } }
public override void ExecuteCmdlet() { try { if (SynapseAnalyticsClient.GetWorkspace(ResourceGroupName, Name) != null) { throw new AzPSInvalidOperationException(string.Format(Resources.SynapseWorkspaceExists, this.Name, this.ResourceGroupName)); } } catch (AzPSResourceNotFoundCloudException ex) { var innerException = ex.InnerException as ErrorResponseException; if (innerException.Body?.Error?.Code == "ResourceNotFound" || innerException.Body?.Error?.Message.Contains("ResourceNotFound") == true) { // account does not exists so go ahead and create one } else if (innerException.Body?.Error?.Code == "ResourceGroupNotFound" || innerException.Body?.Error?.Message.Contains("ResourceGroupNotFound") == true) { // resource group not found, throw error during creation. Don't throw from here. } else { // all other exceptions should be thrown throw; } } var defaultDataLakeStorageAccountUrl = string.Format( "https://{0}.dfs.{1}", this.DefaultDataLakeStorageAccountName, this.DefaultContext.Environment.StorageEndpointSuffix); var createParams = new Workspace { Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true), Identity = new ManagedIdentity { Type = ResourceIdentityType.SystemAssigned }, DefaultDataLakeStorage = new DataLakeStorageAccountDetails { AccountUrl = defaultDataLakeStorageAccountUrl, Filesystem = this.DefaultDataLakeStorageFilesystem }, SqlAdministratorLogin = this.SqlAdministratorLoginCredential.UserName, SqlAdministratorLoginPassword = this.SqlAdministratorLoginCredential.GetNetworkCredential().Password, ManagedVirtualNetwork = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? SynapseConstants.DefaultName : null, Location = this.Location, ManagedVirtualNetworkSettings = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? this.ManagedVirtualNetwork?.ToSdkObject() : null, ManagedResourceGroupName = this.ManagedResourceGroupName, Encryption = this.IsParameterBound(c => c.EncryptionKeyIdentifier) ? new EncryptionDetails { Cmk = new CustomerManagedKeyDetails { Key = new WorkspaceKeyDetails { Name = this.EncryptionKeyName, KeyVaultUrl = this.EncryptionKeyIdentifier } } } : null, WorkspaceRepositoryConfiguration = this.IsParameterBound(c => c.GitRepository) ? this.GitRepository.ToSdkObject() : null }; if (ShouldProcess(Name, string.Format(Resources.CreatingSynapseWorkspace, this.ResourceGroupName, this.Name))) { var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.CreateWorkspace( this.ResourceGroupName, this.Name, createParams)); this.WriteObject(workspace); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.IntegrationRuntimeName = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = InputObject.ResourceGroupName; this.WorkspaceName = InputObject.WorkspaceName; this.IntegrationRuntimeName = InputObject.Name; } if (AutoUpdate == null && !AutoUpdateDelayOffset.HasValue) { throw new PSArgumentException("No valid parameters."); } IntegrationRuntimeResource resource = SynapseAnalyticsClient.GetIntegrationRuntimeAsync( ResourceGroupName, WorkspaceName, IntegrationRuntimeName).ConfigureAwait(true).GetAwaiter().GetResult().IntegrationRuntime; WriteVerbose("Got integration runtime"); Action updateIntegrationRuntime = () => { var request = new UpdateIntegrationRuntimeRequest(); if (!string.IsNullOrEmpty(AutoUpdate)) { request.AutoUpdate = AutoUpdate; } WriteVerbose("Handled AutoUpdate"); if (AutoUpdateDelayOffset.HasValue) { request.UpdateDelayOffset = SafeJsonConvert.SerializeObject( AutoUpdateDelayOffset.Value, SynapseAnalyticsClient.GetSerializationSettings()); WriteVerbose(request.UpdateDelayOffset); } WriteVerbose("Handled AutoUpdateDelayOffset"); WriteObject(SynapseAnalyticsClient.UpdateIntegrationRuntimeAsync(ResourceGroupName, WorkspaceName, IntegrationRuntimeName, resource, request).ConfigureAwait(false).GetAwaiter().GetResult()); }; ConfirmAction( string.Format( CultureInfo.InvariantCulture, Resources.UpdatingIntegrationRuntime, IntegrationRuntimeName, WorkspaceName), IntegrationRuntimeName, updateIntegrationRuntime); }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.InputObject)) { var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = this.InputObject.Name; } if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ResourceName; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } if (this.ShouldProcess(this.WorkspaceName, string.Format(Resources.EnablingAdvancedDataSecurity, this.WorkspaceName))) { var policy = SynapseAnalyticsClient.GetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName); policy.State = SecurityAlertPolicyState.Enabled; if (!string.IsNullOrEmpty(policy.StorageEndpoint)) { policy.StorageAccountAccessKey = SynapseAnalyticsClient.GetStorageKeys(policy.StorageEndpoint)[StorageKeyKind.Primary]; } else { policy.StorageEndpoint = null; } SynapseAnalyticsClient.SetWorkspaceThreatDetectionPolicy(this.ResourceGroupName, this.WorkspaceName, policy); if (!DoNotConfigureVulnerabilityAssessment) { // Deploy arm template to enable VA - only if VA at server level is not defined var workspaceVa = SynapseAnalyticsClient.GetWorkspaceVulnerabilityAssessmentSettings(this.ResourceGroupName, this.WorkspaceName); if (string.IsNullOrEmpty(workspaceVa.StorageContainerPath)) { if (this.IsParameterBound(c => c.InputObject)) { SynapseAnalyticsClient.EnableWorkspaceVa(this.ResourceGroupName, this.WorkspaceName, this.InputObject.Location, this.DeploymentName); } else { var workspace = SynapseAnalyticsClient.GetWorkspace(this.ResourceGroupName, this.WorkspaceName); SynapseAnalyticsClient.EnableWorkspaceVa(this.ResourceGroupName, this.WorkspaceName, workspace.Location, this.DeploymentName); } } } var result = new WorkspaceAdvancedDataSecurityPolicy() { ResourceGroupName = this.ResourceGroupName, WorkspaceName = this.WorkspaceName, IsEnabled = true }; WriteObject(result); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (this.IsParameterBound(c => c.InputObject)) { this.ResourceGroupName = InputObject.ResourceGroupName; this.WorkspaceName = InputObject.WorkspaceName; this.Name = InputObject.Name; } if (string.Equals(Type, SynapseConstants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase)) { if (AuthKey != null || !string.IsNullOrWhiteSpace(SharedIntegrationRuntimeResourceId)) { throw new PSArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.InvalidIntegrationRuntimeSharing), "AuthKey"); } } IntegrationRuntimeResource resource = null; var isUpdate = false; try { resource = SynapseAnalyticsClient.GetIntegrationRuntimeAsync( ResourceGroupName, WorkspaceName, Name).ConfigureAwait(true).GetAwaiter().GetResult().IntegrationRuntime; isUpdate = true; if (Type != null && (resource.Properties is ManagedIntegrationRuntime ^ Type.Equals(SynapseConstants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase))) { throw new PSArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.IntegrationRuntimeWrongType, Name), "Type"); } if (AuthKey != null) { throw new PSArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.UpdateAuthKeyNotAllowed, Name), "AuthKey"); } } catch (CloudException e) { if (e.Response.StatusCode == HttpStatusCode.NotFound) { if (Type == null) { throw new PSArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.NeedIntegrationRuntimeType), "Type"); } resource = new IntegrationRuntimeResource(); if (Type.Equals(SynapseConstants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase)) { resource.Properties = new ManagedIntegrationRuntime(); } else { var selfHosted = new SelfHostedIntegrationRuntime(); if (AuthKey != null) { var authKey = ConvertToUnsecureString(AuthKey); selfHosted.LinkedInfo = new LinkedIntegrationRuntimeKeyAuthorization(new SecureString(authKey)); } resource.Properties = selfHosted; } } else { throw; } } if (!string.IsNullOrWhiteSpace(SharedIntegrationRuntimeResourceId)) { var selfHostedIr = resource.Properties as SelfHostedIntegrationRuntime; if (selfHostedIr != null) { selfHostedIr.LinkedInfo = new LinkedIntegrationRuntimeRbacAuthorization(SharedIntegrationRuntimeResourceId); } else { throw new PSArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.InvalidIntegrationRuntimeSharing), "SharedIntegrationRuntimeResourceId"); } } if (!string.IsNullOrWhiteSpace(Description)) { resource.Properties.Description = Description; } var managedIr = resource.Properties as ManagedIntegrationRuntime; if (managedIr != null) { HandleManagedIntegrationRuntime(managedIr); } var parameters = new CreatePSIntegrationRuntimeParameters() { ResourceGroupName = ResourceGroupName, WorkspaceName = WorkspaceName, Name = Name, IsUpdate = isUpdate, IntegrationRuntimeResource = resource, Force = Force.IsPresent, ConfirmAction = base.ConfirmAction }; WriteObject(SynapseAnalyticsClient.CreateOrUpdateIntegrationRuntime(parameters)); }
public override void ExecuteCmdlet() { try { if (SynapseAnalyticsClient.GetWorkspace(ResourceGroupName, Name) != null) { throw new SynapseException(string.Format(Resources.SynapseWorkspaceExists, this.Name, this.ResourceGroupName)); } } catch (NotFoundException ex) { var innerException = ex.InnerException as ErrorContractException; if (innerException.Body?.Error?.Code == "ResourceNotFound" || innerException.Body?.Error?.Message.Contains("ResourceNotFound") == true) { // account does not exists so go ahead and create one } else if (innerException.Body?.Error?.Code == "ResourceGroupNotFound" || innerException.Body?.Error?.Message.Contains("ResourceGroupNotFound") == true) { // resource group not found, throw error during creation. Don't throw from here. } else { // all other exceptions should be thrown throw; } } var defaultDataLakeStorageAccountUrl = string.Format( "https://{0}.dfs.{1}", this.DefaultDataLakeStorageAccountName, this.DefaultContext.Environment.StorageEndpointSuffix); var createParams = new Workspace { Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true), Identity = new ManagedIdentity { Type = ResourceIdentityType.SystemAssigned }, DefaultDataLakeStorage = new DataLakeStorageAccountDetails { AccountUrl = defaultDataLakeStorageAccountUrl, Filesystem = this.DefaultDataLakeStorageFilesystem }, SqlAdministratorLogin = this.SqlAdministratorLoginCredential.UserName, SqlAdministratorLoginPassword = this.SqlAdministratorLoginCredential.GetNetworkCredential().Password, ManagedVirtualNetwork = this.ManagedVirtualNetwork, Location = this.Location }; if (ShouldProcess(Name, string.Format(Resources.CreatingSynapseWorkspace, this.ResourceGroupName, this.Name))) { var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.CreateOrUpdateWorkspace( this.ResourceGroupName, this.Name, createParams)); if (!this.DisallowAllConnections.IsPresent) { SynapseAnalyticsClient.CreateOrUpdateWorkspaceFirewallRule( this.ResourceGroupName, this.Name, SynapseConstants.FilewallRuleAllowAll, new IpFirewallRuleInfo { StartIpAddress = SynapseConstants.AllowAllStartIpAddress, EndIpAddress = SynapseConstants.AllowAllEndIpAddress, }); } this.WriteObject(workspace); } }