Skip to content

Commit 4505e41

Browse files
author
Hovsep Mkrtchyan
committed
Removed Gallery client reference from Resources CLU project
1 parent 35ec70c commit 4505e41

11 files changed

+34
-680
lines changed

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/GalleryTemplatesClient.cs

Lines changed: 0 additions & 477 deletions
This file was deleted.

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/PSGalleryItem.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourceClient.ResourceManager.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Management.Resources;
16+
using Microsoft.Azure.Management.Resources.Models;
17+
using Microsoft.Rest.Azure;
1518
using System;
1619
using System.Collections;
1720
using System.Collections.Generic;
1821
using System.IO;
1922
using System.Linq;
20-
using System.Text;
21-
using Microsoft.Azure.Commands.Tags.Model;
22-
using Microsoft.Azure.Management.Resources;
23-
using Microsoft.Azure.Management.Resources.Models;
24-
using Microsoft.Azure;
2523
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
26-
using Hyak.Common;
27-
using Microsoft.Rest.Azure;
2824

2925
namespace Microsoft.Azure.Commands.Resources.Models
3026
{
@@ -256,7 +252,7 @@ public virtual List<PSResource> FilterPSResources(BasePSResourceParameters param
256252
/// <returns>The created resource group</returns>
257253
public virtual PSResourceGroup CreatePSResourceGroup(CreatePSResourceGroupParameters parameters)
258254
{
259-
bool createDeployment = !string.IsNullOrEmpty(parameters.GalleryTemplateIdentity) || !string.IsNullOrEmpty(parameters.TemplateFile);
255+
bool createDeployment = !string.IsNullOrEmpty(parameters.TemplateFile);
260256
bool? resourceExists = ResourceManagementClient.ResourceGroups.CheckExistence(parameters.ResourceGroupName);
261257

262258
ResourceGroup resourceGroup = null;
@@ -369,10 +365,6 @@ private string GenerateDeploymentName(CreatePSResourceGroupDeploymentParameters
369365
{
370366
return Path.GetFileNameWithoutExtension(parameters.TemplateFile);
371367
}
372-
else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity))
373-
{
374-
return parameters.GalleryTemplateIdentity;
375-
}
376368
else
377369
{
378370
return Guid.NewGuid().ToString();

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ public partial class ResourcesClient
5656
public IResourceManagementClient ResourceManagementClient { get; set; }
5757

5858
public IAuthorizationManagementClient AuthorizationManagementClient { get; set; }
59-
60-
public GalleryTemplatesClient GalleryTemplatesClient { get; set; }
61-
59+
6260
public Action<string> VerboseLogger { get; set; }
6361

6462
public Action<string> ErrorLogger { get; set; }
@@ -137,32 +135,7 @@ public virtual PSResourceProvider UnregisterProvider(string providerName)
137135

138136
return response.ToPSResourceProvider();
139137
}
140-
141-
private string GetTemplate(string templateFile, string galleryTemplateName)
142-
{
143-
string template;
144-
145-
if (!string.IsNullOrEmpty(templateFile))
146-
{
147-
if (Uri.IsWellFormedUriString(templateFile, UriKind.Absolute))
148-
{
149-
template = GeneralUtilities.DownloadFile(templateFile);
150-
}
151-
else
152-
{
153-
template = FileUtilities.DataStore.ReadFileAsText(templateFile);
154-
}
155-
}
156-
else
157-
{
158-
Debug.Assert(!string.IsNullOrEmpty(galleryTemplateName));
159-
string templateUri = GalleryTemplatesClient.GetGalleryTemplateFile(galleryTemplateName);
160-
template = GeneralUtilities.DownloadFile(templateUri);
161-
}
162-
163-
return template;
164-
}
165-
138+
166139
private ResourceGroup CreateOrUpdateResourceGroup(string name, string location, Hashtable[] tags)
167140
{
168141
Dictionary<string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(tags, validate: true);
@@ -354,13 +327,6 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
354327
Uri = parameters.TemplateFile
355328
};
356329
}
357-
else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity))
358-
{
359-
deployment.Properties.TemplateLink = new TemplateLink
360-
{
361-
Uri = GalleryTemplatesClient.GetGalleryTemplateFile(parameters.GalleryTemplateIdentity)
362-
};
363-
}
364330
else
365331
{
366332
deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile);

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourceIdentifier.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,6 @@ public override string ToString()
143143
return resourceId.ToString();
144144
}
145145

