-
Notifications
You must be signed in to change notification settings - Fork 4.1k
add cmdlets Get/Start/convert-SynapseVulnerabilityAssessmentScan #13690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wyunchi-ms
merged 25 commits into
Azure:master
from
zesluo:zeshi/SynapseVulnerabilityAssessmentScan
Feb 3, 2021
Merged
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3e83191
SynapseVulnerabilityAssessmentScan
zesluo1 b1bc4ce
refine name
zesluo1 cbda9e6
refine function
zesluo1 4cda848
fix problem for StartAzureSynapseSqlPoolVulnerabilityAssessmentScan n…
zesluo1 3d1a05f
resolve conflicts
zesluo1 b066516
some draft codes
zesluo1 4ddc43e
resolve conflicets
zesluo1 0f32468
resolve confilct 2
zesluo1 bdc577c
removce strange sign
zesluo1 f4e8b5c
format code
zesluo1 739d295
refine function
zesluo1 e360705
add test
zesluo1 a33e9ca
add help doc
zesluo1 f072bdd
code refine
zesluo1 89924bf
format refine
zesluo1 c523f0f
update Az.Synapse.psd1
zesluo1 a4c7af6
Merge branch 'master' into zeshi/SynapseVulnerabilityAssessmentScan
zesluo1 a8cd993
add test json
zesluo1 dd3e48a
Merge branch 'zeshi/SynapseVulnerabilityAssessmentScan' of https://gi…
zesluo1 85779d3
refinde document
zesluo1 e30f65f
improve help examples
zesluo1 a3c7038
added test json
zesluo1 9acf177
added test json 2
zesluo1 e2695ba
improved test
zesluo1 549391c
add tests to credscansuppression
zesluo1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...pse/Commands/ManagementCommands/SqlPool/ConvertAzureSynapseVulnerabilityAssessmentScan.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
SupportsShouldProcess = true)] | ||
[OutputType(typeof(PSVulnerabilityAssessmentScanExportModel))] | ||
public class ConvertAzureSynapseVulnerabilityAssessmentScan : SynapseManagementCmdletBase | ||
{ | ||
private const string ConvertByVulnerabilityAssessmentScanRecordModelParameterSet = "ConvertByVulnerabilityAssessmentScanRecordModelParameterSet"; | ||
private const string ConvertByNameParameterSet = "ConvertByNameParameterSet"; | ||
|
||
[Parameter(Mandatory = false, HelpMessage = HelpMessages.ResourceGroupName)] | ||
zesluo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[ResourceGroupCompleter] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceGroupName { get; set; } | ||
|
||
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.WorkspaceName)] | ||
[ResourceNameCompleter(ResourceTypes.Workspace, nameof(ResourceGroupName))] | ||
[ValidateNotNullOrEmpty] | ||
public string WorkspaceName { get; set; } | ||
|
||
[Parameter(Mandatory = true, 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(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); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...nds/ManagementCommands/SqlPool/GetAzureSynapseSqlPoolVulnerabilityAssessmentScanRecord.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = GetByParentResourceParameterSet)] | ||
[OutputType(typeof(PSVulnerabilityAssessmentScanRecordModel))] | ||
public class GetAzureSynapseSqlPoolVulnerabilityAssessmentScanRecord : SynapseManagementCmdletBase | ||
{ | ||
private const string GetByNameParameterSet = "GetByNameParameterSet"; | ||
private const string GetByParentResourceParameterSet = "GetByResourceIdParameterSet"; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = GetByNameParameterSet, 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 = GetByParentResourceParameterSet, 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> | ||
{ | ||
zesluo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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); | ||
} | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...napse/Commands/ManagementCommands/SqlPool/StartAzureSynapseVulnerabilityAssessmentScan.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = SqlPoolObjectParameterSet | ||
, SupportsShouldProcess = true),OutputType(typeof(PSVulnerabilityAssessmentScanRecordModel))] | ||
[OutputType(typeof(PSVulnerabilityAssessmentScanRecordModel))] | ||
public class StartAzureSynapseSqlPoolVulnerabilityAssessmentScanInitialziation : SynapseManagementCmdletBase | ||
zesluo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
protected const string SqlPoolObjectParameterSet = "SqlPoolObjectParameterSet"; | ||
protected const string GetByNameParameterSet = "GetByNameParameterSet"; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = GetByNameParameterSet, 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, ParameterSetName = GetByNameParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.ScanId)] | ||
[ValidateNotNullOrEmpty] | ||
public string ScanId { get; set; } | ||
|
||
[Parameter(ValueFromPipeline = true, ParameterSetName = SqlPoolObjectParameterSet, Mandatory = true, | ||
HelpMessage = "The Sql Pool object to get Vulnerability Assessment settings for")] | ||
[ValidateNotNull] | ||
public PSSynapseSparkPool 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); | ||
|
||
// Get scan record | ||
var results = this.SynapseAnalyticsClient.GetVulnerabilityAssessmentScanRecord(ResourceGroupName, WorkspaceName, Name, scanId); | ||
WriteObject(results, true); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Synapse/Synapse/Models/PSVulnerabilityAssessmentScanErrorModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Synapse/Synapse/Models/PSVulnerabilityAssessmentScanExportModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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> | ||
zesluo marked this conversation as resolved.
Show resolved
Hide 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; } | ||
|
||
|
||
zesluo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/// <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; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.