17
17
Create, update, and delete registration assignments and registration definitions
18
18
#>
19
19
20
- function New-AzManagedServicesAssignmentWithId
21
- {
22
- [CmdletBinding ()]
23
- param (
24
- [string ] [Parameter ()] $Scope ,
25
- [string ] [Parameter ()] $RegistrationDefinitionResourceId ,
26
- [Guid ] [Parameter ()] $RegistrationAssignmentId
27
- )
28
-
29
- $profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider ]::Instance.Profile
30
- $cmdlet = New-Object - TypeName Microsoft.Azure.PowerShell.Cmdlets.ManagedServices.Commands.NewAzureRmManagedServicesAssignment
31
- $cmdlet.DefaultProfile = $profile
32
- $cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
33
-
34
- if (-not ([string ]::IsNullOrEmpty($Scope )))
35
- {
36
- $cmdlet.Scope = $Scope
37
- }
38
-
39
- if (-not ([string ]::IsNullOrEmpty($RegistrationDefinitionResourceId )))
40
- {
41
- $cmdlet.RegistrationDefinitionResourceId = $RegistrationDefinitionResourceId
42
- }
43
-
44
- if ($RegistrationAssignmentId -ne $null -and $RegistrationAssignmentId -ne [System.Guid ]::Empty)
45
- {
46
- $cmdlet.RegistrationAssignmentId = $RegistrationAssignmentId
47
- }
48
-
49
- $cmdlet.ExecuteCmdlet ()
50
- }
51
-
52
- function New-AzManagedServicesDefinitionWithId
20
+ function Test-ManagedServices_CRUD
53
21
{
54
- [CmdletBinding ()]
55
- param (
56
- [string ] [Parameter ()] $Name ,
57
- [string ] [Parameter ()] $ManagedByTenantId ,
58
- [string ] [Parameter ()] $PrincipalId ,
59
- [string ] [Parameter ()] $RoleDefinitionId ,
60
- [string ] [Parameter ()] $Description ,
61
- [Guid ] [Parameter ()] $RegistrationDefinitionId
62
- )
63
-
64
- $profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider ]::Instance.Profile
65
- $cmdlet = New-Object - TypeName Microsoft.Azure.PowerShell.Cmdlets.ManagedServices.Commands.NewAzureRmManagedServicesDefinition
66
- $cmdlet.DefaultProfile = $profile
67
- $cmdlet.CommandRuntime = $PSCmdlet.CommandRuntime
68
-
69
- if (-not ([string ]::IsNullOrEmpty($Description )))
22
+ $roleDefinitionId = " acdd72a7-3385-48ef-bd42-f606fba81ae7"
23
+ $managedByTenantId = " bab3375b-6197-4a15-a44b-16c41faa91d7"
24
+ $principalId = " d6f6c88a-5b7a-455e-ba40-ce146d4d3671"
25
+ $subscriptionId = " 002b3477-bfbf-4402-b377-6003168b75d3"
26
+ $displayName = " Resource display name"
27
+ $assignmentId = " 8af8768c-73c2-4993-86ae-7a45c9b232c6"
28
+ $definitionId = " 1ccdb215-959a-48b9-bd7c-0584d461ea6c"
29
+
30
+ # put definition
31
+ $definition = New-AzManagedServicesDefinition - ManagedByTenantId $managedByTenantId - RoleDefinitionId $roleDefinitionId - PrincipalId $principalId - DisplayName $displayName - Name $definitionId
32
+
33
+ Assert-AreEqual $definitionId $definition.Name
34
+ Assert-AreEqual $displayName $definition.Properties.DisplayName
35
+ Assert-AreEqual $managedByTenantId $definition.Properties.ManagedByTenantId
36
+ Assert-AreEqual $roleDefinitionId $definition.Properties.Authorization [0 ].RoleDefinitionId
37
+ Assert-AreEqual $principalId $definition.Properties.Authorization [0 ].PrincipalId
38
+
39
+ # get definition
40
+ $retrievedDefinition = Get-AzManagedServicesDefinition - Name $definitionId
41
+ Assert-NotNull $retrievedDefinition
42
+ Assert-AreEqual $definition.Id $retrievedDefinition.Id
43
+
44
+ # put assignment
45
+ $assignment = New-AzManagedServicesAssignment `
46
+ - RegistrationDefinitionId $definition.Id `
47
+ - Name $assignmentId
48
+ Assert-NotNull $assignment
49
+
50
+ # get assignment
51
+ $retrievedAssignment = Get-AzManagedServicesAssignment - Name $assignmentId - ExpandRegistrationDefinition
52
+ Assert-NotNull $retrievedAssignment
53
+ Assert-AreEqual $assignment.Id $retrievedAssignment.Id
54
+ Assert-AreEqual $definition.Id $retrievedAssignment.Properties.RegistrationDefinitionId
55
+
56
+ # remove assignment
57
+ Remove-AzManagedServicesAssignment - Name $assignmentId
58
+
59
+ # remove definition
60
+ Remove-AzManagedServicesDefinition - Name $definitionId
61
+
62
+ # list assignments
63
+ $assignments = Get-AzManagedServicesAssignment
64
+ Foreach ($assignment in $assignments )
70
65
{
71
- $cmdlet .Description = $Description
66
+ Assert-AreNotEqual ( $assignmentId , $assignment .Name )
72
67
}
73
68
74
- if (-not ([string ]::IsNullOrEmpty($Name )))
69
+ # list definitions
70
+ $definitions = Get-AzManagedServicesDefinition
71
+ Foreach ($definition in $definitions )
75
72
{
76
- $cmdlet .Name = $ Name
73
+ Assert-AreNotEqual ( $assignmentId , $assignment . Name)
77
74
}
78
-
79
- if (-not ([string ]::IsNullOrEmpty($ManagedByTenantId )))
80
- {
81
- $cmdlet.ManagedByTenantId = $ManagedByTenantId
82
- }
83
-
84
- if (-not ([string ]::IsNullOrEmpty($PrincipalId )))
85
- {
86
- $cmdlet.PrincipalId = $PrincipalId
87
- }
88
-
89
- if (-not ([string ]::IsNullOrEmpty($RoleDefinitionId )))
90
- {
91
- $cmdlet.RoleDefinitionId = $RoleDefinitionId
92
- }
93
-
94
- if ($RegistrationDefinitionId -ne $null -and $RegistrationDefinitionId -ne [System.Guid ]::Empty)
95
- {
96
- $cmdlet.RegistrationDefinitionId = $RegistrationDefinitionId
97
- }
98
-
99
- $cmdlet.ExecuteCmdlet ()
100
- }
101
-
102
- function Test-ManagedServices_CRUD
103
- {
104
- $roleDefinitionId = " acdd72a7-3385-48ef-bd42-f606fba81ae7" ;
105
- $managedByTenantId = " bab3375b-6197-4a15-a44b-16c41faa91d7" ;
106
- $principalId = " d6f6c88a-5b7a-455e-ba40-ce146d4d3671" ;
107
- $subscriptionId = " 002b3477-bfbf-4402-b377-6003168b75d3"
108
- $name = getAssetName
109
- $assignmentId = " 8af8768c-73c2-4993-86ae-7a45c9b232c6" ;
110
- $definitionId = " 1ccdb215-959a-48b9-bd7c-0584d461ea6c"
111
-
112
- # put def
113
- $definition = New-AzManagedServicesDefinitionWithId - ManagedByTenantId $managedByTenantId - RoleDefinitionId $roleDefinitionId - PrincipalId $principalId - Name $name - RegistrationDefinitionId $definitionId
114
-
115
- Assert-AreEqual $name $definition.Properties.Name
116
- Assert-AreEqual $managedByTenantId $definition.Properties.ManagedByTenantId
117
- Assert-AreEqual $roleDefinitionId $definition.Properties.Authorization [0 ].RoleDefinitionId
118
- Assert-AreEqual $principalId $definition.Properties.Authorization [0 ].PrincipalId
119
-
120
- # get def
121
- $getDef = Get-AzManagedServicesDefinition - Name $definitionId
122
- Assert-NotNull $getDef
123
- Assert-AreEqual $definition.Id $getDef.Id
124
-
125
- # put assignment
126
- $assignment = New-AzManagedServicesAssignmentWithId `
127
- - RegistrationDefinitionResourceId $definition.Id `
128
- - RegistrationAssignmentId $assignmentId
129
- Assert-NotNull $assignment
130
-
131
- # get assignment
132
- $getAssignment = Get-AzManagedServicesAssignment - Id $assignmentId - ExpandRegistrationDefinition
133
- Assert-NotNull $getAssignment
134
- Assert-AreEqual $assignment.Id $getAssignment.Id
135
- Assert-AreEqual $definition.Id $getAssignment.Properties.RegistrationDefinitionId
136
-
137
- # remove assignment
138
- Remove-AzManagedServicesAssignment - Id $assignmentId
139
-
140
- # remove definition
141
- Remove-AzManagedServicesDefinition - Id $definitionId
142
-
143
- # list assignments
144
- $assignments = Get-AzManagedServicesAssignment
145
- Foreach ($assignment in $assignments )
146
- {
147
- Assert-AreNotEqual ($assignmentId , $assignment.Name )
148
- }
149
-
150
- # list definitions
151
- $definitions = Get-AzManagedServicesDefinition
152
- Foreach ($definition in $definitions )
153
- {
154
- Assert-AreNotEqual ($definitionId , $definition.Name )
155
- }
156
75
}
0 commit comments