diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/RemoveAzureResourceGroupCmdlet.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/RemoveAzureResourceGroupCmdlet.cs index 8bd7fef868ba..e9ac3857e493 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/RemoveAzureResourceGroupCmdlet.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/RemoveAzureResourceGroupCmdlet.cs @@ -59,6 +59,8 @@ public override void ExecuteCmdlet() ProjectResources.RemoveResourceGroupMessage, Name, () => ResourceManagerSdkClient.DeleteResourceGroup(Name)); + + WriteObject(true); } } } \ No newline at end of file diff --git a/src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj b/src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj index 36b619ed187f..b8827c0d30f1 100644 --- a/src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj +++ b/src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj @@ -82,9 +82,7 @@ ..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5945.28173-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll - False ..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.0-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll - True False @@ -143,9 +141,7 @@ ..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.1.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll - False ..\..\..\packages\WindowsAzure.Storage.6.0.0\lib\net40\Microsoft.WindowsAzure.Storage.dll - True False diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.ResourceManager.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.ResourceManager.cs index 7468ac88658e..2b7ae8d90c93 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.ResourceManager.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.ResourceManager.cs @@ -68,31 +68,31 @@ public virtual List FilterPSResources(BasePSResourceParameters param throw new ArgumentException(ProjectResources.ResourceDoesntExists); } - //resources.Add(getResult.Resource.ToPSResource(this, false)); + resources.Add(getResult.Resource.ToPSResource(this, false)); } else { - //PSTagValuePair tagValuePair = new PSTagValuePair(); - //if (parameters.Tag != null && parameters.Tag.Length == 1 && parameters.Tag[0] != null) - //{ - // tagValuePair = TagsConversionHelper.Create(parameters.Tag[0]); - // if (tagValuePair == null) - // { - // throw new ArgumentException(ProjectResources.InvalidTagFormat); - // } - //} - //ResourceListResult listResult = ResourceManagementClient.Resources.List(new ResourceListParameters - //{ - // ResourceGroupName = parameters.ResourceGroupName, - // ResourceType = parameters.ResourceType, - // TagName = tagValuePair.Name, - // TagValue = tagValuePair.Value - //}); + PSTagValuePair tagValuePair = new PSTagValuePair(); + if (parameters.Tag != null && parameters.Tag.Length == 1 && parameters.Tag[0] != null) + { + tagValuePair = TagsConversionHelper.Create(parameters.Tag[0]); + if (tagValuePair == null) + { + throw new ArgumentException(ProjectResources.InvalidTagFormat); + } + } + ResourceListResult listResult = ResourceManagementClient.Resources.List(new ResourceListParameters + { + ResourceGroupName = parameters.ResourceGroupName, + ResourceType = parameters.ResourceType, + TagName = tagValuePair.Name, + TagValue = tagValuePair.Value + }); - //if (listResult.Resources != null) - //{ - // resources.AddRange(listResult.Resources.Select(r => r.ToPSResource(this, false))); - //} + if (listResult.Resources != null) + { + resources.AddRange(listResult.Resources.Select(r => r.ToPSResource(this, false))); + } } return resources; } diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs index 99b130f5bb61..fd8a5e990045 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs @@ -17,7 +17,9 @@ using Microsoft.Azure.Commands.Common.Authentication.Models; using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components; using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities; +using Microsoft.Azure.Commands.Resources.Models.Authorization; using Microsoft.Azure.Management.Authorization; +using Microsoft.Azure.Management.Authorization.Models; using Microsoft.Azure.Management.Resources; using Microsoft.Azure.Management.Resources.Models; using Microsoft.WindowsAzure.Commands.Utilities.Common; @@ -133,6 +135,20 @@ public DeploymentExtended ProvisionDeploymentStatus(string resourceGroup, string ProvisioningState.Failed); } + internal List GetResourcePermissions(ResourceIdentifier identity) + { + PermissionGetResult permissionsResult = AuthorizationManagementClient.Permissions.ListForResource( + identity.ResourceGroupName, + identity.ToResourceIdentity()); + + if (permissionsResult != null) + { + return permissionsResult.Permissions.Select(p => p.ToPSPermission()).ToList(); + } + + return null; + } + private void WriteDeploymentProgress(string resourceGroup, string deploymentName, Deployment deployment) { const string normalStatusFormat = "Resource {0} '{1}' provisioning status is {2}"; diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesExtensions.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesExtensions.cs index eca1337ac129..7e8b5d7f3dde 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesExtensions.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesExtensions.cs @@ -12,18 +12,20 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.Resources.Models.Authorization; -using Microsoft.Azure.Commands.Tags.Model; -using Microsoft.Azure.Gallery; -using Microsoft.Azure.Management.Resources.Models; -using Microsoft.WindowsAzure.Commands.Utilities.Common; -using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Resources.Models.Authorization; +using Microsoft.Azure.Commands.Tags.Model; +using Microsoft.Azure.Gallery; +using Microsoft.Azure.Management.Authorization.Models; +using Microsoft.Azure.Management.Resources.Models; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Newtonsoft.Json; namespace Microsoft.Azure.Commands.Resources.Models { @@ -40,6 +42,33 @@ public static PSGalleryItem ToPSGalleryItem(this GalleryItem gallery) return psGalleryItem; } + public static PSResource ToPSResource(this GenericResourceExtended resource, ResourcesClient client, bool minimal) + { + ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); + return new PSResource + { + Name = identifier.ResourceName, + Location = resource.Location, + ResourceType = identifier.ResourceType, + ResourceGroupName = identifier.ResourceGroupName, + ParentResource = identifier.ParentResource, + Properties = JsonUtilities.DeserializeJson(resource.Properties), + PropertiesText = resource.Properties, + Tags = TagsConversionHelper.CreateTagHashtable(resource.Tags), + Permissions = minimal ? null : client.GetResourcePermissions(identifier), + ResourceId = identifier.ToString() + }; + } + + public static PSPermission ToPSPermission(this Permission permission) + { + return new PSPermission() + { + Actions = new List(permission.Actions), + NotActions = new List(permission.NotActions) + }; + } + private static string ConstructTemplateLinkView(TemplateLink templateLink) { if (templateLink == null) diff --git a/src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1 b/src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1 index 703d280f7907..afd4c80086b7 100644 --- a/src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1 +++ b/src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1 @@ -107,8 +107,8 @@ Creates the test environment needed to perform the Sql data masking tests function Create-DataMaskingTestEnvironment ($testSuffix) { $params = Get-SqlDataMaskingTestEnvironmentParameters $testSuffix - New-AzureRmResourceGroup -Name $params.rgname -Location "Australia East" -Force - New-AzureRmResourceGroupDeployment -ResourceGroupName $params.rgname -TemplateFile ".\Templates\sql-ddm-test-env-setup.json" -serverName $params.serverName -databaseName $params.databaseName -EnvLocation "Australia East" -administratorLogin $params.userName -Force + $rg = New-AzureRmResourceGroup -Name $params.rgname -Location "Australia East" -Force + $rgdeployment = New-AzureRmResourceGroupDeployment -ResourceGroupName $params.rgname -TemplateFile ".\Templates\sql-ddm-test-env-setup.json" -serverName $params.serverName -databaseName $params.databaseName -EnvLocation "Australia East" -administratorLogin $params.userName -Force $fullServerName = $params.serverName + ".database.windows.net" $uid = $params.userName