Skip to content

Clu #294

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 13 commits into from
Jan 4, 2016
Merged

Clu #294

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
14 changes: 7 additions & 7 deletions examples/resource-management/01-ResourceGroups.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
Param(
[string]$resourceGroupName,
[string]$resourceGroupLocation
[string]$groupName,
[string]$location
)

Write-Host "=== Managing Resource Groups in Azure ==="

Write-Host "1. Create a new resource group"
New-AzureRmResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation
New-AzureRmResourceGroup -Name $groupName -Location $location

Write-Host "2. Update group tags"
Set-AzureRmResourceGroup -Name $resourceGroupName -Tags @{Name = "testtag"; Value = "testval"}
Set-AzureRmResourceGroup -Name $groupName -Tags @{Name = "testtag"; Value = "testval"}

Write-Host "3. Get information about resource group"
$resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName
$resourceGroup = Get-AzureRmResourceGroup -Name $groupName
Write-Host $resourceGroup

Write-Host "4. List all resource groups in the subscription"
Get-AzureRmResourceGroup

Write-Host "5. Remove resource group"
Remove-AzureRmResourceGroup -Name $resourceGroupName -Force
Remove-AzureRmResourceGroup -Name $groupName -Force

Write-Host "6. Validations"
Assert-AreEqual $resourceGroup.ResourceGroupName $resourceGroupName
Assert-AreEqual $resourceGroup.ResourceGroupName $groupName
44 changes: 44 additions & 0 deletions examples/resource-management/02-Resource.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -e
printf "\n=== Managing Resources in Azure ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create --name "$groupName" --location "$location"
resourceName="CluResource"
destinationGroupName=$groupName"Destination"

printf "\n2. Registering Resource Provider Namespace.\n"
providerNamespace="Providers.Test"
azure resource provider register --ProviderNamespace $providerNamespace --Force

printf "\n3. Creating a new Resource: %s.\n" "$resourceName"
resourceType="$providerNamespace/statefulResources"
tags='[{"Name": "testtag", "Value": "testvalue"}]'
properties='{"administratorLogin": "adminuser", "administratorLoginPassword": "P@ssword1"}'
apiversion="2014-04-01"
azure resource create --Name $resourceName --Location $location --Tags "$tags" --ResourceGroupName $groupName --ResourceType $resourceType --PropertyObject "$properties" --ApiVersion $apiversion --Force

printf "\n4. Get information about Resource : %s.\n" "$resourceName"
resourceInfo=$(azure resource get -n $resourceName)
printf "\nValidating Resource name is: %s\n" "$resourceName"
[ $(echo $resourceInfo | jq '.Name' --raw-output) == "$resourceName" ]

printf "\n5. Find Resource with name = %s and type =.\n" "$resourceName" "$resourceType"
foundResource=$(azure resource find -n "clu" -t $resourceType)
printf "\nValidating Resource name is: %s\n" "$resourceName"
[ $(echo $foundResource | jq '.Name' --raw-output) == "$resourceName" ]

printf "\n6. Update Resource.\n"
tagsUpdate='[{"Name": "testtagUpdated", "Value": "testvalueUpdated"}]'
azure resource set --ResourceGroupName $groupName --ResourceName $resourceName --ResourceType $resourceType --Tags "$tagsUpdate" -f

printf "\n7. Move Resource to resource group: %s.\n" "$destinationGroupName"
azure group create --name "$destinationGroupName" --location "$location"
resourceId=$(echo $resourceInfo | jq '.Id')
arrayId="[$resourceId]"
azure resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f

printf "\n8. Removing resource: %s.\n" "$resourceName"
foundResource=$(azure resource find -n "clu" -t $resourceType)
resourceId=$(echo $foundResource | jq '.Id' --raw-output)
azure resource remove --Id "$resourceId" -f
19 changes: 19 additions & 0 deletions examples/resource-management/04-RoleAssignments.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Param(
[string]$groupName,
[string]$location
)

Write-Host "=== Managing Role Assignments in Azure ==="

Write-Host "1. Create a new resource group"
New-AzureRmResourceGroup -Name $groupName -Location $location