146-
public ResourceIdentity ToResourceIdentity(string apiVersion)
147-
{
148-
if (string.IsNullOrEmpty(ResourceType))
149-
{
150-
throw new ArgumentNullException("ResourceType");
151-
}
152-
if (ResourceType.IndexOf('/') < 0)
153-
{
154-
throw new ArgumentException(ProjectResources.ResourceTypeFormat, "ResourceType");
155-
}
156-
157-
ResourcesResourceIdentity identity = new ResourcesResourceIdentity
158-
{
159-
ResourceName = ResourceName,
160-
ParentResourcePath = ParentResource,
161-
ResourceProviderNamespace = ResourceIdentifier.GetProviderFromResourceType(ResourceType),
162-
ResourceType = ResourceIdentifier.GetTypeFromResourceType(ResourceType),
163-
ResourceProviderApiVersion = apiVersion
164-
};
165-
166-
return identity;
167-
}
168-
169146
private void AppendIfNotNull(ref StringBuilder resourceId, string format, string value)
170147
{
171148
if (!string.IsNullOrEmpty(value))

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourceWithParameterBaseCmdlet.cs

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Resources.Models;
1616
using Microsoft.Azure.Commands.Utilities.Common;
17+
using Newtonsoft.Json;
1718
using System;
1819
using System.Collections;
1920
using System.Collections.Generic;
@@ -87,55 +88,7 @@ protected ResourceWithParameterBaseCmdlet()
8788
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
8889
[ValidateNotNullOrEmpty]
8990
public string TemplateUri { get; set; }
90-
91-
public object GetDynamicParameters()
92-
{
93-
if (!string.IsNullOrEmpty(TemplateFile) &&
94-
!TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase))
95-
{
96-
templateFile = TemplateFile;
97-
if (string.IsNullOrEmpty(TemplateParameterUri))
98-
{
99-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
100-
TemplateFile,
101-
TemplateParameterObject,
102-
TemplateParameterFile,
103-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
104-
}
105-
else
106-
{
107-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
108-
TemplateFile,
109-
TemplateParameterObject,
110-
TemplateParameterUri,
111-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
112-
}
113-
}
114-
else if (!string.IsNullOrEmpty(TemplateUri) &&
115-
!TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase))
116-
{
117-
templateUri = TemplateUri;
118-
if (string.IsNullOrEmpty(TemplateParameterUri))
119-
{
120-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
121-
TemplateUri,
122-
TemplateParameterObject,
123-
TemplateParameterFile,
124-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
125-
}
126-
else
127-
{
128-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
129-
TemplateUri,
130-
TemplateParameterObject,
131-
TemplateParameterUri,
132-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
133-
}
134-
}
135-
136-
return dynamicParameters;
137-
}
138-
91+
13992
protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
14093
{
14194
templateParameterObject = templateParameterObject ?? new Hashtable();
@@ -144,7 +97,7 @@ protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject
14497
string templateParameterFilePath = TemplateParameterFile;
14598
if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
14699
{
147-
var parametersFromFile = GalleryTemplatesClient.ParseTemplateParameterFileContents(templateParameterFilePath);
100+
var parametersFromFile = this.ParseTemplateParameterFileContents(templateParameterFilePath);
148101
parametersFromFile.ForEach(dp => templateParameterObject[dp.Key] = dp.Value.Value);
149102
}
150103

@@ -157,5 +110,27 @@ protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject
157110

158111
return templateParameterObject;
159112
}
113+
114+
private Dictionary<string, TemplateFileParameterV1> ParseTemplateParameterFileContents(string templateParameterFilePath)
115+
{
116+
Dictionary<string, TemplateFileParameterV1> parameters = new Dictionary<string, TemplateFileParameterV1>();
117+
118+
if (!string.IsNullOrEmpty(templateParameterFilePath) &&
119+
FileUtilities.DataStore.FileExists(templateParameterFilePath))
120+
{
121+
try
122+
{
123+
parameters = JsonConvert.DeserializeObject<Dictionary<string, TemplateFileParameterV1>>(
124+
FileUtilities.DataStore.ReadFileAsText(templateParameterFilePath));
125+
}
126+
catch (JsonSerializationException)
127+
{
128+
parameters = new Dictionary<string, TemplateFileParameterV1>(
129+
JsonConvert.DeserializeObject<TemplateFileParameterV2>(FileUtilities.DataStore.ReadFileAsText(templateParameterFilePath)).Parameters);
130+
}
131+
}
132+
133+
return parameters;
134+
}
160135
}
161136
}

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourcesBaseCmdlet.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public abstract class ResourcesBaseCmdlet : AzureRMCmdlet
2626
/// Field that holds the resource client instance
2727
/// </summary>
2828
private ResourcesClient resourcesClient;
29-
30-
/// <summary>
31-
/// Field that holds the gallery templates client instance
32-
/// </summary>
33-
private GalleryTemplatesClient galleryTemplatesClient;
34-
29+
3530
/// <summary>
3631
/// Field that holds the policies client instance
3732
/// </summary>
@@ -59,26 +54,6 @@ public ResourcesClient ResourcesClient
5954
set { this.resourcesClient = value; }
6055
}
6156

