Skip to content

Commit f1cbf62

Browse files
authored
Merge pull request Azure#3387 from MsysTechnologiesllc/ali/add_daemon_and_databag_secret_key_options_in_chef_extension
Added daemon and databag secret-key options in ChefExtension for ASM and ARM commands.
2 parents 4d73bd0 + ebcbc36 commit f1cbf62

File tree

15 files changed

+2142
-495
lines changed

15 files changed

+2142
-495
lines changed

src/ResourceManager/Compute/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Updated Set-AzureRmVMChefExtension cmdlet to add following new options :
22+
- Daemon: Configures the chef-client service for unattended execution. e.g. -Daemon 'none' or e.g. -Daemon 'service'."
23+
- Secret: The encryption key used to encrypt and decrypt the data bag item values.
24+
- SecretFile: The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
2125

2226
## Version 2.5.0
2327
* Fix Get-AzureRmVM with -Status issue: Get-AzureRmVM throws an exception when Get-AzureRmVM lists multiple VMs and some of the VMs are deleted during Get-AzureRmVM is performed.

src/ResourceManager/Compute/Commands.Compute/Extension/Chef/SetAzureVMChefExtension.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineExtensionBaseCmdlet
4848
private string JsonAttributeTemplate = "custom_json_attr";
4949
private string ChefServiceIntervalTemplate = "chef_service_interval";
5050
private string RunListTemplate = "runlist";
51+
private string DaemonTemplate = "daemon";
52+
private string SecretTemplate = "encrypted_data_bag_secret";
5153

5254
[Parameter(
5355
Mandatory = true,
@@ -114,6 +116,27 @@ public string TypeHandlerVersion
114116
[ValidateNotNullOrEmpty]
115117
public string ChefServiceInterval { get; set; }
116118

119+
[Parameter(
120+
ValueFromPipelineByPropertyName = true,
121+
HelpMessage = "Configures the chef-client service for unattended execution. The node platform should be Windows." +
122+
"Options: 'none' or 'service'." +
123+
"none - Currently prevents the chef-client service from being configured as a service." +
124+
"service - Configures the chef-client to run automatically in the background as a service.")]
125+
[ValidateNotNullOrEmpty]
126+
public string Daemon { get; set; }
127+
128+
[Parameter(
129+
ValueFromPipelineByPropertyName = true,
130+
HelpMessage = "The encryption key used to encrypt and decrypt the data bag item values.")]
131+
[ValidateNotNullOrEmpty]
132+
public string Secret { get; set; }
133+
134+
[Parameter(
135+
ValueFromPipelineByPropertyName = true,
136+
HelpMessage = "The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.")]
137+
[ValidateNotNullOrEmpty]
138+
public string SecretFile { get; set; }
139+
117140
[Parameter(
118141
ValueFromPipelineByPropertyName = true,
119142
HelpMessage = "The Chef Server Node Runlist.")]
@@ -228,6 +251,7 @@ private Hashtable PublicConfiguration
228251
bool IsJsonAttributeEmpty = string.IsNullOrEmpty(this.JsonAttribute);
229252
bool IsChefServiceIntervalEmpty = string.IsNullOrEmpty(this.ChefServiceInterval);
230253
string BootstrapVersion = string.IsNullOrEmpty(this.BootstrapVersion) ? "" : this.BootstrapVersion;
254+
bool IsDaemonEmpty = string.IsNullOrEmpty(this.Daemon);
231255

232256
//Cases handled:
233257
// 1. When clientRb given by user and:
@@ -300,6 +324,11 @@ private Hashtable PublicConfiguration
300324
hashTable.Add(ChefServiceIntervalTemplate, ChefServiceInterval);
301325
}
302326

327+
if (this.Windows.IsPresent && !IsDaemonEmpty)
328+
{
329+
hashTable.Add(DaemonTemplate, this.Daemon);
330+
}
331+
303332
this.publicConfiguration = hashTable;
304333
}
305334

