Skip to content

Commit 520232f

Browse files
authored
Merge pull request Azure#9176 from filizt/NewCmdlets
Blueprints Preview - Add new cmdlets
2 parents ae50903 + efa02da commit 520232f

File tree

67 files changed

+4621
-764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4621
-764
lines changed

src/Blueprint/Blueprint.Test/Blueprint.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<None Remove="UnitTests\**" />
1616
</ItemGroup>
1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.12.0-preview" />
18+
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.13.0-preview" />
1919
</ItemGroup>
2020
<ItemGroup>
2121
<ProjectReference Include="..\Blueprint\Blueprint.csproj" />

src/Blueprint/Blueprint.Test/ScenarioTests/BlueprintTests.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function Test-GetBlueprintWithDefinitionLocationNameAndVersion
2525
Assert-NotNull $blueprintByMG
2626
Assert-NotNull $blueprintByMG.Id
2727
Assert-NotNull $blueprintByMG.Scope
28-
Assert-NotNull $blueprintByMG.DefinitionLocationId
2928
Assert-NotNull $blueprintByMG.TargetScope
3029
}
3130

@@ -38,6 +37,5 @@ function Test-GetBlueprintWithDefinitionLocationNameAndLatestPublished
3837
Assert-NotNull $blueprintByMG
3938
Assert-NotNull $blueprintByMG.Id
4039
Assert-NotNull $blueprintByMG.Scope
41-
Assert-NotNull $blueprintByMG.DefinitionLocationId
4240
Assert-NotNull $blueprintByMG.TargetScope
4341
}

src/Blueprint/Blueprint/Az.Blueprint.psd1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,19 @@ NestedModules = @('.\Microsoft.Azure.PowerShell.Cmdlets.Blueprint.dll')
7474
FunctionsToExport = @()
7575

7676
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
77-
CmdletsToExport = 'Get-AzBlueprint', 'Get-AzBlueprintAssignment',
78-
'New-AzBlueprintAssignment', 'Remove-AzBlueprintAssignment',
79-
'Set-AzBlueprintAssignment'
77+
CmdletsToExport = 'Get-AzBlueprint',
78+
'Get-AzBlueprintAssignment',
79+
'New-AzBlueprintAssignment',
80+
'Remove-AzBlueprintAssignment',
81+
'Set-AzBlueprintAssignment',
82+
'New-AzBlueprint',
83+
'Publish-AzBlueprint',
84+
'New-AzBlueprintArtifact',
85+
'Get-AzBlueprintArtifact',
86+
'Export-AzBlueprintWithArtifact',
87+
'Import-AzBlueprintWithArtifact',
88+
'Set-AzBlueprintArtifact',
89+
'Set-AzBlueprint'
8090

8191
# Variables to export from this module
8292
# VariablesToExport = @()

src/Blueprint/Blueprint/Blueprint.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.props" />
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.12.0-preview" />
11+
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.13.0-preview" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

