X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
61e1fc0
Initial code
Aug 11, 2020
2e1c25b
Code cleanup
Aug 11, 2020
e086111
Changed to default RunspaceMode.CurrentRunspace in internal class…
Aug 12, 2020
9324490
Updated ReadCimSchemaMof in MofDscClassCache.cs
Aug 12, 2020
4a6f818
Moved convertion cmdlet from SMA to DSC module
Aug 12, 2020
5b51113
Fixed runspace usage of JsonDeserializer.DeserializeClasses
Aug 12, 2020
5fbe162
Fixed PSModulePath handling for DeserializeClasses(RunspaceMode.NewRu…
Aug 12, 2020
3cf7abe
Fixed typo
Aug 12, 2020
06bcaff
Changed mof code to be using original namespace
Aug 17, 2020
5038ab7
Removed unused GenerateMofForType from JsonDscClassCache
Aug 17, 2020
05cf4e9
Removed leftover code in MofDscClassCache.cs
Aug 18, 2020
595530e
Feedback 1
Aug 19, 2020
3cf4c9e
Feedback 2
Aug 19, 2020
e024660
Feedback 3
Aug 19, 2020
08cffc3
Moved exception string to resources
Aug 20, 2020
8034edf
Fixed exception message code
Aug 20, 2020
93d638f
Added PSDscJsonSchemaSupport experimental feature
Aug 20, 2020
bc74051
Feedback 4
Aug 21, 2020
dca42a5
Merge branch 'master' into JsonWork
Aug 21, 2020
bda00c0
CodeFactor 1
Aug 21, 2020
0b39821
CodeFactor 2
Aug 21, 2020
4737ece
CodeFactor 3
Aug 21, 2020
6512f38
CodeFactor 4
Aug 21, 2020
dee8701
CodeFactor 5
Aug 21, 2020
c690d8f
Revert "CodeFactor 5"
Aug 21, 2020
2c9591b
Updated for a simplified schema
Aug 24, 2020
cdeeb29
Parser updates
Aug 25, 2020
6419de0
Fixed null-check in windows code
Aug 25, 2020
ce19485
Inverted bool condition in parser
Aug 26, 2020
bd9e84a
Merge branch 'master' into JsonWork
Aug 31, 2020
7869f1d
Feedback 5
Sep 1, 2020
6499eef
Updated default location of BaseRegistrations on Windows
Sep 2, 2020
d72925f
feedback 6
Sep 2, 2020
3701d8e
Merge branch 'JsonWork' of https://github.com/anmenaga/PowerShell int…
Sep 2, 2020
880f5fe
Added GetCachedClass
Sep 22, 2020
c601386
Updated GetCachedClass
Sep 29, 2020
8a789da
Fixed embedded classes for class-based resources
Oct 6, 2020
8e2f174
Fix SInt16Array(CIM)->int64[](.NET) mapping in LanguagePrimitives
Nov 21, 2020
ddb99d4
Fixed handling of duplicates for class-based resources
Nov 22, 2020
2b1e288
Updated error reporting for class resources
Nov 22, 2020
97b3da9
Removed unused GetResourceMethodsLinePosition
Nov 22, 2020
623dab4
Renamed LoadResourcesFromModule
Nov 22, 2020
70e3816
Merged in latest PS masater code
Nov 22, 2020
26b9ddf
Fixed new code style violations that were breaking build
Nov 22, 2020
2eaf084
Removed module import in configuration parsing
Nov 24, 2020
795a807
Class-based resource only support
Dec 8, 2020
39f9f05
Reverted splitting old code into separate files
Jan 5, 2021
9a98234
Updated experimental feature name
Jan 5, 2021
c2e82e7
Style fixes
Jan 5, 2021
a6ef5b6
Fixed tab completion tests
Jan 6, 2021
5a22731
Fixed typo in CompletionAnalysis
Jan 6, 2021
c1d935f
Updated exp feature
Jan 11, 2021
21f0cdf
Updated Get-ExperimentalFeature.Tests.ps1
Jan 11, 2021
cd5c3be
Updated error message when PSDesiredStateConfiguration v3 module is m…
Jan 11, 2021
ab4dca1
CodeFactor 1
Jan 12, 2021
9901fa2
CodeFactor 2
Jan 12, 2021
7250c1a
Merge branch 'master' into JsonWork
Jan 12, 2021
5a3cff1
CodeFactor 3
Jan 12, 2021
01c2f22
Merge branch 'JsonWork' of https://github.com/anmenaga/PowerShell int…
Jan 12, 2021
af4bf0b
CodeFactor 4
Jan 12, 2021
33e04b3
feedback
Jan 20, 2021
4a56618
feedback 5
Jan 20, 2021
a2aa5f9
feedback 6
Jan 20, 2021
f028e49
CodeFactor 5
Jan 20, 2021
00981b8
removed internal classversion property that is not used
Jan 22, 2021
7783bcf
Updated members according to naming convention
Jan 25, 2021
d75bea9
Updated NewApiIsUsed flag
Jan 26, 2021
c0db81c
Import-DscResource fix
Jan 27, 2021
0af0b68
feedback 7
Jan 28, 2021
e02bf3a
feedback 8
Feb 2, 2021
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
8 changes: 5 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ Fix steps:
-not ($Runtime -like 'fxdependent*')) {

$json = & $publishPath\pwsh -noprofile -command {
$expFeatures = [System.Collections.Generic.List[string]]::new()
Get-ExperimentalFeature | ForEach-Object { $expFeatures.Add($_.Name) }
# Special case for DSC code in PS;
# this experimental feature requires new DSC module that is not inbox,
# so we don't want default DSC use case be broken
$expFeatures = Get-ExperimentalFeature | Where-Object Name -NE PS7DscSupport | ForEach-Object -MemberName Name

# Make sure ExperimentalFeatures from modules in PSHome are added
# https://github.com/PowerShell/PowerShell/issues/10550
Expand All @@ -598,7 +600,7 @@ Fix steps:
}
}