@@ -314,6 +343,12 @@ private Hashtable PrivateConfiguration
314343
if (this.privateConfiguration == null)
315344
{
316345
var hashTable = new Hashtable();
346+
347+
if (!string.IsNullOrEmpty(this.SecretFile))
348+
hashTable.Add(SecretTemplate, File.ReadAllText(this.SecretFile).TrimEnd('\r', '\n'));
349+
else if (!string.IsNullOrEmpty(this.Secret))
350+
hashTable.Add(SecretTemplate, this.Secret);
351+
317352
hashTable.Add(PrivateConfigurationTemplate, File.ReadAllText(this.ValidationPem).TrimEnd('\r', '\n'));
318353
this.privateConfiguration = hashTable;
319354
}
@@ -398,12 +433,30 @@ private void ValidateParameters()
398433
bool IsClientRbEmpty = string.IsNullOrEmpty(this.ClientRb);
399434
bool IsChefServerUrlEmpty = string.IsNullOrEmpty(this.ChefServerUrl);
400435
bool IsValidationClientNameEmpty = string.IsNullOrEmpty(this.ValidationClientName);
436+
bool IsDaemonEmpty = string.IsNullOrEmpty(this.Daemon);
401437
// Validate ClientRb or ChefServerUrl and ValidationClientName should exist.
402438
if (IsClientRbEmpty && (IsChefServerUrlEmpty || IsValidationClientNameEmpty))
403439
{
404440
throw new ArgumentException(
405441
"Required -ClientRb or -ChefServerUrl and -ValidationClientName options.");
406442
}
443+
444+
if (!IsDaemonEmpty)
445+
{
446+
bool IsDaemonValueInvalid = Array.IndexOf(new String[2] {"none", "service"}, this.Daemon) == -1;
447+
// Validation against the invalid use of Daemon option.
448+
if (IsDaemonValueInvalid || this.Linux.IsPresent)
449+
{
450+
throw new ArgumentException(
451+
"Invalid use of -Daemon option.");
452+
}
453+
}
454+
455+
if (!string.IsNullOrEmpty(this.SecretFile) && !File.Exists(this.SecretFile))
456+
{
457+
throw new FileNotFoundException(
458+
"File specified in -SecretFile option does not exist.");
459+
}
407460
}
408461

409462
public override void ExecuteCmdlet()

