Skip to content

PSObject removal from resource cmdlets. #1498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using System;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using Microsoft.Rest;
using System;
using System.Runtime.InteropServices;
using Commands.Common.Authentication.Properties;
using Microsoft.Rest.Azure.Authentication;
using System.Management.Automation;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,11 +16,10 @@
using System;
using System.Linq;
using System.Management.Automation;
using System.Security;
using Commands.Common.Authentication.Properties;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using Microsoft.Rest.Azure.Authentication;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Factories
{
Expand Down
3 changes: 1 addition & 2 deletions src/CLU/Commands.Common.Authentication/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Factories
{
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.Authentication/JsonUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using System;
using System.Collections.Generic;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using Microsoft.Rest;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@
<data name="AccountNeedsToBeSpecified" xml:space="preserve">
<value>Account needs to be specified</value>
</data>
<data name="AzureDirectoryName" xml:space="preserve">
<value>Windows Azure Powershell</value>
</data>
<data name="CertificateNotFoundInStore" xml:space="preserve">
<value>No certificate was found in the certificate store with thumbprint {0}</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.Authentication/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Commands.Common.Authentication.Properties;
using System;
using System.IO;
using System.Linq;
using Commands.Common.Authentication.Properties;

namespace Microsoft.Azure.Commands.Common.Authentication
{
Expand Down
12 changes: 3 additions & 9 deletions src/CLU/Commands.Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,11 @@ protected virtual void WriteExceptionError(Exception ex)
WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.CloseError, null));
}

protected PSObject ConstructPSObject(string typeName, params object[] args)
protected PSObject ConstructPSObject(params object[] args)
{
return PowerShellUtilities.ConstructPSObject(typeName, args);
return PowerShellUtilities.ConstructPSObject(args);
}

protected void SafeWriteOutputPSObject(string typeName, params object[] args)
{
PSObject customObject = this.ConstructPSObject(typeName, args);
WriteObject(customObject);
}


private void FlushDebugMessages(bool record = false)
{
if (record)
Expand Down
9 changes: 2 additions & 7 deletions src/CLU/Commands.Common/PowerShellUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,12 @@ private static void ChangeForTargetEnvironment(Func<IEnumerable<string>, IEnumer
}
}

public static PSObject ConstructPSObject(string typeName, params object[] args)
public static PSObject ConstructPSObject(params object[] args)
{
Debug.Assert(args.Length % 2 == 0, "The parameter args length must be even number");

PSObject outputObject = new PSObject();

if (!string.IsNullOrEmpty(typeName))
{
outputObject.TypeNames.Add(typeName);
}


for (int i = 0, j = 0; i < args.Length / 2; i++, j += 2)
{
outputObject.Properties.Add(new PSNoteProperty(args[j].ToString(), args[j + 1]));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources
{
public class ResourceLock<TProperties> : Resource<TProperties>
{
public ResourceLock(Resource<TProperties> r)
: base(r)
{
}

/// <summary>
/// Gets or sets the lock id for the resource.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string LockId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
{
public class ResourcePolicyAssignment<TProperties> : Resource<TProperties>
{
public ResourcePolicyAssignment(Resource<TProperties> r)
: base(r)
{
}

/// <summary>
/// Gets or sets the policy assignment id for the resource.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string PolicyAssignmentId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
{
public class ResourcePolicyDefinition<TProperties> : Resource<TProperties>
{
public ResourcePolicyDefinition(Resource<TProperties> r)
: base(r)
{
}

/// <summary>
/// Gets or sets the policy definition id for the resource.
/// </summary>
[JsonProperty(Required = Required.Default)]
public string PolicyDefinitionId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources
/// </summary>
public class Resource<TProperties>
{
public Resource()
{

}

public Resource(Resource<TProperties> r)
{
this.ChangedTime = r.ChangedTime;
this.CreatedTime = r.CreatedTime;
this.ETag = r.ETag;
this.Id = r.Id;
this.Kind = r.Kind;
this.Location = r.Location;
this.Name = r.Name;
this.Plan = r.Plan;
this.Properties = r.Properties;
this.Sku = r.Sku;
this.Tags = r.Tags;
this.Type = r.Type;
}

/// <summary>
/// Gets or sets the properties.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal static class JTokenExtensions
/// </summary>
/// <param name="jtoken">The <see cref="JObject"/></param>
/// <param name="objectType">The type of the object.</param>
internal static PSObject ToPsObject(this JToken jtoken, string objectType = null)
internal static PSObject ToPsObject(this JToken jtoken)
{
if (jtoken == null)
{
Expand All @@ -63,12 +63,7 @@ internal static PSObject ToPsObject(this JToken jtoken, string objectType = null

var jobject = (JObject)jtoken;
var psObject = new PSObject();

if (!string.IsNullOrWhiteSpace(objectType))
{
psObject.TypeNames.Add(objectType);
}


foreach (var property in jobject.Properties())
{
psObject.Properties.Add(new PSNoteProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ private static JToken ToJToken(object value)
}
else
{
var properties = (valueAsPsObject.TypeNames.Any(typeName => typeName.EqualsInsensitively(Constants.MicrosoftAzureResource)))
? valueAsPsObject.Properties.Where(property => !PsObjectExtensions.PropertiesToRemove.ContainsKey(property.Name))
: valueAsPsObject.Properties.AsEnumerable();
var properties = valueAsPsObject.Properties.AsEnumerable();

foreach (var member in properties)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,10 @@ internal static PSObject ToPsObject(this Resource<JToken> resource)
{ "Sku", resource.Sku == null ? null : resource.Sku.ToJToken().ToPsObject() },
};

var resourceTypeName = resourceType == null && extensionResourceType == null
? null
: (resourceType + extensionResourceType).Replace('/', '.');

var psObject =
PowerShellUtilities.ConstructPSObject(
resourceTypeName,
objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value }));

psObject.TypeNames.Add(Constants.MicrosoftAzureResource);

return psObject;
}

Expand Down
Loading