-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Cross-platform updates to DSC code in SMA DLL #13399
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
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
61e1fc0
Initial code
2e1c25b
Code cleanup
e086111
Changed to default RunspaceMode.CurrentRunspace in internal class…
9324490
Updated ReadCimSchemaMof in MofDscClassCache.cs
4a6f818
Moved convertion cmdlet from SMA to DSC module
5b51113
Fixed runspace usage of JsonDeserializer.DeserializeClasses
5fbe162
Fixed PSModulePath handling for DeserializeClasses(RunspaceMode.NewRu…
3cf7abe
Fixed typo
06bcaff
Changed mof code to be using original namespace
5038ab7
Removed unused GenerateMofForType from JsonDscClassCache
05cf4e9
Removed leftover code in MofDscClassCache.cs
595530e
Feedback 1
3cf4c9e
Feedback 2
e024660
Feedback 3
08cffc3
Moved exception string to resources
8034edf
Fixed exception message code
93d638f
Added PSDscJsonSchemaSupport experimental feature
bc74051
Feedback 4
dca42a5
Merge branch 'master' into JsonWork
bda00c0
CodeFactor 1
0b39821
CodeFactor 2
4737ece
CodeFactor 3
6512f38
CodeFactor 4
dee8701
CodeFactor 5
c690d8f
Revert "CodeFactor 5"
2c9591b
Updated for a simplified schema
cdeeb29
Parser updates
6419de0
Fixed null-check in windows code
ce19485
Inverted bool condition in parser
bd9e84a
Merge branch 'master' into JsonWork
7869f1d
Feedback 5
6499eef
Updated default location of BaseRegistrations on Windows
d72925f
feedback 6
3701d8e
Merge branch 'JsonWork' of https://github.com/anmenaga/PowerShell int…
880f5fe
Added GetCachedClass
c601386
Updated GetCachedClass
8a789da
Fixed embedded classes for class-based resources
8e2f174
Fix SInt16Array(CIM)->int64[](.NET) mapping in LanguagePrimitives
ddb99d4
Fixed handling of duplicates for class-based resources
2b1e288
Updated error reporting for class resources
97b3da9
Removed unused GetResourceMethodsLinePosition
623dab4
Renamed LoadResourcesFromModule
70e3816
Merged in latest PS masater code
26b9ddf
Fixed new code style violations that were breaking build
2eaf084
Removed module import in configuration parsing
795a807
Class-based resource only support
39f9f05
Reverted splitting old code into separate files
9a98234
Updated experimental feature name
c2e82e7
Style fixes
a6ef5b6
Fixed tab completion tests
5a22731
Fixed typo in CompletionAnalysis
c1d935f
Updated exp feature
21f0cdf
Updated Get-ExperimentalFeature.Tests.ps1
cd5c3be
Updated error message when PSDesiredStateConfiguration v3 module is m…
ab4dca1
CodeFactor 1
9901fa2
CodeFactor 2
7250c1a
Merge branch 'master' into JsonWork
5a3cff1
CodeFactor 3
01c2f22
Merge branch 'JsonWork' of https://github.com/anmenaga/PowerShell int…
af4bf0b
CodeFactor 4
33e04b3
feedback
4a56618
feedback 5
a2aa5f9
feedback 6
f028e49
CodeFactor 5
00981b8
removed internal classversion property that is not used
7783bcf
Updated members according to naming convention
d75bea9
Updated NewApiIsUsed flag
c0db81c
Import-DscResource fix
0af0b68
feedback 7
e02bf3a
feedback 8
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/System.Management.Automation/DscSupport/JsonCimDSCParser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Management.Automation; | ||
| using System.Security; | ||
|
|
||
| namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal.CrossPlatform | ||
| { | ||
| /// <summary> | ||
| /// Class that does high level Cim schema parsing. | ||
| /// </summary> | ||
| internal class CimDSCParser | ||
| { | ||
| private readonly JsonDeserializer _jsonDeserializer; | ||
|
|
||
| internal CimDSCParser() | ||
| { | ||
| _jsonDeserializer = JsonDeserializer.Create(); | ||
| } | ||
|
|
||
| internal IEnumerable<PSObject> ParseSchemaJson(string filePath, bool useNewRunspace = false) | ||
| { | ||
| try | ||
| { | ||
| string json = File.ReadAllText(filePath); | ||
anmenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| string fileNameDefiningClass = Path.GetFileNameWithoutExtension(filePath); | ||
| int dotIndex = fileNameDefiningClass.IndexOf(".schema", StringComparison.InvariantCultureIgnoreCase); | ||
anmenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (dotIndex != -1) | ||
| { | ||
| fileNameDefiningClass = fileNameDefiningClass.Substring(0, dotIndex); | ||
| } | ||
|
|
||
| IEnumerable<PSObject> result = _jsonDeserializer.DeserializeClasses(json, useNewRunspace); | ||
| foreach (dynamic classObject in result) | ||
anmenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| string superClassName = classObject.SuperClassName; | ||
| string className = classObject.ClassName; | ||
| if (string.Equals(superClassName, "OMI_BaseResource", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| // Get the name of the file without schema.mof/json extension | ||
| if (!className.Equals(fileNameDefiningClass, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| PSInvalidOperationException e = PSTraceSource.NewInvalidOperationException( | ||
| ParserStrings.ClassNameNotSameAsDefiningFile, className, fileNameDefiningClass); | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| PSInvalidOperationException e = PSTraceSource.NewInvalidOperationException( | ||
| exception, ParserStrings.CimDeserializationError, filePath); | ||
|
|
||
| e.SetErrorId("CimDeserializationError"); | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
| } | ||
72 changes: 72 additions & 0 deletions
72
src/System.Management.Automation/DscSupport/JsonDeserializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Management.Automation; | ||
| using System.Management.Automation.Runspaces; | ||
|
|
||
| namespace Microsoft.PowerShell.DesiredStateConfiguration.Internal.CrossPlatform | ||
| { | ||
| internal class JsonDeserializer | ||
| { | ||
| #region Constructors | ||
|
|
||
| /// <summary> | ||
| /// Instantiates a default deserializer. | ||
| /// </summary> | ||
| /// <returns>Default deserializer.</returns> | ||
| public static JsonDeserializer Create() | ||
| { | ||
| return new JsonDeserializer(); | ||
| } | ||
|
|
||
| #endregion Constructors | ||
|
|
||
| #region Methods | ||
|
|
||
| /// <summary> | ||
| /// Returns schema of Cim classes from specified json file. | ||
| /// </summary> | ||
| /// <param name="json">Json text to deserialize.</param> | ||
| /// <param name="useNewRunspace">If a new runspace should be used.</param> | ||
| /// <returns>Deserialized PSObjects.</returns> | ||
| public IEnumerable<PSObject> DeserializeClasses(string json, bool useNewRunspace = false) | ||
| { | ||
| if (string.IsNullOrEmpty(json)) | ||
| { | ||
| throw new ArgumentNullException(nameof(json)); | ||
| } | ||
|
|
||
| System.Management.Automation.PowerShell powerShell = null; | ||
anmenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (useNewRunspace) | ||
| { | ||
| // currently using RunspaceMode.NewRunspace will reset PSModulePath env var for the entire process | ||
| // this is something we want to avoid in DSC GuestConfigAgent scenario, so we use following workaround | ||
| var s_iss = InitialSessionState.CreateDefault(); | ||
| s_iss.EnvironmentVariables.Add( | ||
| new SessionStateVariableEntry( | ||
| "PSModulePath", | ||
| Environment.GetEnvironmentVariable("PSModulePath"), | ||
| description: null)); | ||
| powerShell = System.Management.Automation.PowerShell.Create(s_iss); | ||
| } | ||
| else | ||
| { | ||
| powerShell = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); | ||
| } | ||
|
|
||
| using (powerShell) | ||
| { | ||
| return powerShell.AddCommand("Microsoft.PowerShell.Utility\\ConvertFrom-Json") | ||
| .AddParameter("InputObject", json) | ||
| .AddParameter("Depth", 100) // maximum supported by cmdlet | ||
| .Invoke(); | ||
| } | ||
| } | ||
|
|
||
| #endregion Methods | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.