src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13015,6 +13015,24 @@ PS C:\> Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "Reso
1301513015
<maml:uri /></dev:type>
1301613016
<dev:defaultValue>None</dev:defaultValue>
1301713017
</command:parameter>
13018+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Secret</maml:name>
13019+
<maml:Description><maml:para>The encryption key used to encrypt and decrypt the data bag item values.
13020+
</maml:para>
13021+
</maml:Description>
13022+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13023+
<dev:type><maml:name>String</maml:name>
13024+
<maml:uri /></dev:type>
13025+
<dev:defaultValue>None</dev:defaultValue>
13026+
</command:parameter>
13027+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>SecretFile</maml:name>
13028+
<maml:Description><maml:para>The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
13029+
</maml:para>
13030+
</maml:Description>
13031+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13032+
<dev:type><maml:name>String</maml:name>
13033+
<maml:uri /></dev:type>
13034+
<dev:defaultValue>None</dev:defaultValue>
13035+
</command:parameter>
1301813036
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>ClientRb</maml:name>
1301913037
<maml:Description><maml:para>Specifies the full path of the Chef client.rb.
1302013038
</maml:para>
@@ -13185,6 +13203,36 @@ PS C:\&gt; Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "Reso
1318513203
<maml:uri /></dev:type>
1318613204
<dev:defaultValue>None</dev:defaultValue>
1318713205
</command:parameter>
13206+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Daemon</maml:name>
13207+
<maml:Description><maml:para>Configures the chef-client service for unattended execution. The node platform should be Windows.
13208+
Options: 'none' or 'service'
13209+
none - Currently prevents the chef-client service from being configured as a service.
13210+
service - Configures the chef-client to run automatically in the background as a service.
13211+
</maml:para>
13212+
</maml:Description>
13213+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13214+
<dev:type><maml:name>String</maml:name>
13215+
<maml:uri /></dev:type>
13216+
<dev:defaultValue>None</dev:defaultValue>
13217+
</command:parameter>
13218+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Secret</maml:name>
13219+
<maml:Description><maml:para>The encryption key used to encrypt and decrypt the data bag item values.
13220+
</maml:para>
13221+
</maml:Description>
13222+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13223+
<dev:type><maml:name>String</maml:name>
13224+
<maml:uri /></dev:type>
13225+
<dev:defaultValue>None</dev:defaultValue>
13226+
</command:parameter>
13227+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>SecretFile</maml:name>
13228+
<maml:Description><maml:para>The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
13229+
</maml:para>
13230+
</maml:Description>
13231+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13232+
<dev:type><maml:name>String</maml:name>
13233+
<maml:uri /></dev:type>
13234+
<dev:defaultValue>None</dev:defaultValue>
13235+
</command:parameter>
1318813236
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>ClientRb</maml:name>
1318913237
<maml:Description><maml:para>Specifies the full path of the Chef client.rb.
1319013238
</maml:para>
@@ -13310,6 +13358,36 @@ PS C:\&gt; Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "Reso
1331013358
<maml:uri /></dev:type>
1331113359
<dev:defaultValue>None</dev:defaultValue>
1331213360
</command:parameter>
13361+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Daemon</maml:name>
13362+
<maml:Description><maml:para>Configures the chef-client service for unattended execution. The node platform should be Windows.
13363+
Options: 'none' or 'service'
13364+
none - Currently prevents the chef-client service from being configured as a service.
13365+
service - Configures the chef-client to run automatically in the background as a service.
13366+
</maml:para>
13367+
</maml:Description>
13368+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13369+
<dev:type><maml:name>String</maml:name>
13370+
<maml:uri /></dev:type>
13371+
<dev:defaultValue>None</dev:defaultValue>
13372+
</command:parameter>
13373+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Secret</maml:name>
13374+
<maml:Description><maml:para>The encryption key used to encrypt and decrypt the data bag item values.
13375+
</maml:para>
13376+
</maml:Description>
13377+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13378+
<dev:type><maml:name>String</maml:name>
13379+
<maml:uri /></dev:type>
13380+
<dev:defaultValue>None</dev:defaultValue>
13381+
</command:parameter>
13382+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>SecretFile</maml:name>
13383+
<maml:Description><maml:para>The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
13384+
</maml:para>
13385+
</maml:Description>
13386+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
13387+
<dev:type><maml:name>String</maml:name>
13388+
<maml:uri /></dev:type>
13389+
<dev:defaultValue>None</dev:defaultValue>
13390+
</command:parameter>
1331313391
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>ClientRb</maml:name>
1331413392
<maml:Description><maml:para>Specifies the full path of the Chef client.rb.
1331513393
</maml:para>

