Add a default implementation of a DSC Resource #82
michaeltlombardi
started this conversation in
Ideas
Replies: 1 comment
-
|
Additional benefits for this approach:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
As a follow up to #81, if there is a defined interface for basic DSC Resources, it would be even more useful to have a starting point for the implementation. This would reduce the amount of copy-paste and boilerplate code needed by DSC Resource authors while helping to ensure a more standardized experience for users as well.
By way of example, a common pattern I noticed when inspecting DSC Resources while working on the integration code for Puppet is that many DSC Resources reimplement their Get logic in their Test implementation. This is okay (though not necessary) as long as the implementations match. Unfortunately, in my experience, the implementations often did not match and this caused problems for integrating tools.
Instead, a default implementation could make it more difficult (and unnecessary) to implement anti-patterns, saving developer effort and improving the experience for integrating tools and end users.
Example Resources
Each of these DSC Resources reimplements some of the functionality of their own Get logic in Test instead of having Test compare the state reported by Get to the desired state.
HyperVDsc/DSC_VMNetworkAdapter
Source. This implementation calls
Get-VMNetworkAdapterin both Get and Test.NetworkingDsc/
Source. This implementation calls
Get-NetAdapterAdvancedPropertyin both Get and Test.xExchange/ExchangeServer
Source. This implementation calls
Get-ExchangeServerInternalin both Get and Test.StorageDsc/DiskAccessPath
Source. This implementation calls
Get-DiskByIdentifierin both Get and Test.cChoco/cChocoSource
Source. This implementation retrieves the current state of the configuration in the Test method but the Get method always returns an object that actually seems to represent the desired state instead of current state.
cNtfsAccessControl/cNtfsPermissionEntry
Source. This implementation calls
Get-Aclin both Get and Test.ComputerManagementDsc
Source. This implementation calls
Test-TimeZoneIdin Test instead of reusing the value returned from Get (which callsGet-TimeZoneId). On inspection,Test-TimeZoneIdis defined to callGet-TimeZoneIdand compare the value it returns.AccessControlDsc/NTFSAccessEntry
Source. This implementation calls
Get-AccessControlin both Get and Test but processes that return value differently in both implementations which may be functionally identical but are not guaranteed to be.GroupPolicyDsc/
Source. This implementation calls
Get-GPOin both Get and Test.Proposal
I propose that the IDscResource be extended with default implementations (proposed high-level implementation below).
This would allow, for example, a default
Testmethod which compares each property specified for testing with the results of calling theGetmethod. If all of the properties of a DSC Resource can be compared directly to the values returned fromGet, a DSC Resource author wouldn't need to override the method.High Level Implementation
The IDscResource could be updated to:
$CurrentStateas an empty instance of the DSC Resource's class$CurrentState$CurrentState$CurrentState$CurrentStateto the verifiable class properties (anything that isn't markedNotConfigurableorParameter-see Add a Write-Only / Parameter Attribute for the DscProperty attribute #76), returning$falseif any property is not equal and$trueonly if they are all correct. If Add support for reporting how a DSC Resource is out-of-state via the Test method #77 is accepted and implemented, this would need to behave differently so it can return the detailed information about how the resource is out of state (if it is).Alternative
If it is not possible to support default implementations in an interface, I believe the least work / best experience is to directly add default implementations to the interface proposed in #81. If that is not feasible, having a base class would also be valuable and functional.
Beta Was this translation helpful? Give feedback.
All reactions