Skip to content

Commit 4da0efc

Browse files
committed
piping
1 parent c442201 commit 4da0efc

File tree

9 files changed

+309
-88
lines changed

9 files changed

+309
-88
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Common;
20+
using Microsoft.Azure.Commands.Automation.Model;
21+
22+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
23+
{
24+
/// <summary>
25+
/// Gets azure automation variables for a given account.
26+
/// </summary>
27+
[Cmdlet(VerbsCommon.New, "AzureAutomationVariable")]
28+
[OutputType(typeof(Variable))]
29+
public class NewAzureAutomationVariable : AzureAutomationBaseCmdlet
30+
{
31+
/// <summary>
32+
/// Gets or sets the variable name.
33+
/// </summary>
34+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The variable name.")]
35+
[ValidateNotNullOrEmpty]
36+
public string Name { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets the variable IsEncrypted Property.
40+
/// </summary>
41+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The IsEncrypted property of the variable.")]
42+
[ValidateNotNull]
43+
public SwitchParameter Encrypted
44+
{
45+
get
46+
{
47+
return isEncrypted;
48+
}
49+
50+
set
51+
{
52+
isEncrypted = value;
53+
}
54+
}
55+
56+
private bool isEncrypted;
57+
58+
/// <summary>
59+
/// Gets or sets the variable description.
60+
/// </summary>
61+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the variable.")]
62+
public string Description { get; set; }
63+
64+
/// <summary>
65+
/// Gets or sets the variable value.
66+
/// </summary>
67+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The value of the variable.")]
68+
public string Value { get; set; }
69+
70+
/// <summary>
71+
/// Execute this cmdlet.
72+
/// </summary>
73+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
74+
protected override void AutomationExecuteCmdlet()
75+
{
76+
Variable variable = new Variable()
77+
{
78+
Name = this.Name,
79+
Encrypted = this.isEncrypted,
80+
Description = this.Description,
81+
Value = this.Value
82+
};
83+
84+
var ret = this.AutomationClient.NewVariable(this.AutomationAccountName, variable);
85+
86+
this.GenerateCmdletOutput(ret);
87+
}
88+
}
89+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Common;
20+
using Microsoft.Azure.Commands.Automation.Model;
21+
using Microsoft.Azure.Commands.Automation.Properties;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
24+
{
25+
/// <summary>
26+
/// Gets azure automation variables for a given account.
27+
/// </summary>
28+
[Cmdlet(VerbsCommon.Remove, "AzureAutomationVariable")]
29+
[OutputType(typeof(Variable))]
30+
public class RemoveAzureAutomationVariable : AzureAutomationBaseCmdlet
31+
{
32+
/// <summary>
33+
/// Gets or sets the variable name.
34+
/// </summary>
35+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The variable name.")]
36+
[ValidateNotNullOrEmpty]
37+
public string Name { get; set; }
38+
39+
[Parameter(Position = 2, HelpMessage = "Confirm the removal of the variable")]
40+
public SwitchParameter Force { get; set; }
41+
42+
/// <summary>
43+
/// Execute this cmdlet.
44+
/// </summary>
45+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
46+
protected override void AutomationExecuteCmdlet()
47+
{
48+
ConfirmAction(
49+
Force.IsPresent,
50+
string.Format(Resources.RemovingAzureAutomationResourceWarning, "Module"),
51+
string.Format(Resources.RemoveAzureAutomationResourceDescription, "Module"),
52+
Name,
53+
() =>
54+
{
55+
this.AutomationClient.RemoveVariable(this.AutomationAccountName, this.Name);
56+
});
57+
}
58+
}
59+
}

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAutomationVariable.cs renamed to src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationVariable.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ public class SetAzureAutomationVariable : AzureAutomationBaseCmdlet
3535
[ValidateNotNullOrEmpty]
3636
public string Name { get; set; }
3737

38-
/// <summary>
39-
/// Gets or sets the variable IsEncrypted Property.
40-
/// </summary>
41-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The IsEncrypted property of the variable.")]
42-
[ValidateNotNull]
43-
public bool IsEncrypted { get; set; }
44-
4538
/// <summary>
4639
/// Gets or sets the variable description.
4740
/// </summary>
@@ -63,7 +56,6 @@ protected override void AutomationExecuteCmdlet()
6356
Variable variable = new Variable()
6457
{
6558
Name = this.Name,
66-
IsEncrypted = this.IsEncrypted,
6759
Description = this.Description,
6860
Value = this.Value
6961
};

src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,16 @@
103103
<Compile Include="Cmdlet\GetAzureAutomationJobOutput.cs" />
104104
<Compile Include="Cmdlet\GetAzureAutomationVariable.cs" />
105105
<Compile Include="Cmdlet\GetAzureAutomationRunbook.cs" />
106-
<Compile Include="Cmdlet\SetAutomationVariable.cs" />
106+
<Compile Include="Cmdlet\NewAzureAutomationVariable.cs" />
107+
<Compile Include="Cmdlet\RemoveAzureAutomationVariable.cs" />
108+
<Compile Include="Cmdlet\SetAzureAutomationVariable.cs" />
107109
<Compile Include="Cmdlet\RemoveAzureAutomationSchedule.cs" />
108110
<Compile Include="Cmdlet\GetAzureAutomationSchedule.cs" />
109111
<Compile Include="Cmdlet\NewAzureAutomationSchedule.cs" />
110112
<Compile Include="Cmdlet\SetAzureAutomationSchedule.cs" />
111113
<Compile Include="Common\AutomationClient.cs" />
112114
<Compile Include="Common\AutomationCmdletParameterSet.cs" />
115+
<Compile Include="Common\AzureAutomationOperationException.cs" />
113116
<Compile Include="Common\Constants.cs" />
114117
<Compile Include="Common\IAutomationClient.cs" />
115118
<Compile Include="Common\Requires.cs" />

0 commit comments

Comments
 (0)