ConvertTo-Json $expFeatures.ToArray()
ConvertTo-Json $expFeatures
}

$config += @{ ExperimentalFeatures = ([string[]] ($json | ConvertFrom-Json)) }
Expand Down
18 changes: 15 additions & 3 deletions src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public static object ConvertCimInstanceToObject(Type targetType, CimInstance ins

using (System.Management.Automation.PowerShell powerShell = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
{
const string script = "param($targetType,$moduleName) & (Microsoft.PowerShell.Core\\Get-Module $moduleName) { New-Object $targetType } ";

powerShell.AddScript(script);
powerShell.AddScript("param($targetType,$moduleName) & (Microsoft.PowerShell.Core\\Get-Module $moduleName) { New-Object $targetType } ");
powerShell.AddArgument(targetType);
powerShell.AddArgument(moduleName);

Expand Down Expand Up @@ -945,6 +943,20 @@ private static CimClass MyClassCallback(string serverName, string namespaceName,
return null;
}

/// <summary>
/// Reads CIM MOF schema file and returns classes defined in it.
/// This is used MOF->PSClass conversion tool.
/// </summary>
/// <param name="mofPath">
/// Path to CIM MOF schema file for reading.
/// </param>
/// <returns>List of classes from MOF schema file.</returns>
public static List<CimClass> ReadCimSchemaMof(string mofPath)
{
var parser = new Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser(MyClassCallback);
return parser.ParseSchemaMof(mofPath);
}

/// <summary>
/// Import CIM classes from the given file.
/// </summary>
Expand Down
68 changes: 68 additions & 0 deletions src/System.Management.Automation/DscSupport/JsonCimDSCParser.cs
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);
string fileNameDefiningClass = Path.GetFileNameWithoutExtension(filePath);
int dotIndex = fileNameDefiningClass.IndexOf(".schema", StringComparison.InvariantCultureIgnoreCase);
if (dotIndex != -1)
{
fileNameDefiningClass = fileNameDefiningClass.Substring(0, dotIndex);
}

IEnumerable<PSObject> result = _jsonDeserializer.DeserializeClasses(json, useNewRunspace);
foreach (dynamic classObject in result)
{
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 src/System.Management.Automation/DscSupport/JsonDeserializer.cs
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;

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
}
}
Loading
X Tutup