Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.VulnerabilityAssessment.Model;
using System;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet("Convert", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlPool + SynapseConstants.VulnerabilityAssessmentScan, DefaultParameterSetName = ConvertByVulnerabilityAssessmentScanRecordModelParameterSet,
SupportsShouldProcess = true)]
[OutputType(typeof(PSVulnerabilityAssessmentScanExportModel))]
public class ConvertAzureSynapseVulnerabilityAssessmentScan : SynapseManagementCmdletBase
{
private const string ConvertByVulnerabilityAssessmentScanRecordModelParameterSet = "ConvertByVulnerabilityAssessmentScanRecordModelParameterSet";
private const string ConvertByNameParameterSet = "ConvertByNameParameterSet";

[Parameter(Mandatory = true, ParameterSetName = ConvertByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ResourceGroupName)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = ConvertByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.WorkspaceName)]
[ResourceNameCompleter(ResourceTypes.Workspace, nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string WorkspaceName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = ConvertByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.SqlPoolName)]
[ResourceNameCompleter(
ResourceTypes.SqlPool,
nameof(ResourceGroupName),
nameof(WorkspaceName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = false, ParameterSetName = ConvertByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ScanId)]
[ValidateNotNullOrEmpty]
public string ScanId { get; set; }

[Parameter(ParameterSetName = ConvertByVulnerabilityAssessmentScanRecordModelParameterSet,
Mandatory = false,
ValueFromPipeline = true,
HelpMessage = "The scan record object to use in order to convert a Vulnerability Assessment scan")]
[ValidateNotNullOrEmpty]
public PSVulnerabilityAssessmentScanRecordModel InputObject { get; set; }

public override void ExecuteCmdlet()
{
if (string.IsNullOrEmpty(this.ResourceGroupName))
{
this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
}

string scanId = ScanId;

if (string.Equals(this.ParameterSetName, ConvertByVulnerabilityAssessmentScanRecordModelParameterSet, StringComparison.OrdinalIgnoreCase))
{
scanId = InputObject.ScanId;
}

if (string.IsNullOrEmpty(scanId))
{
throw new Exception(Properties.Resources.ScanIdParameterIsRequired);
}

var results = new PSVulnerabilityAssessmentScanExportModel(ResourceGroupName, WorkspaceName, Name, scanId);

WriteObject(results);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.VulnerabilityAssessment.Model;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlPool+ SynapseConstants.VulnerabilityAssessmentScanRecord,
DefaultParameterSetName = GetBySqlPoolObjectParameterSet)]
[OutputType(typeof(PSVulnerabilityAssessmentScanRecordModel))]
public class GetAzureSynapseSqlPoolVulnerabilityAssessmentScanRecord : SynapseManagementCmdletBase
{
private const string GetByNameParameterSet = "GetByNameParameterSet";
private const string GetBySqlPoolObjectParameterSet = "GetBySqlPoolObjectParameterSet";

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ResourceGroupName)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.WorkspaceName)]
[ResourceNameCompleter(ResourceTypes.Workspace, nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string WorkspaceName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = GetByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.SqlPoolName)]
[ResourceNameCompleter(
ResourceTypes.SqlPool,
nameof(ResourceGroupName),
nameof(WorkspaceName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ScanId)]
[ValidateNotNullOrEmpty]
public string ScanId { get; set; }

[Parameter(Mandatory = true, ParameterSetName = GetBySqlPoolObjectParameterSet, ValueFromPipeline = true,
HelpMessage = HelpMessages.SqlPoolObject)]
[ValidateNotNull]
public PSSynapseSqlPool SqlPoolObject { get; set; }

public override void ExecuteCmdlet()
{
if (SqlPoolObject != null)
{
var resourceIdentifier = new ResourceIdentifier(SqlPoolObject.Id);
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);
}

ICollection<PSVulnerabilityAssessmentScanRecordModel> results;

bool getScanRecordBySpecificScanId = MyInvocation.BoundParameters.ContainsKey(nameof(ScanId));
string scanId = ScanId;

if (getScanRecordBySpecificScanId)
{
results = new List<PSVulnerabilityAssessmentScanRecordModel>
{
Comment thread
zesluo marked this conversation as resolved.
Outdated
this.SynapseAnalyticsClient.GetVulnerabilityAssessmentScanRecord(this.ResourceGroupName, this.WorkspaceName, this.Name, scanId).ConfigureAwait(true).GetAwaiter().GetResult()
};
WriteObject(results);
}
else
{
results = SynapseAnalyticsClient.ListVulnerabilityAssessmentScanRecords(this.ResourceGroupName, this.WorkspaceName, this.Name).ConfigureAwait(true).GetAwaiter().GetResult();
WriteObject(results, true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Synapse.Common;
using Microsoft.Azure.Commands.Synapse.Models;
using Microsoft.Azure.Commands.Synapse.VulnerabilityAssessment.Model;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Synapse
{
[Cmdlet("Start", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + SynapseConstants.SynapsePrefix + SynapseConstants.SqlPool + SynapseConstants.VulnerabilityAssessmentScanInitialziation, DefaultParameterSetName = StartSqlPoolObjectParameterSet
, SupportsShouldProcess = true),OutputType(typeof(PSVulnerabilityAssessmentScanRecordModel))]
[OutputType(typeof(PSVulnerabilityAssessmentScanRecordModel))]
public class StartAzureSynapseSqlPoolVulnerabilityAssessmentScanInitialziation : SynapseManagementCmdletBase
Comment thread
zesluo marked this conversation as resolved.
Outdated
{
protected const string StartSqlPoolObjectParameterSet = "StartSqlPoolObjectParameterSet";
protected const string StartSqlPoolNameParameterSet = "StartSqlPoolNameParameterSet";

[Parameter(Mandatory = true, ParameterSetName = StartSqlPoolNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ResourceGroupName)]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = StartSqlPoolNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.WorkspaceName)]
[ResourceNameCompleter(ResourceTypes.Workspace, nameof(ResourceGroupName))]
[ValidateNotNullOrEmpty]
public string WorkspaceName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = StartSqlPoolNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.SqlPoolName)]
[ResourceNameCompleter(
ResourceTypes.SqlPool,
nameof(ResourceGroupName),
nameof(WorkspaceName))]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = false, ParameterSetName = StartSqlPoolNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ScanId)]
[ValidateNotNullOrEmpty]
public string ScanId { get; set; }

