Skip to content

Commit 4d36076

Browse files
Merge pull request #5 from Francisco-Gamino/SC-Cmdlets
Adding Azure Automation Source Control cmdlets with docs.
2 parents a36cfad + 1f11393 commit 4d36076

31 files changed

+3392
-7
lines changed

src/ResourceManager/Automation/AzureRM.Automation.psd1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RequiredAssemblies = '.\Microsoft.Azure.Management.Automation.dll'
6363
# TypesToProcess = @()
6464

6565
# Format files (.ps1xml) to be loaded when importing this module
66-
# FormatsToProcess = @()
66+
FormatsToProcess = @(".\AzureRM.Automation.format.ps1xml")
6767

6868
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
6969
NestedModules = @('.\Microsoft.Azure.Commands.ResourceManager.Automation.dll')
@@ -135,7 +135,14 @@ CmdletsToExport = 'Get-AzureRMAutomationHybridWorkerGroup',
135135
'Get-AzureRmAutomationSoftwareUpdateConfiguration',
136136
'Remove-AzureRmAutomationSoftwareUpdateConfiguration',
137137
'Get-AzureRmAutomationSoftwareUpdateRun',
138-
'Get-AzureRmAutomationSoftwareUpdateMachineRun'
138+
'Get-AzureRmAutomationSoftwareUpdateMachineRun',
139+
'New-AzureRmAutomationSourceControl',
140+
'Get-AzureRmAutomationSourceControl',
141+
'Remove-AzureRmAutomationSourceControl',
142+
'Update-AzureRmAutomationSourceControl',
143+
'Start-AzureRmAutomationSourceControlSyncJob',
144+
'Get-AzureRmAutomationSourceControlSyncJob',
145+
'Get-AzureRmAutomationSourceControlSyncJobOutput'
139146