src/ResourceManager/Compute/Commands.Compute/help/Set-AzureRmVMChefExtension.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Set-AzureRmVMChefExtension [-ResourceGroupName] <String> [-VMName] <String> [[-T
1919
[-ChefServerUrl <String>] [-ValidationClientName <String>] [-OrganizationName <String>]
2020
[-BootstrapVersion <String>] [-Linux] [[-Location] <String>] [[-Name] <String>]
2121
[[-AutoUpgradeMinorVersion] <Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]
22+
[-Secret <String>]
2223
```
2324

2425
### Windows
@@ -28,6 +29,7 @@ Set-AzureRmVMChefExtension [-ResourceGroupName] <String> [-VMName] <String> [[-T
2829
[-ChefServerUrl <String>] [-ValidationClientName <String>] [-OrganizationName <String>]
2930
[-BootstrapVersion <String>] [-Windows] [[-Location] <String>] [[-Name] <String>]
3031
[[-AutoUpgradeMinorVersion] <Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]
32+
[-Daemon <String>] [-SecretFile <String>]
3133
```
3234

3335
## DESCRIPTION
@@ -37,15 +39,15 @@ The **Set-AzureVMChefExtension** cmdlet adds the Chef extension to the virtual m
3739

3840
### Example 1: Add a Chef extension to a Windows virtual machine
3941
```
40-
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup001" -VMName "WindowsVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Windows
42+
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup001" -VMName "WindowsVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Daemon "service" -SecretFile "C:\my_encrypted_data_bag_secret" -Windows
4143
```
4244

4345
This command adds a Chef extension to a Windows virtual machine named WindowsVM001.
4446
When the virtual machine starts, Chef bootstraps the virtual machine to run Apache.
4547

4648
### Example 2: Add a Chef extension to a Linux virtual machine
4749
```
48-
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup002" -VMName "LinuxVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Linux
50+
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup002" -VMName "LinuxVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Secret "my_secret" -Linux
4951
```
5052

5153
This command adds a Chef extension to a Linux virtual machine named LinuxVM001.
@@ -284,6 +286,54 @@ Accept pipeline input: True (ByPropertyName)
284286
Accept wildcard characters: False
285287
```
286288
289+
### -Daemon
290+
Configures the chef-client service for unattended execution. The node platform should be Windows.
291+
Options: 'none' or 'service'
292+
none - Currently prevents the chef-client service from being configured as a service.
293+
service - Configures the chef-client to run automatically in the background as a service.
294+
295+
```yaml
296+
Type: String
297+
Parameter Sets: Windows
298+
Aliases:
299+
300+
Required: False
301+
Position: Named
302+
Default value: None
303+
Accept pipeline input: True (ByPropertyName)
304+
Accept wildcard characters: False
305+
```
306+
307+
### -Secret
308+
The encryption key used to encrypt and decrypt the data bag item values.
309+
310+
```yaml
311+
Type: String
312+
Parameter Sets: (All)
313+
Aliases:
314+
315+
Required: False
316+
Position: Named
317+
Default value: None
318+
Accept pipeline input: True (ByPropertyName)
319+
Accept wildcard characters: False
320+
```
321+
322+
### -SecretFile
323+
The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
324+
325+
```yaml
326+
Type: String
327+
Parameter Sets: (All)
328+
Aliases:
329+
330+
Required: False
331+
Position: Named
332+
Default value: None
333+
Accept pipeline input: True (ByPropertyName)
334+
Accept wildcard characters: False
335+
```
336+
287337
### -Windows
288338
Indicates that this cmdlet creates a Windows virtual machine.
289339

src/ServiceManagement/Common/Commands.ScenarioTest/ChefExtension/ChefExtensionTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
18-
{
18+
{
1919
public class ChefExtensionTests
2020
{
2121
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
@@ -33,6 +33,13 @@ public void TestSetAzureVMChefExtension()
3333
this.RunPowerShellTest("Test-SetAzureVMChefExtension");
3434
}
3535

36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestSetAzureVMChefExtensionAdvancedOptions()
39+
{
40+
this.RunPowerShellTest("Test-SetAzureVMChefExtensionAdvancedOptions");
41+
}
42+
3643
protected void SetupManagementClients()
3744
{
3845
var rdfeTestFactory = new RDFETestEnvironmentFactory();
@@ -53,7 +60,7 @@ protected void RunPowerShellTest(params string[] scripts)
5360
using (UndoContext context = UndoContext.Current)
5461
{
5562
context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));
56-
63+
5764
SetupManagementClients();
5865

5966
var modules = new List<string>
@@ -76,6 +83,6 @@ protected void RunPowerShellTest(params string[] scripts)
7683

7784
helper.RunPowerShellTest(scriptEnvPath, scripts);
7885
}
79-
}
86+
}
8087
}
8188
}

src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@
220220
<None Include="Resources\ChefExtension\tstorgnztn-validator.pem">
221221
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
222222
</None>
223+
<None Include="Resources\ChefExtension\encrypted_data_bag_secret">
224+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
225+
</None>
223226
<None Include="Resources\DiagnosticsExtension\DiagnosticsExtensionTests.ps1">
224227
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
225228
</None>
@@ -283,6 +286,9 @@
283286
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ChefExtensionTests\TestSetAzureVMChefExtension.json">
284287
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
285288
</None>
289+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ChefExtensionTests\TestSetAzureVMChefExtensionAdvancedOptions.json">
290+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
291+
</None>
286292
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DscExtensionTests\TestGetAzureVMDscExtension.json">
287293
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
288294
</None>

0 commit comments

Comments
 (0)