[Parameter(ValueFromPipeline = true, ParameterSetName = StartSqlPoolObjectParameterSet, Mandatory = true,
HelpMessage = "The Sql Pool object to get Vulnerability Assessment settings for")]
[ValidateNotNull]
public PSSynapseSqlPool SqlPoolObject { get; set; }

/// <summary>
/// Gets or sets whether or not to run this cmdlet in the background as a job
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void ExecuteCmdlet()
{
if (SqlPoolObject != null)
{
var resourceIdentifier = new ResourceIdentifier(SqlPoolObject.Id);
this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
this.WorkspaceName = resourceIdentifier.ParentResource;
this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
this.Name = resourceIdentifier.ResourceName;
}

string scanId = ScanId;

if (!MyInvocation.BoundParameters.ContainsKey(nameof(ScanId)))
{
// If the user didn't provide any scan ID for the new scan, we will generate one in the format of 20170109_130108
// Scan Id e.g 20170109_130108
scanId = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss");
}

if (string.IsNullOrEmpty(this.ResourceGroupName))
{
this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
}

// Run scan
this.SynapseAnalyticsClient.StartVulnerabilityAssessmentScan(ResourceGroupName, WorkspaceName, Name, scanId).ConfigureAwait(true).GetAwaiter().GetResult();

// Get scan record
var results = this.SynapseAnalyticsClient.GetVulnerabilityAssessmentScanRecord(ResourceGroupName, WorkspaceName, Name, scanId).ConfigureAwait(true).GetAwaiter().GetResult();
WriteObject(results, true);
}
}
}
2 changes: 2 additions & 0 deletions src/Synapse/Synapse/Common/HelpMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public static class HelpMessages
{
public const string ResourceGroupName = "Resource group name.";

public const string ScanId = "Scan Id.";

public const string Location = "Azure region where the resource should be created.";

public const string WorkspaceName = "Name of Synapse workspace.";
Expand Down
1 change: 1 addition & 0 deletions src/Synapse/Synapse/Common/ResourceTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public static class ResourceTypes
public const string Workspace = "Microsoft.Synapse/workspaces";
public const string SparkPool = "Microsoft.Synapse/workspaces/bigDataPools";
public const string SqlPool = "Microsoft.Synapse/workspaces/sqlPools";
public const string ScanId = "Microsoft.Synapse/workspaces/sqlPools/scanId";
Comment thread
zesluo marked this conversation as resolved.
Outdated
public const string SqlPoolRestorePoint = "Microsoft.Synapse/workspaces/sqlPools/sqlPoolRestorePoints";
public const string RecoverableSqlPool = "Microsoft.Synapse/workspaces/recoverableSqlPools";
public const string StorageAccount = "Microsoft.Storage/storageAccounts";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.Common.Attributes;

namespace Microsoft.Azure.Commands.Synapse.Model
{
/// <summary>
/// A class representing a Vulnerability Assessment scan error
/// </summary>
public class PSVulnerabilityAssessmentScanErrorModel
{
/// <summary>
/// Gets or sets the scan error code
/// </summary>
[Ps1Xml(Label = "Error code", Target = ViewControl.Table)]
public string Code { get; internal set; }

/// <summary>
/// Gets or sets the scan error message
/// </summary>
[Ps1Xml(Label = "Error message", Target = ViewControl.Table)]
public string Message { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.WindowsAzure.Commands.Common.Attributes;

namespace Microsoft.Azure.Commands.Synapse.Models
{

public class PSVulnerabilityAssessmentScanExportModel
{

/// <summary>
Comment thread
zesluo marked this conversation as resolved.
/// Gets or sets the resource group
/// </summary>
public string ResourceGroupName { get; set; }
/// <summary>
/// Gets or sets the Workspace name
/// </summary>
public string WorkspaceName { get; set; }

/// <summary>
/// Gets or sets the SqlPool name
/// </summary>
public string SqlPoolName { get; set; }

/// <summary>
/// Gets or sets a location of the exported report
/// </summary>
[Ps1Xml(Label = "Converted Report Location", Target = ViewControl.Table)]
public string ExportedReportLocation { get; set; }

/// <summary>
/// Gets or sets the scan ID
/// </summary>
public string ScanId { get; internal set; }

public PSVulnerabilityAssessmentScanExportModel(string ResourceGroupName, string WorkspaceName, string SqlPoolName, string ScanId, [Optional] string ExportedReportLocation)
{
this.ResourceGroupName = ResourceGroupName;
this.ExportedReportLocation = ExportedReportLocation;
this.ScanId = ScanId;

this.WorkspaceName = WorkspaceName;
this.SqlPoolName = SqlPoolName;
}
}
}

Loading