Skip to content

Commit

Permalink
Test another variant of base class
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Jan 18, 2024
1 parent f59ea2f commit 88ede21
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 31 deletions.
36 changes: 5 additions & 31 deletions source/Classes/001.PermissionBase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,12 @@
.SYNOPSIS
This is base class to use for all permission classes.
.PARAMETER State
The state of the permission.
.NOTES
The DSC properties specifies the attribute Mandatory but State was meant
to be attribute Key, but those attributes are not honored correctly during
compilation in the current implementation of PowerShell DSC. If the
attribute would have been left as Key then it would not have been possible
to add an identical instance of ServerPermission in two separate DSC
resource instances in a DSC configuration. The Key property only works
on the top level DSC properties. E.g. two resources instances of
SqlPermission in a DSC configuration trying to grant the database
permission 'AlterAnyDatabase' in two separate databases would have failed compilation
as a the property State would have been seen as "duplicate resource".
Since it is not possible to use the attribute Key the State property is
evaluate during runtime so that no two states are enforcing the same
permission.
The method Equals() returns $false if type is not the same on both sides
of the comparison. There was a thought to throw an exception if the object
being compared was of another type, but since there was issues with using
for example [ServerPermission[]], it was left out. This can be the correct
way since if moving for example [ServerPermission[]] to the left side and
the for example [ServerPermission] to the right side, then the left side
array is filtered with the matching values on the right side. This is the
normal behavior for other types.
This base class cannot have DSC properties. If it would have, then the
DSC resource that uses the complex type that use this as a parent class
would fail with the error:
The 'Permission' property with type 'DatabasePermission' of DSC resource class 'SqlDatabasePermission' is not supported."
.EXAMPLE
[PermissionBase] @{}
Expand All @@ -44,11 +23,6 @@
#>
class PermissionBase : IComparable, System.IEquatable[Object]
{
[DscProperty(Mandatory)]
[ValidateSet('Grant', 'GrantWithGrant', 'Deny')]
[System.String]
$State

PermissionBase ()
{
}
Expand Down
33 changes: 33 additions & 0 deletions source/Classes/002.DatabasePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,37 @@
.SYNOPSIS
The possible database permission states.
.PARAMETER State
The state of the permission.
.PARAMETER Permission
The permissions to be granted or denied for the user in the database.
.NOTES
The DSC properties specifies the attribute Mandatory but State was meant
to be attribute Key, but those attributes are not honored correctly during
compilation in the current implementation of PowerShell DSC. If the
attribute would have been left as Key then it would not have been possible
to add an identical instance of ServerPermission in two separate DSC
resource instances in a DSC configuration. The Key property only works
on the top level DSC properties. E.g. two resources instances of
SqlPermission in a DSC configuration trying to grant the database
permission 'AlterAnyDatabase' in two separate databases would have failed compilation
as a the property State would have been seen as "duplicate resource".
Since it is not possible to use the attribute Key the State property is
evaluate during runtime so that no two states are enforcing the same
permission.
The method Equals() returns $false if type is not the same on both sides
of the comparison. There was a thought to throw an exception if the object
being compared was of another type, but since there was issues with using
for example [ServerPermission[]], it was left out. This can be the correct
way since if moving for example [ServerPermission[]] to the left side and
the for example [ServerPermission] to the right side, then the left side
array is filtered with the matching values on the right side. This is the
normal behavior for other types.
.EXAMPLE
[DatabasePermission] @{}
Expand All @@ -20,6 +48,11 @@
#>
class DatabasePermission : PermissionBase
{
[DscProperty(Mandatory)]
[ValidateSet('Grant', 'GrantWithGrant', 'Deny')]
[System.String]
$State

[DscProperty(Mandatory)]
[AllowEmptyCollection()]
[ValidateSet(
Expand Down
33 changes: 33 additions & 0 deletions source/Classes/002.ServerPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,37 @@
.SYNOPSIS
The possible server permission states.
.PARAMETER State
The state of the permission.
.PARAMETER Permission
The permissions to be granted or denied for the user in the database.
.NOTES
The DSC properties specifies the attribute Mandatory but State was meant
to be attribute Key, but those attributes are not honored correctly during
compilation in the current implementation of PowerShell DSC. If the
attribute would have been left as Key then it would not have been possible
to add an identical instance of ServerPermission in two separate DSC
resource instances in a DSC configuration. The Key property only works
on the top level DSC properties. E.g. two resources instances of
SqlPermission in a DSC configuration trying to grant the database
permission 'AlterAnyDatabase' in two separate databases would have failed compilation
as a the property State would have been seen as "duplicate resource".
Since it is not possible to use the attribute Key the State property is
evaluate during runtime so that no two states are enforcing the same
permission.
The method Equals() returns $false if type is not the same on both sides
of the comparison. There was a thought to throw an exception if the object
being compared was of another type, but since there was issues with using
for example [ServerPermission[]], it was left out. This can be the correct
way since if moving for example [ServerPermission[]] to the left side and
the for example [ServerPermission] to the right side, then the left side
array is filtered with the matching values on the right side. This is the
normal behavior for other types.
.EXAMPLE
[ServerPermission] @{}
Expand All @@ -19,6 +47,11 @@
#>
class ServerPermission : PermissionBase
{
[DscProperty(Mandatory)]
[ValidateSet('Grant', 'GrantWithGrant', 'Deny')]
[System.String]
$State

[DscProperty(Mandatory)]
[AllowEmptyCollection()]
[ValidateSet(
Expand Down

0 comments on commit 88ede21

Please sign in to comment.