forked from microsoft/PSRule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IConfiguration interface microsoft#1838
- Loading branch information
1 parent
db596be
commit 406ecb3
Showing
14 changed files
with
231 additions
and
109 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Feature flagging | ||
|
||
!!! Abstract | ||
Feature flags are a way to enable or disable functionality. | ||
Rule and module authors can use feature flags to toggle functionality on or off. | ||
|
||
## Using feature flags in emitters | ||
|
||
When an emitter is executed `IEmitterContext` is passed into each call. | ||
This context includes a `Configuration` property that exposes `IConfiguration`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,4 @@ | |
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Runtime\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,63 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Runtime; | ||
|
||
/// <summary> | ||
/// Access configuration values at runtime. | ||
/// </summary> | ||
public interface IConfiguration | ||
{ | ||
/// <summary> | ||
/// Try to the configuration item if it exists. | ||
/// </summary> | ||
/// <param name="configurationKey">The name of the configuration item.</param> | ||
/// <param name="defaultValue">The default value to use if the configuration item does not exist.</param> | ||
/// <returns>Returns the configuration item or the specified default value.</returns> | ||
object? GetValueOrDefault(string configurationKey, object? defaultValue = default); | ||
|
||
/// <summary> | ||
/// Get the specified configuration item as a string if it exists. | ||
/// </summary> | ||
/// <param name="configurationKey">The name of the configuration item.</param> | ||
/// <param name="defaultValue">The default value to use if the configuration item does not exist.</param> | ||
/// <returns>Returns the configuration item or the specified default value.</returns> | ||
string? GetStringOrDefault(string configurationKey, string? defaultValue = default); | ||
|
||
/// <summary> | ||
/// Get the specified configuration item as a boolean if it exists. | ||
/// </summary> | ||
/// <param name="configurationKey">The name of the configuration item.</param> | ||
/// <param name="defaultValue">The default value to use if the configuration item does not exist.</param> | ||
/// <returns>Returns the configuration item or the specified default value.</returns> | ||
bool? GetBoolOrDefault(string configurationKey, bool? defaultValue = default); | ||
|
||
/// <summary> | ||
/// Get the specified configuration item as an integer if it exists. | ||
/// </summary> | ||
/// <param name="configurationKey">The name of the configuration item.</param> | ||
/// <param name="defaultValue">The default value to use if the configuration item does not exist.</param> | ||
/// <returns>Returns the configuration item or the specified default value.</returns> | ||
int? GetIntegerOrDefault(string configurationKey, int? defaultValue = default); | ||
|
||
/// <summary> | ||
/// Get the specified configuration item as a string array. | ||
/// </summary> | ||
/// <param name="configurationKey">The name of the configuration item.</param> | ||
/// <returns> | ||
/// Returns an array of strings. | ||
/// If the configuration key does not exist and empty array is returned. | ||
/// If the configuration key is a string, an array with a single element is returned. | ||
/// </returns> | ||
string[] GetStringValues(string configurationKey); | ||
|
||
/// <summary> | ||
/// Check if specified configuration item is enabled. | ||
/// </summary> | ||
/// <remarks> | ||
/// Use this method to check if a feature is enabled. | ||
/// </remarks> | ||
/// <param name="configurationKey">The name of the configuration item.</param> | ||
/// <returns>Returns <c>true</c> when the configuration item exists and it set to <c>true</c>. Otherwise <c>false</c> is returned.</returns> | ||
bool IsEnabled(string configurationKey); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Pipeline; | ||
|
||
/// <summary> | ||
/// A helper to build a pipeline for executing rules and conventions within a PSRule sandbox. | ||
/// </summary> | ||
public interface IInvokePipelineBuilder : IPipelineBuilder | ||
{ | ||
/// <summary> | ||
/// Configures paths that will be scanned for input. | ||
/// </summary> | ||
/// <param name="path">An array of relative or absolute path specs to be scanned. Directories will be recursively scanned for all files not excluded matching the file path spec.</param> | ||
void InputPath(string[] path); | ||
|
||
/// <summary> | ||
/// Configures a variable that will receive all results in addition to the host context. | ||
/// </summary> | ||
/// <param name="variableName">The name of the variable to set.</param> | ||
void ResultVariable(string variableName); | ||
|
||
/// <summary> | ||
/// Unblocks PowerShell sources from trusted publishers that originate from an Internet zone. | ||
/// </summary> | ||
/// <param name="publisher">The trusted publisher to unblock.</param> | ||
void UnblockPublisher(string publisher); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Pipeline; | ||
|
||
/// <summary> | ||
/// A helper to construct the pipeline for Invoke-PSRule. | ||
/// </summary> | ||
internal sealed class InvokeRulePipelineBuilder : InvokePipelineBuilderBase | ||
{ | ||
internal InvokeRulePipelineBuilder(Source[] source, IHostContext hostContext) | ||
: base(source, hostContext) { } | ||
} |
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
Oops, something went wrong.