Skip to content

Commit 4493fc2

Browse files
authored
Merge pull request #16283 from Azure/bez/fix
Fix conflicts
2 parents 37010d9 + b7a961f commit 4493fc2

File tree

19 files changed

+320
-25
lines changed

19 files changed

+320
-25
lines changed

.ci-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"src/**/document/*",
6666
".ci-config.json",
6767
"tools/PrepareAutorestModule.ps1",
68-
"tools/SyncFromMainBranch.ps1"
68+
"tools/SyncFromMainBranch.ps1",
69+
"tools/GeneratedModuleList.txt"
6970
],
7071
"phases": []
7172
},

src/Compute/Compute/help/Invoke-AzVMRunCommand.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ Invoke a run command on the VM.
3838

3939
## EXAMPLES
4040

41-
### Example 1
42-
```
41+
### Example 1: Invoke a command on Windows
42+
```powershell
4343
PS C:\> Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1' -Parameter @{param1 = "var1"; param2 = "var2"}
4444
```
4545

46-
Invoke a run command of RunPowerShellScript with overriding the script 'sample.ps1' and the parameters on the VM of 'vmname' in resource group 'rgname'.
46+
Invoke a run command 'RunPowerShellScript' with overriding the script 'sample.ps1' on a Windows VM named 'vmname' in resource group 'rgname'. Var1 and var2 are defined as parameters in the sample.ps1. Parameter value can be string type only and script is responsible for converting them to other types if needed.
47+
48+
### Example 2: Invoke a command on Linux
49+
```powershell
50+
export param1=var1 param2=var2
51+
set -- var1 var2 var3
52+
53+
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -Name 'vmname' -CommandId 'RunShellScript' -ScriptPath 'sample.bash' -Parameter @{"param1" = "var1";"param2" = "var2"}
54+
echo This is a sample bash script
55+
echo Usage 1: Ordered parameters: $0 $1
56+
echo Usage 2: Named exports: $var1 $var2
57+
```
58+
59+
This command invokes a run command 'RunShellScript' with overriding the script 'sample.bash' on a Linux VM named 'vmname'. Var1 and var2 are defined as parameters in the sample.bash.
4760

4861
## PARAMETERS
4962

@@ -93,7 +106,7 @@ Accept wildcard characters: False
93106
```
94107
95108
### -Parameter
96-
The run command parameters.
109+
The run command parameters. Specify parameters as key/value pairs to be passed at script execution.
97110
98111
```yaml
99112
Type: System.Collections.Hashtable
@@ -138,7 +151,8 @@ Accept wildcard characters: False
138151
```
139152
140153
### -ScriptPath
141-
Path of the script to be executed. When this value is given, the given script will override the default script of the command.
154+
Path of the script to be executed. When this value is given, the given script will override the default script of the command.
155+
Path should point to a file from a local file system. The command will load it and send it for execution.
142156
143157
```yaml
144158
Type: System.String
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Microsoft.Azure.Commands.Sql.Common;
2+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
3+
using System.Collections.Generic;
4+
using Xunit;
5+
6+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
7+
{
8+
public class ResourceWildcardFilterHelperTests
9+
{
10+
[Fact]
11+
[Trait(Category.AcceptanceType, Category.CheckIn)]
12+
public void SqlSubResourceWildcardFilterTest()
13+
{
14+
ResourceWildcardFilterHelper wildcardFilterHelper = new ResourceWildcardFilterHelper();
15+
16+
// should match test01
17+
Assert.Single(wildcardFilterHelper.SqlSubResourceWildcardFilter("test01", ReturnedResources, "PropertyName1"));
18+
// should match none
19+
Assert.Empty(wildcardFilterHelper.SqlSubResourceWildcardFilter("test", ReturnedResources, "PropertyName1"));
20+
// should match all
21+
Assert.Equal(11, wildcardFilterHelper.SqlSubResourceWildcardFilter("t*t*", ReturnedResources, "PropertyName1").Count);
22+
// should match none
23+
Assert.Empty(wildcardFilterHelper.SqlSubResourceWildcardFilter("t*t", ReturnedResources, "PropertyName1"));
24+
// should match test01 and test11
25+
Assert.Equal(2, wildcardFilterHelper.SqlSubResourceWildcardFilter("t*1", ReturnedResources, "PropertyName1").Count);
26+
// should match all because empty value
27+
Assert.Equal(11, wildcardFilterHelper.SqlSubResourceWildcardFilter(string.Empty, ReturnedResources, "PropertyName1").Count);
28+
// should match all because null property name
29+
Assert.Equal(11, wildcardFilterHelper.SqlSubResourceWildcardFilter("anything", ReturnedResources, null).Count);
30+
}
31+
32+
private readonly List<TestResource> ReturnedResources = new List<TestResource>()
33+
{
34+
new TestResource("test01", "case01"),
35+
new TestResource("test02", "case02"),
36+
new TestResource("test03", "case03"),
37+
new TestResource("test04", "case04"),
38+
new TestResource("test05", "case05"),
39+
new TestResource("test06", "case06"),
40+
new TestResource("test07", "case07"),
41+
new TestResource("test08", "case08"),
42+
new TestResource("test09", "case09"),
43+
new TestResource("test10", "case10"),
44+
new TestResource("test11", "case11"),
45+
};
46+
}
47+
48+
internal class TestResource
49+
{
50+
public TestResource(string PropertyName1, string PropertyName2)
51+
{
52+
this.PropertyName1 = PropertyName1;
53+
this.PropertyName2 = PropertyName2;
54+
}
55+
56+
public string PropertyName1 { get; set; }
57+
58+
public string PropertyName2 { get; set; }
59+
}
60+
}

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed FirewallRuleName wildcard filtering in `Get-AzSqlServerFirewallRule` [#16199]
2122

2223
## Version 3.5.1
2324

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Management.Automation;
4+
5+
namespace Microsoft.Azure.Commands.Sql.Common
6+
{
7+
public class ResourceWildcardFilterHelper
8+
{
9+
public List<T> SqlSubResourceWildcardFilter<T>(string value, IEnumerable<T> resources, string propertyName)
10+
{
11+
if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(propertyName))
12+
{
13+
IEnumerable<T> output = resources;
14+
WildcardPattern pattern = new WildcardPattern(value, WildcardOptions.IgnoreCase);
15+
output = output.Where(t => IsMatch(t, propertyName, pattern));
16+
17+
return output.ToList();
18+
}
19+
else
20+
{
21+
return resources.ToList();
22+
}
23+
}
24+
25+
private bool IsMatch<T>(T resource, string property, WildcardPattern pattern)
26+
{
27+
var value = (string)GetPropertyValue(resource, property);
28+
return !string.IsNullOrEmpty(value) && pattern.IsMatch(value);
29+
}
30+
31+
private object GetPropertyValue<T>(T resource, string property)
32+
{
33+
System.Reflection.PropertyInfo pi = typeof(T).GetProperty(property);
34+
if (pi != null)
35+
{
36+
return pi.GetValue(resource, null);
37+
}
38+
39+
return null;
40+
}
41+
}
42+
}

src/Sql/Sql/FirewallRule/Cmdlet/GetAzureSqlServerFirewallRule.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Sql.Common;
1516
using Microsoft.Azure.Commands.Sql.FirewallRule.Model;
1617
using System.Collections.Generic;
1718
using System.Management.Automation;
@@ -44,6 +45,7 @@ public class GetAzureSqlServerFirewallRule : AzureSqlServerFirewallRuleCmdletBas
4445
protected override IEnumerable<AzureSqlServerFirewallRuleModel> GetEntity()
4546
{
4647
ICollection<AzureSqlServerFirewallRuleModel> results = null;
48+
ResourceWildcardFilterHelper filterHelper = new ResourceWildcardFilterHelper();
4749

4850
if (this.MyInvocation.BoundParameters.ContainsKey("FirewallRuleName") && !WildcardPattern.ContainsWildcardCharacters(FirewallRuleName))
4951
{
@@ -55,7 +57,7 @@ protected override IEnumerable<AzureSqlServerFirewallRuleModel> GetEntity()
5557
results = ModelAdapter.ListFirewallRules(this.ResourceGroupName, this.ServerName);
5658
}
5759

58-
return SubResourceWildcardFilter(FirewallRuleName, results);
60+
return filterHelper.SqlSubResourceWildcardFilter(FirewallRuleName, results, nameof(AzureSqlServerFirewallRuleModel.FirewallRuleName));
5961
}
6062

6163
/// <summary>

src/Storage/Storage.Management/help/Move-AzDataLakeGen2Item.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ dir2/file2 False 1024 2020-03-23 09:57:33Z rwxrw-rw-
5858

5959
This command move file 'dir1/file1' in 'filesystem1' to file 'dir2/file2' in 'filesystem2' in the same Storage account without prompt.
6060

61+
### Example 3: Move an item with Sas token
62+
```
63+
PS C:\> $sas = New-AzStorageContainerSASToken -Name $filesystemName -Permission rdw -Context $ctx
64+
65+
PS C:\> $sasctx = New-AzStorageContext -StorageAccountName $ctx.StorageAccountName -SasToken $sas
66+
67+
PS C:\> Move-AzDataLakeGen2Item -FileSystem $filesystemName -Path $itempath1 -DestFileSystem $filesystemName -DestPath "$($itempath2)$($sas)" -Context $sasctx
68+
69+
FileSystem Name: filesystem1
70+
71+
Path IsDirectory Length LastModified Permissions Owner Group
72+
---- ----------- ------ ------------ ----------- ----- -----
73+
dir2/file1 False 1024 2021-03-23 09:57:33Z rwxrw-rw- $superuser $superuser
74+
```
75+
76+
This first command creates a Sas token with rdw permission, the second command creates a Storage context from the Sas token, the 3rd command moves an item with the Sas token.
77+
This example use same Sastoken with rdw permission on both source and destication, if use 2 SAS token for source and destication, source need permission rd, destication need permission w.
78+
6179
## PARAMETERS
6280

6381
### -Context

src/Synapse/Synapse/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Updated `Set-AzSynapseNoteBook` and `Set-AzSynapseSparkJobDefinition` to support new parameter [-FolderPath]
2223

2324
## Version 0.18.0
2425
* Added cmdlets for Synapse Kusto pool

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Notebooks/SetAzureSynapseNotebook.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public class SetAzureSynapseNotebook : SynapseArtifactsCmdletBase
5757
[Alias("NotebookName")]
5858
public string Name { get; set; }
5959

60+
[Parameter(ValueFromPipelineByPropertyName = false, Mandatory = false, HelpMessage = HelpMessages.NoteBookFolderPath)]
61+
[ValidateNotNullOrEmpty]
62+
public string FolderPath { get; set; }
63+
6064
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = SetByNameAndSparkPool,
6165
Mandatory = true, HelpMessage = HelpMessages.SparkPoolName)]
6266
[Parameter(ValueFromPipelineByPropertyName = false, ParameterSetName = SetByObjectAndSparkPool,
@@ -134,6 +138,13 @@ public override void ExecuteCmdlet()
134138
notebookResource.Properties.SessionProperties = new NotebookSessionProperties(options["memory"] + "g", (int)options["cores"], options["memory"] + "g", (int)options["cores"], (int)options["nodeCount"]);
135139
}
136140

141+
if (this.IsParameterBound(c => c.FolderPath))
142+
{
143+
NotebookFolder folder = new NotebookFolder();
144+
folder.Name = this.FolderPath;
145+
notebookResource.Properties.Folder = folder;
146+
}
147+
137148
WriteObject(new PSNotebookResource(SynapseAnalyticsClient.CreateOrUpdateNotebook(this.Name, notebookResource), this.WorkspaceName));
138149
}
139150
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/SparkJobDefinitions/SetAzureSynapseSparkJobDefinition.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Azure.Analytics.Synapse.Artifacts.Models;
1516
using Microsoft.Azure.Commands.Common.Exceptions;
1617
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1718
using Microsoft.Azure.Commands.Synapse.Common;
@@ -54,6 +55,10 @@ public class SetAzureSynapseSparkJobDefinition : SynapseArtifactsCmdletBase
5455
[Alias("File")]
5556
public string DefinitionFile { get; set; }
5657

58+
[Parameter(ValueFromPipelineByPropertyName = false, Mandatory = false, HelpMessage = HelpMessages.SparkConfigurationFolderPath)]
59+
[ValidateNotNullOrEmpty]
60+
public string FolderPath { get; set; }
61+
5762
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
5863
public SwitchParameter AsJob { get; set; }
5964

@@ -67,7 +72,15 @@ public override void ExecuteCmdlet()
6772
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.SettingSynapseSparkJobDefinition, this.Name, this.WorkspaceName)))
6873
{
6974
string rawJsonContent = SynapseAnalyticsClient.ReadJsonFileContent(this.TryResolvePath(DefinitionFile));
70-
WriteObject(new PSSparkJobDefinitionResource(SynapseAnalyticsClient.CreateOrUpdateSparkJobDefinition(this.Name, rawJsonContent)));
75+
SparkJobDefinition sparkJobDefinition = JsonConvert.DeserializeObject<SparkJobDefinition>(rawJsonContent);
76+
SparkJobDefinitionResource sparkJobDefinitionResource = new SparkJobDefinitionResource(sparkJobDefinition);
77+
if (this.IsParameterBound(c => c.FolderPath))
78+
{
79+
SparkJobDefinitionFolder folder = new SparkJobDefinitionFolder();
80+
folder.Name = FolderPath;
81+
sparkJobDefinitionResource.Properties.Folder = folder;
82+
}
83+
WriteObject(new PSSparkJobDefinitionResource(SynapseAnalyticsClient.CreateOrUpdateSparkJobDefinition(this.Name, sparkJobDefinitionResource)));
7184
}
7285
}
7386
}

0 commit comments

Comments
 (0)