Write-Host "2. Creating a new Role Assignment."
$userId = ((Get-AzureRmADUser)[0]).Id
$definitionId = ((Get-AzureRmRoleDefinition)[0]).Id
$subscriptionId = (Get-AzureRmSubscription).SubscriptionId
$scope="/subscriptions/" + $subscriptionId + "/resourceGroups/" + $groupName
$roleAssignment = New-AzureRmRoleAssignment -ObjectId $userId -RoleDefinitionId $definitionId -Scope $scope

Write-Host "3. Delete last created Role Assignment."
Remove-AzureRmRoleAssignment -ObjectId $roleAssignment.ObjectId -Scope $scope -RoleDefinitionId $definitionId -f
21 changes: 21 additions & 0 deletions examples/resource-management/04-RoleAssignments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e
printf "\n=== Managing Role Assignments in Azure ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create --name "$groupName" --location "$location"

printf "\n2. Creating a new Role Assignment.\n"
users=$(azure ad users get)
userId=$(echo $users | cat | jq '.[0].Id' -s --raw-output)
roleDefinitions=$(azure role definition get)
roleDefinitionId=$(echo $roleDefinitions | cat | jq '.[0].Id' -s --raw-output)
subsciptions=$(azure subscription get)
subscriptionId=$(echo $subsciptions | cat | jq '.[0].SubscriptionId' -s --raw-output)
scope="/subscriptions/$subscriptionId/resourceGroups/$groupName"
azure role assignment create --ObjectId "$userId" --RoleDefinitionId "$roleDefinitionId" --Scope "$scope"

printf "\n3. Delete last created Role Assignment.\n"
assignments=$(azure role assignment get)
assignmentId=$(echo $assignments | cat | jq '.[-1].ObjectId' -s --raw-output)
azure role assignment remove --ObjectId "$assignmentId" --Scope "$scope" --RoleDefinitionId "$roleDefinitionId" -f
25 changes: 25 additions & 0 deletions examples/resource-management/05-RoleDefinitions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Param(
[string]$groupName,
[string]$location
)

Write-Host "=== Managing Role Definitions in Azure ==="

Write-Host "1. Create a new resource group"
New-AzureRmResourceGroup -Name $groupName -Location $location

Write-Host "2. Creating a new Role Definition."
$rd = New-AzureRmRoleDefinition -InputFile roleDefinition.json

Write-Host "3. Get information about Role Definitions."
Get-AzureRmRoleDefinition -Name $rd.Name

Write-Host "4. Update Role Definition."
$rd.Actions.Add('Microsoft.Authorization/*/write')
$updatedRd = Set-AzureRmRoleDefinition -Role $rd
Assert-NotNull $updatedRd

Write-Host "5. Delete Role Definition."
Remove-AzureRmRoleDefinition -Id $rd.Id -Force -PassThru
$readRd = Get-AzureRmRoleDefinition -Name $rd.Name
Assert-Null $readRd
21 changes: 21 additions & 0 deletions examples/resource-management/05-RoleDefinitions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e
printf "\n=== Managing Role Definitions in Azure ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create --name "$groupName" --location "$location"

printf "\n2. Creating a new Role Definition.\n"
roleDefinition=$(azure role definition create --inputfile $BASEDIR/resource-management/roleDefinition.json)

printf "\n3. Get information about Role Definitions.\n"
roleDefinitionName=$(echo $roleDefinition | jq '.Name' --raw-output)
azure role definition get -n $roleDefinitionName

printf "\n4. Update Role Definition.\n"
updatedRoleDefinition=$(echo $roleDefinition | jq '.Actions |= .+ ["Microsoft.Authorization/*/write"]')
azure role definition set --Role "$updatedRoleDefinition"

