-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration environment (#5139)
## Change This change adds a `ConfigurationEnvironment` type which is a property of a `ConfigurationUnit`. It defines the environment in which the unit should be run. This currently encompasses two properties; the security context and the processor. The values are parsed from the metadata, but the object is considered authoritative at runtime and when serializing. They are also inherited in schema 0.3, allowing the entire set to be defined in a single environment in it's metadata. The code that was using the `securityContext` metadata has been updated to use the environment property instead. It also uses the unique environment calculation function for the set to more efficiently determine which contexts are present.
- Loading branch information
Showing
35 changed files
with
1,808 additions
and
157 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -321,6 +321,7 @@ STDAPI | |
STGM | ||
storeedgefd | ||
stpkgmanvalwestustest | ||
stringable | ||
STRINGID | ||
STRINGIZE | ||
STRSAFE | ||
|
This file contains 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 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 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
62 changes: 62 additions & 0 deletions
62
src/Microsoft.Management.Configuration.Processor/Extensions/DictionaryExtensions.cs
This file contains 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,62 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <copyright file="DictionaryExtensions.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Management.Configuration.Processor.Extensions | ||
{ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Windows.Foundation.Collections; | ||
|
||
/// <summary> | ||
/// Extensions for dictionaries. | ||
/// </summary> | ||
internal static class DictionaryExtensions | ||
{ | ||
/// <summary> | ||
/// Performs a deep compare of the dictionaries. | ||
/// </summary> | ||
/// <param name="first">First dictionary.</param> | ||
/// <param name="second">Second dictionary.</param> | ||
/// <returns>Whether the two dictionaries equal.</returns> | ||
internal static bool ContentEquals(this IDictionary<string, string> first, IDictionary<string, string> second) | ||
{ | ||
if (first.Count != second.Count) | ||
{ | ||
return false; | ||
} | ||
|
||
foreach (var keyValuePair in first) | ||
{ | ||
string key = keyValuePair.Key; | ||
if (!second.ContainsKey(key)) | ||
{ | ||
return false; | ||
} | ||
|
||
var firstValue = keyValuePair.Value; | ||
var secondValue = second[key]; | ||
|
||
// Empty value check. | ||
if (firstValue == null && secondValue == null) | ||
{ | ||
continue; | ||
} | ||
else if (firstValue == null || secondValue == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (firstValue != secondValue) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains 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 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
86 changes: 86 additions & 0 deletions
86
src/Microsoft.Management.Configuration.UnitTests/Helpers/ConfigurationEnvironmentData.cs
This file contains 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,86 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <copyright file="ConfigurationEnvironmentData.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Management.Configuration.UnitTests.Helpers | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Contains the data defining a configuration environment. | ||
/// </summary> | ||
internal class ConfigurationEnvironmentData | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConfigurationEnvironmentData"/> class. | ||
/// </summary> | ||
internal ConfigurationEnvironmentData() { } | ||
|
||
/// <summary> | ||
/// Gets or sets the security context. | ||
/// </summary> | ||
internal SecurityContext Context { get; set; } = SecurityContext.Current; | ||
|
||
/// <summary> | ||
/// Gets or sets the processor identifier. | ||
/// </summary> | ||
internal string ProcessorIdentifier { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Gets or sets the processor properties. | ||
/// </summary> | ||
internal Dictionary<string, string> ProcessorProperties { get; set; } = new (); | ||
|
||
/// <summary> | ||
/// Applies this environment to the given unit. | ||
/// </summary> | ||
/// <param name="unit">The unit to apply to.</param> | ||
/// <returns>The given unit.</returns> | ||
internal ConfigurationUnit ApplyToUnit(ConfigurationUnit unit) | ||
{ | ||
var environment = unit.Environment; | ||
|
||
environment.Context = this.Context; | ||
environment.ProcessorIdentifier = this.ProcessorIdentifier; | ||
environment.ProcessorProperties.Clear(); | ||
foreach (var property in this.ProcessorProperties) | ||
{ | ||
environment.ProcessorProperties.Add(property.Key, property.Value); | ||
} | ||
|
||
return unit; | ||
} | ||
|
||
/// <summary> | ||
/// Tests whether the given properties match this object's properties. | ||
/// </summary> | ||
/// <param name="properties">The properties to test.</param> | ||
/// <returns>True if the properties match; false if not.</returns> | ||
internal bool PropertiesEqual(IDictionary<string, string> properties) | ||
{ | ||
if (properties.Count != this.ProcessorProperties.Count) | ||
{ | ||
return false; | ||
} | ||
|
||
foreach (var property in properties) | ||
{ | ||
string? value = null; | ||
if (!this.ProcessorProperties.TryGetValue(property.Key, out value)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (property.Value != value) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Microsoft.Management.Configuration.UnitTests/Helpers/ConfigurationExtensions.cs
This file contains 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
Oops, something went wrong.