140147
# Variables to export from this module
141148
# VariablesToExport = @()
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Configuration>
3+
<ViewDefinitions>
4+
<View>
5+
<Name>SourceControl</Name>
6+
<ViewSelectedBy>
7+
<TypeName>Microsoft.Azure.Commands.Automation.Model.SourceControl</TypeName>
8+
</ViewSelectedBy>
9+
<TableControl>
10+
<TableHeaders>
11+
<TableColumnHeader><Label>Name</Label></TableColumnHeader>
12+
<TableColumnHeader><Label>SourceType</Label></TableColumnHeader>
13+
<TableColumnHeader><Label>Branch</Label></TableColumnHeader>
14+
<TableColumnHeader><Label>FolderPath</Label></TableColumnHeader>
15+
<TableColumnHeader><Label>AutoSync</Label></TableColumnHeader>
16+
<TableColumnHeader><Label>PublishRunbook</Label></TableColumnHeader>
17+
<TableColumnHeader><Label>RepoUrl</Label></TableColumnHeader>
18+
<TableColumnHeader><Label>Description</Label></TableColumnHeader>
19+
<TableColumnHeader><Label>CreationTime</Label></TableColumnHeader>
20+
<TableColumnHeader><Label>LastModifiedTime</Label></TableColumnHeader>
21+
</TableHeaders>
22+
<TableRowEntries>
23+
<TableRowEntry>
24+
<TableColumnItems>
25+
<TableColumnItem><PropertyName>Name</PropertyName></TableColumnItem>
26+
<TableColumnItem><PropertyName>SourceType</PropertyName></TableColumnItem>
27+
<TableColumnItem><PropertyName>Branch</PropertyName></TableColumnItem>
28+
<TableColumnItem><PropertyName>FolderPath</PropertyName></TableColumnItem>
29+
<TableColumnItem><PropertyName>AutoSync</PropertyName></TableColumnItem>
30+
<TableColumnItem><PropertyName>PublishRunbook</PropertyName></TableColumnItem>
31+
<TableColumnItem><PropertyName>RepoUrl</PropertyName></TableColumnItem>
32+
<TableColumnItem><PropertyName>Description</PropertyName></TableColumnItem>
33+
<TableColumnItem><PropertyName>CreationTime</PropertyName></TableColumnItem>
34+
<TableColumnItem><PropertyName>LastModifiedTime</PropertyName></TableColumnItem>
35+
</TableColumnItems>
36+
</TableRowEntry>
37+
</TableRowEntries>
38+
</TableControl>
39+
</View>
40+
<View>
41+
<Name>SourceControlSyncJob</Name>
42+
<ViewSelectedBy>
43+
<TypeName>Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJob</TypeName>
44+
</ViewSelectedBy>
45+
<TableControl>
46+
<TableHeaders>
47+
<TableColumnHeader><Label>SourceControlSyncJobId</Label></TableColumnHeader>
48+
<TableColumnHeader><Label>SyncType</Label></TableColumnHeader>
49+
<TableColumnHeader><Label>Status</Label></TableColumnHeader>
50+
<TableColumnHeader><Label>StartTime</Label><Width>10</Width></TableColumnHeader>
51+
<TableColumnHeader><Label>EndTime</Label><Width>10</Width></TableColumnHeader>
52+
</TableHeaders>
53+
<TableRowEntries>
54+
<TableRowEntry>
55+
<TableColumnItems>
56+
<TableColumnItem><PropertyName>SourceControlSyncJobId</PropertyName></TableColumnItem>
57+
<TableColumnItem><PropertyName>SyncType</PropertyName></TableColumnItem>
58+
<TableColumnItem><PropertyName>ProvisioningState</PropertyName></TableColumnItem>
59+
<TableColumnItem><ScriptBlock>$_.StartTime.ToString("MM/dd/yyyy hh:mm tt")</ScriptBlock></TableColumnItem>
60+
<TableColumnItem><ScriptBlock>$_.EndTime.ToString("MM/dd/yyyy hh:mm tt")</ScriptBlock></TableColumnItem>
61+
</TableColumnItems>
62+
</TableRowEntry>
63+
</TableRowEntries>
64+
</TableControl>
65+
</View>
66+
<View>
67+
<Name>SourceControlSyncJobRecord</Name>
68+
<ViewSelectedBy>
69+
<TypeName>Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJobRecord</TypeName>
70+
</ViewSelectedBy>
71+
<TableControl>
72+
<TableHeaders>
73+
<TableColumnHeader><Label>Status</Label></TableColumnHeader>
74+
<TableColumnHeader><Label>SyncType</Label></TableColumnHeader>
75+
<TableColumnHeader><Label>Exception</Label><Width>60</Width></TableColumnHeader>
76+
<TableColumnHeader><Label>StartTime</Label><Width>10</Width></TableColumnHeader>
77+
<TableColumnHeader><Label>EndTime</Label><Width>10</Width></TableColumnHeader>
78+
</TableHeaders>
79+
<TableRowEntries>
80+
<TableRowEntry>
81+
<TableColumnItems>
82+
<TableColumnItem><PropertyName>ProvisioningState</PropertyName></TableColumnItem>
83+
<TableColumnItem><PropertyName>SyncType</PropertyName></TableColumnItem>
84+
<TableColumnItem><PropertyName>Exception</PropertyName></TableColumnItem>
85+
<TableColumnItem><ScriptBlock>$_.StartTime.ToString("MM/dd/yyyy hh:mm tt")</ScriptBlock></TableColumnItem>
86+
<TableColumnItem><ScriptBlock>$_.EndTime.ToString("MM/dd/yyyy hh:mm tt")</ScriptBlock></TableColumnItem>
87+
</TableColumnItems>
88+
</TableRowEntry>
89+
</TableRowEntries>
90+
</TableControl>
91+
</View>
92+
</ViewDefinitions>
93+
</Configuration>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 Microsoft.Azure.Commands.Automation.Common;
16+
using Microsoft.Azure.Commands.Automation.Model;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
21+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
22+
{
23+
/// <summary>
24+
/// Gets azure automation source controls for a given account.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureRmAutomationSourceControl", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
27+
[OutputType(typeof(SourceControl))]
28+
public class GetAzureAutomationSourceControl : AzureAutomationBaseCmdlet
29+
{
30+
/// <summary>
31+
/// Gets or sets the variable source control.
32+
/// </summary>
33+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = true,
34+
ValueFromPipelineByPropertyName = true, HelpMessage = "The source control name.")]
35+
[ValidateNotNullOrEmpty]
36+
public string Name { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets the source control SourceType.
40+
/// </summary>
41+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, HelpMessage = "The source control type.")]
42+
[ValidateSet(Constants.SupportedSourceType.GitHub,
43+
Constants.SupportedSourceType.VsoGit,
44+
Constants.SupportedSourceType.VsoTfvc, IgnoreCase = true)]
45+
[ValidateNotNullOrEmpty]
46+
public string SourceType { get; set; }
47+
48+
/// <summary>
49+
/// Execute this cmdlet.
50+
/// </summary>
51+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
52+
protected override void AutomationProcessRecord()
53+
{
54+
if (this.ParameterSetName == AutomationCmdletParameterSets.ByName)
55+
{
56+
var result = this.AutomationClient.GetSourceControl(
57+
this.ResourceGroupName,
58+
this.AutomationAccountName,
59+
this.Name);
60+
61+
WriteObject(result);
62+
}
63+
64+
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll)
65+
{
66+
IEnumerable<SourceControl> result = null;
67+
var nextLink = string.Empty;
68+
69+
do
70+
{
71+
result = this.AutomationClient.ListSourceControl(
72+
this.ResourceGroupName,
73+
this.AutomationAccountName,
74+
this.SourceType,
75+
ref nextLink);
76+
77+
WriteObject(result, true);
78+
79+
} while (!string.IsNullOrEmpty(nextLink));
80+
}
81+
}
82+
}
83+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Microsoft.Azure.Commands.Automation.Common;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
21+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
22+
{
23+
/// <summary>
24+
/// Gets a Source Control Sync Job object for automation.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureRmAutomationSourceControlSyncJob")]
27+
[OutputType(typeof(Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJob),
28+
typeof(Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJobRecord))]
29+
public class GetAzureAutomationSourceControlSyncJob : AzureAutomationBaseCmdlet
30+
{
31+
/// <summary>
32+
/// Gets or sets the source control name of the job.
33+
/// </summary>
34+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
35+
HelpMessage = "The source control name of the job.")]
36+
[Alias("Name")]
37+
public string SourceControlName { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the source control sync job id.
41+
/// </summary>
42+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
43+
ValueFromPipeline = true, HelpMessage = "The source control sync job id.")]
44+
[Alias("SourceControlSyncJobId")]
45+
public Guid Id { get; set; }
46+
47+
/// <summary>
48+
/// Execute this cmdlet.
49+
/// </summary>
50+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
51+
protected override void AutomationProcessRecord()
52+
{
53+
if (this.Id != null && !Guid.Empty.Equals(this.Id))
54+
{
55+
// ByJobId
56+
var job = this.AutomationClient.GetSourceControlSyncJob(
57+
this.ResourceGroupName,
58+
this.AutomationAccountName,
59+
this.SourceControlName,
60+
this.Id);
61+
62+
this.WriteObject(job);
63+
}
64+
else
65+
{
66+
// ByAll
67+
IEnumerable<Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJob> jobs = null;
68+
var nextLink = string.Empty;
69+
70+
do
71+
{
72+
jobs = this.AutomationClient.ListSourceControlSyncJobs(
73+
this.ResourceGroupName,
74+
this.AutomationAccountName,
75+
this.SourceControlName,
76+
ref nextLink);
77+
78+
this.WriteObject(jobs, true);
79+
80+
} while (!string.IsNullOrEmpty(nextLink));
81+
}
82+
}
83+
}
84+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 Microsoft.Azure.Commands.Automation.Common;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
21+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
22+
{
23+
/// <summary>
24+
/// Gets a Source Control Sync Job object for automation.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureRmAutomationSourceControlSyncJobOutput")]
27+
[OutputType(typeof(Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJobStream),
28+
typeof(Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJobStreamRecord))]
29+
public class GetAzureAutomationSourceControlSyncJobOutput : AzureAutomationBaseCmdlet
30+
{
31+
/// <summary>
32+
/// Gets or sets the source control name of the job.
33+
/// </summary>
34+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
35+
HelpMessage = "The source control name.")]
36+
[Alias("Name")]
37+
public string SourceControlName { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the source contorl sync job id.
41+
/// </summary>
42+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
43+
HelpMessage = "The source control sync job id.")]
44+
[Alias("SourceControlSyncJobId")]
45+
public Guid Id { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the stream type of the job.
49+
/// </summary>
50+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
51+
HelpMessage = "The stream type. Defaults to Any.")]
52+
public SourceControlSyncJobStreamType Stream { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets the stream type of the job.
56+
/// </summary>
57+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
58+
HelpMessage = "The stream id.")]
59+
[Alias("SourceControlSyncJobStreamId")]
60+
public string StreamId { get; set; }
61+
62+
/// <summary>
63+
/// Execute this cmdlet.
64+
/// </summary>
65+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
66+
protected override void AutomationProcessRecord()
67+
{
68+
if (this.StreamId != null && !Guid.Empty.Equals(this.StreamId))
69+
{
70+
// ByStreamId
71+
var stream = this.AutomationClient.GetSourceControlSyncJobStreamRecord(
72+
this.ResourceGroupName,
73+
this.AutomationAccountName,
74+
this.SourceControlName,
75+
this.Id,
76+
this.StreamId);
77+
78+
this.WriteObject(stream);
79+
}
80+
else
81+
{
82+
// ByAll
83+
IEnumerable<Microsoft.Azure.Commands.Automation.Model.SourceControlSyncJobStream> streams = null;
84+
var nextLink = string.Empty;
85+
86+
do
87+
{
88+
streams = this.AutomationClient.GetSourceControlSyncJobStream(
89+
this.ResourceGroupName,
90+
this.AutomationAccountName,
91+
this.SourceControlName,
92+
this.Id,
93+
this.Stream.ToString(),
94+
ref nextLink);
95+
this.WriteObject(streams, true);
96+
97+
} while (!string.IsNullOrEmpty(nextLink));
98+
}
99+
}
100+
}
101+
}
102+

0 commit comments

Comments
 (0)