printf "\n5. Delete Role Definition.\n"
roleDefinitionId=$(echo $roleDefinition | jq '.Id' --raw-output)
azure role definition remove --Id $roleDefinitionId --PassThru -f
10 changes: 10 additions & 0 deletions examples/resource-management/roleDefinition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Name": "CluRoleDefinition",
"Description": "Super awesome Clu Role Definition",
"Actions": [
"Microsoft.Authorization/*/read",
"Microsoft.Support/*"
],
"NotActions": [],
"AssignableScopes": [ "/subscriptions/3ca49042-782a-4cc9-89b5-ee1b487fe115" ]
}
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.Authentication/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"System.Linq": "4.0.1-beta-23516",
"Microsoft.CLU": "1.0.0",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.ScenarioTest/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime.Azure": "2.6.0",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common.Storage/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.Common/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Microsoft.CLU": "1.0.0",
"Commands.Common.Authentication": "",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ internal static PSObject ToPsObject(this JToken jtoken)
{
return null;
}

// TODO CORECLR does not exist in coreclr50
/*if (jtoken.Type != JTokenType.Object)

if (jtoken.Type != JTokenType.Object)
{
return new PSObject(JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken));
}*/
var retObject = new PSObject();
retObject.Properties.Add(new PSNoteProperty(
name: JTokenExtensions.ConvertToPascalCase(propertyName: jtoken.Type.ToString()),
value: JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken)));
return retObject;
}

var jobject = (JObject)jtoken;
var psObject = new PSObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
/// <summary>
/// Gets or sets the resource name parameter.
/// </summary>
[Alias("Name")]
[Alias("Name", "n")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name. e.g. to specify a database MyServer/MyDatabase.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name. e.g. to specify a database MyServer/MyDatabase.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name. e.g. to specify a database MyServer/MyDatabase.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase
[ValidateNotNullOrEmpty]
[Alias("sku")]
public Hashtable SkuObject { get; set; }



/// <summary>
/// Gets or sets the tags.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,12 @@ public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBase
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
[Alias("f")]
public SwitchParameter Force { get; set; }

/// <summary>
/// Gets or sets the subscription id.
/// </summary>
public Guid SubscriptionId { get; set; }


/// <summary>
/// Initializes the default subscription id if needed.
/// </summary>
public ResourceManipulationCmdletBase()
{
if (string.IsNullOrEmpty(this.ResourceId))
{
this.SubscriptionId = DefaultContext.Subscription.Id;
}
}

protected override void OnProcessRecord()
Expand Down Expand Up @@ -149,7 +140,7 @@ protected string GetResourceId()
private string GetResourceIdWithoutParentResource()
{
return ResourceIdUtility.GetResourceId(
subscriptionId: this.SubscriptionId,
subscriptionId: DefaultContext.Subscription.Id,
resourceGroupName: this.ResourceGroupName,
resourceType: this.ResourceType,
resourceName: this.ResourceName,
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.ResourceManager.Cmdlets/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Commands.Common": "",
"Commands.ResourceManager.Common": "",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Commands.ResourceManager.Common/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"Commands.ResourceManager.Common": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime.Azure": "2.6.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Compute.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"Microsoft.Azure.Management.Network": "3.0.3-preview",
"Microsoft.Azure.Management.Storage": "4.0.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.Azure.Commands.Compute/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Commands.Common.Storage": "",
"Commands.ResourceManager.Common": "",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Commands.Common.Storage": "",
"Commands.ResourceManager.Common": "",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand Down
4 changes: 2 additions & 2 deletions src/CLU/Microsoft.Azure.Commands.Network/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.Azure.Management.Network": "3.0.3-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime.Azure": "2.6.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
4 changes: 2 additions & 2 deletions src/CLU/Microsoft.Azure.Commands.Profile.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime.Azure": "2.6.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
4 changes: 2 additions & 2 deletions src/CLU/Microsoft.Azure.Commands.Profile/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"Commands.ResourceManager.Common": "",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime.Azure": "2.6.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
8 changes: 4 additions & 4 deletions src/CLU/Microsoft.Azure.Commands.Resources.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"Commands.ScenarioTests.ResourceManager.Common": "",
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Commands.Resources": "",
"Microsoft.Azure.Graph.RBAC": "2.1.0-preview",
"Microsoft.Azure.Management.Authorization": "2.1.0-preview",
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.9.0",
"Microsoft.Rest.ClientRuntime.Azure": "2.6.0",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
Expand Down
Loading