src/Blueprint/Blueprint/Blueprint.format.ps1xml

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,51 @@
1212
<ListItems>
1313
<ListItem>
1414
<Label>Name</Label>
15-
<PropertyName>BlueprintName</PropertyName>
15+
<PropertyName>Name</PropertyName>
1616
</ListItem>
1717
<ListItem>
1818
<Label>Id</Label>
1919
<PropertyName>Id</PropertyName>
2020
</ListItem>
2121
<ListItem>
22-
<Label>DefinitionLocationId</Label>
23-
<PropertyName>DefinitionLocationId</PropertyName>
22+
<PropertyName>SubscriptionId</PropertyName>
23+
<ItemSelectionCondition>
24+
<ScriptBlock>
25+
-not ([string]::IsNullOrEmpty($_.SubscriptionId))
26+
</ScriptBlock>
27+
</ItemSelectionCondition>
28+
</ListItem>
29+
<ListItem>
30+
<PropertyName>ManagementGroupId</PropertyName>
31+
<ItemSelectionCondition>
32+
<ScriptBlock>
33+
-not ([string]::IsNullOrEmpty($_.ManagementGroupId))
34+
</ScriptBlock>
35+
</ItemSelectionCondition>
2436
</ListItem>
2537
<ListItem>
2638
<Label>Version</Label>
27-
<PropertyName>Name</PropertyName>
39+
<PropertyName>Version</PropertyName>
2840
</ListItem>
2941
<ListItem>
3042
<PropertyName>Description</PropertyName>
3143
<ItemSelectionCondition>
3244
<ScriptBlock>
33-
$_.Description -ne $null -and $_.Description -ne &quot;&quot;
45+
-not ([string]::IsNullOrEmpty($_.Description))
3446
</ScriptBlock>
3547
</ItemSelectionCondition>
3648
</ListItem>
3749
<ListItem>
3850
<PropertyName>ChangeNotes</PropertyName>
3951
<ItemSelectionCondition>
4052
<ScriptBlock>
41-
$_.ChangeNotes -ne $null -and $_.ChangeNotes -ne &quot;&quot;
53+
-not ([string]::IsNullOrEmpty($_.ChangeNotes))
4254
</ScriptBlock>
4355
</ItemSelectionCondition>
4456
</ListItem>
4557
<ListItem>
4658
<Label>TimeCreated</Label>
47-
<ScriptBlock>$_.Status.TimeCreated.ToString("yyyy-MM-dd")</ScriptBlock>
59+
<ScriptBlock>$_.Status.TimeCreated.ToString()</ScriptBlock>
4860
</ListItem>
4961
<ListItem>
5062
<Label>TargetScope</Label>
@@ -81,24 +93,41 @@
8193
<PropertyName>Id</PropertyName>
8294
</ListItem>
8395
<ListItem>
84-
<Label>DefinitionLocationId</Label>
85-
<PropertyName>DefinitionLocationId</PropertyName>
96+
<PropertyName>SubscriptionId</PropertyName>
97+
<ItemSelectionCondition>
98+
<ScriptBlock>
99+
-not ([string]::IsNullOrEmpty($_.SubscriptionId))
100+
</ScriptBlock>
101+
</ItemSelectionCondition>
102+
</ListItem>
103+
<ListItem>
104+
<PropertyName>ManagementGroupId</PropertyName>
105+
<ItemSelectionCondition>
106+
<ScriptBlock>
107+
-not ([string]::IsNullOrEmpty($_.ManagementGroupId))
108+
</ScriptBlock>
109+
</ItemSelectionCondition>
86110
</ListItem>
87111
<ListItem>
88112
<Label>Versions</Label>
89113
<PropertyName>Versions</PropertyName>
114+
<ItemSelectionCondition>
115+
<ScriptBlock>
116+
$_.Versions.count -gt 0
117+
</ScriptBlock>
118+
</ItemSelectionCondition>
90119
</ListItem>
91120
<ListItem>
92121
<PropertyName>Description</PropertyName>
93122
<ItemSelectionCondition>
94123
<ScriptBlock>
95-
$_.Description -ne $null -and $_.Description -ne &quot;&quot;
124+
-not ([string]::IsNullOrEmpty($_.Description))
96125
</ScriptBlock>
97126
</ItemSelectionCondition>
98127
</ListItem>
99128
<ListItem>
100129
<Label>TimeCreated</Label>
101-
<ScriptBlock>$_.Status.TimeCreated.ToString("yyyy-MM-dd")</ScriptBlock>
130+
<ScriptBlock>$_.Status.TimeCreated.ToString()</ScriptBlock>
102131
</ListItem>
103132
<ListItem>
104133
<Label>TargetScope</Label>
@@ -142,7 +171,7 @@
142171
<PropertyName>Description</PropertyName>
143172
<ItemSelectionCondition>
144173
<ScriptBlock>
145-
$_.Description -ne $null -and $_.Description -ne &quot;&quot;
174+
-not ([string]::IsNullOrEmpty($_.Description))
146175
</ScriptBlock>
147176
</ItemSelectionCondition>
148177
</ListItem>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.Blueprint.Models;
16+
using Microsoft.Azure.Management.Blueprint.Models;
17+
using Microsoft.Azure.PowerShell.Cmdlets.Blueprint.Properties;
18+
using Microsoft.Rest.Azure;
19+
using Newtonsoft.Json.Linq;
20+
using System;
21+
using System.Collections;
22+
using System.Collections.Generic;
23+
using System.IO;
24+
using Microsoft.Azure.Commands.Common.Authentication;
25+
26+
namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
27+
{
28+
public class BlueprintArtifactsCmdletBase : BlueprintCmdletBase
29+
{
30+
protected Dictionary<string, ParameterValueBase> GetPolicyAssignmentParameters(Hashtable policyParameter)
31+
{
32+
var policyAssignmentParameters = new Dictionary<string, ParameterValueBase>();
33+
34+
foreach (var key in policyParameter.Keys)
35+
{
36+
var value = new ParameterValue(policyParameter[key], null);
37+
policyAssignmentParameters.Add(key.ToString(), value);
38+
}
39+
40+
return policyAssignmentParameters;
41+
}
42+
43+
protected string ValidateAndReturnFilePath(string filePath)
44+
{
45+
var templatePath = ResolveUserPath(filePath);
46+
47+
if (templatePath == null || !AzureSession.Instance.DataStore.FileExists(templatePath))
48+
{
49+
throw new FileNotFoundException(string.Format("Can't find file at " + filePath));
50+
}
51+
52+
return templatePath;
53+
}
54+
55+
protected Dictionary<string, ParameterValueBase> GetTemplateParametersFromFile(string validatedFilePath)
56+
{
57+
Dictionary<string, ParameterValueBase> parameters = new Dictionary<string, ParameterValueBase>();
58+
59+
JObject parsedJson = JObject.Parse(AzureSession.Instance.DataStore.ReadFileAsText(validatedFilePath));
60+
61+
//To-Do: This could be done better by creating a type and deserializing the JSON file through converters.
62+
var parametersHashtable = parsedJson["parameters"].ToObject<Dictionary<string, JObject>>();
63+
64+
foreach (var key in parametersHashtable.Keys)
65+
{
66+
var kvp = parametersHashtable[key];
67+
var value = kvp["value"].ToString();
68+
var paramValue = new ParameterValue(value);
69+
parameters.Add(key, paramValue);
70+
}
71+
72+
return parameters;
73+
}
74+
75+
protected void ThrowIfArtifactNotExist(string scope, string blueprintName, string artifactName)
76+
{
77+
PSArtifact artifact = null;
78+
79+
try
80+
{
81+
artifact = BlueprintClient.GetArtifact(scope, blueprintName, artifactName, null);
82+
}
83+
catch (Exception ex)
84+
{
85+
if (ex is CloudException cex && cex.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
86+
{
87+
// if exception is for a reason other than .NotFound, pass it to the caller.
88+
throw;
89+
}
90+
}
91+
92+
if (artifact == null)
93+
{
94+
throw new Exception(string.Format(Resources.ArtifactNotExist, artifactName, blueprintName));
95+
}
96+
}
97+
protected void ThrowIfArtifactExits(string scope, string blueprintName, string artifactName)
98+
{
99+
PSArtifact artifact = null;
100+
101+
try
102+
{
103+
artifact = BlueprintClient.GetArtifact(scope, blueprintName, artifactName, null);
104+
}
105+
catch (Exception ex)
106+
{
107+
if (ex is CloudException cex && cex.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
108+
{
109+
// if exception is for a reason other than .NotFound, pass it to the caller.
110+
throw;
111+
}
112+
}
113+
114+
if (artifact != null)
115+
{
116+
throw new Exception(string.Format(Resources.ArtifactExists, artifactName, blueprintName));
117+
}
118+
}
119+
}
120+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.Blueprint.Models;
16+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
17+
using System;
18+
using System.Management.Automation;
19+
using static Microsoft.Azure.Commands.Blueprint.Common.BlueprintConstants;
20+
21+
namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
22+
{
23+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "BlueprintArtifact", DefaultParameterSetName = ParameterSetNames.ArtifactsByBlueprint), OutputType(typeof(PSBlueprintAssignment))]
24+
public class GetAzureRmBlueprintArtifact : BlueprintArtifactsCmdletBase
25+
{
26+
#region Parameters
27+
[Parameter(ParameterSetName = ParameterSetNames.ArtifactsByBlueprint, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ArtifactName)]
28+
[ValidateNotNullOrEmpty]
29+
public string Name { get; set; }
30+
31+
[Parameter(ParameterSetName = ParameterSetNames.ArtifactsByBlueprint, Mandatory = true, ValueFromPipeline = true, HelpMessage = ParameterHelpMessages.BlueprintObject)]
32+
[ValidateNotNull]
33+
public PSBlueprintBase Blueprint { get; set; }
34+
35+
[Parameter(ParameterSetName = ParameterSetNames.ArtifactsByBlueprint, Mandatory = false, HelpMessage = "Version of the blueprint to get the artifacts from.")]
36+
[ValidateNotNullOrEmpty]
37+
public string BlueprintVersion { get; set; }
38+
#endregion
39+
40+
#region Cmdlet Overrides
41+
public override void ExecuteCmdlet()
42+
{
43+
var scope = Blueprint.Scope;
44+
45+
try
46+
{
47+
if (this.IsParameterBound(c => c.Name))
48+
{
49+
WriteObject(BlueprintClient.GetArtifact(scope, Blueprint.Name, Name, BlueprintVersion));
50+
}
51+
else
52+
{
53+
WriteObject(BlueprintClient.ListArtifacts(scope, Blueprint.Name, BlueprintVersion));
54+
}
55+
}
56+
catch (Exception ex)
57+
{
58+
WriteExceptionError(ex);
59+
}
60+
}
61+
#endregion
62+
}
63+
}

0 commit comments

Comments
 (0)