62-
/// <summary>
63-
/// Gets or sets the gallery templates client
64-
/// </summary>
65-
public GalleryTemplatesClient GalleryTemplatesClient
66-
{
67-
get
68-
{
69-
if (this.galleryTemplatesClient == null)
70-
{
71-
// since this accessor can be called before BeginProcessing, use GetCurrentContext if no
72-
// profile is passed in
73-
this.galleryTemplatesClient = new GalleryTemplatesClient(ClientFactory, DefaultContext);
74-
}
75-
76-
return this.galleryTemplatesClient;
77-
}
78-
79-
set { this.galleryTemplatesClient = value; }
80-
}
81-
8257
/// <summary>
8358
/// Gets or sets the policies client
8459
/// </summary>

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourcesExtensions.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,7 @@ public static PSResourceProviderLocationInfo ToPSResourceProviderLocationInfo(th
139139

140140
return result;
141141
}
142-
143-
public static PSGalleryItem ToPSGalleryItem(this GalleryItem gallery)
144-
{
145-
PSGalleryItem psGalleryItem = new PSGalleryItem();
146-
foreach (PropertyInfo prop in gallery.GetType().GetProperties())
147-
{
148-
(typeof(PSGalleryItem)).GetProperty(prop.Name).SetValue(psGalleryItem, prop.GetValue(gallery, null), null);
149-
}
150-
151-
return psGalleryItem;
152-
}
153-
142+
154143
// TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
155144
//public static PSDeploymentEventData ToPSDeploymentEventData(this EventData eventData)
156145
//{

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ValidatePSResourceGroupDeploymentParameters.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public class ValidatePSResourceGroupDeploymentParameters
2020
{
2121
public string ResourceGroupName { get; set; }
2222

23-
public string GalleryTemplateIdentity { get; set; }
24-
2523
public string TemplateFile { get; set; }
2624

2725
public Hashtable TemplateParameterObject { get; set; }

src/CLU/Microsoft.Azure.Commands.Resources/ProviderFeatures/GetAzureProviderFeatureCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override void ProcessRecord()
7272
break;
7373

7474
default:
75-
throw new ApplicationException(string.Format("Unknown parameter set encountered: '{0}'", this.ParameterSetName));
75+
throw new PSInvalidOperationException(string.Format("Unknown parameter set encountered: '{0}'", this.ParameterSetName));
7676
}
7777
}
7878
}

src/CLU/Microsoft.Azure.Commands.Resources/ResourceGroups/GetAzureResourceGroupCommand.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Resources.Models;
1616
using System.Collections.Generic;
17-
using System.IO;
1817
using System.Management.Automation;
19-
using System.Reflection;
20-
using Microsoft.Azure.Common.Authentication;
2118

2219
namespace Microsoft.Azure.Commands.Resources
2320
{

0 commit comments

Comments
 (0)