forked from Azure/PSRule.Rules.Azure
-
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.
Fixed output map expansion with resource IDs Azure#3153 (Azure#3156)
- Loading branch information
1 parent
dc51030
commit 4c81900
Showing
13 changed files
with
1,241 additions
and
31 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
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
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 |
---|---|---|
@@ -1,34 +1,49 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace PSRule.Rules.Azure.Data.Template; | ||
|
||
internal readonly struct ParameterType | ||
#nullable enable | ||
|
||
[DebuggerDisplay("{Type}/{ItemType}, {Name}")] | ||
internal readonly struct ParameterType(TypePrimitive type = TypePrimitive.None, TypePrimitive itemType = TypePrimitive.None, string? name = null) | ||
{ | ||
public readonly TypePrimitive Type; | ||
public readonly string Name; | ||
public readonly TypePrimitive Type = type; | ||
public readonly TypePrimitive ItemType = itemType; | ||
public readonly string? Name = name; | ||
|
||
public static readonly ParameterType String = new(TypePrimitive.String); | ||
public static readonly ParameterType Object = new(TypePrimitive.Object); | ||
public static readonly ParameterType SecureString = new(TypePrimitive.SecureString); | ||
public static readonly ParameterType Array = new(TypePrimitive.Array); | ||
|
||
public ParameterType(TypePrimitive type = TypePrimitive.None, string name = null) | ||
public static bool TrySimpleType(string? type, out ParameterType? value) | ||
{ | ||
Type = type; | ||
Name = name; | ||
if (!TypeHelpers.TryTypePrimitive(type, out var primitive) || primitive == null) | ||
{ | ||
value = new ParameterType(); | ||
return false; | ||
} | ||
value = new ParameterType(primitive.Value, default, default); | ||
return true; | ||
} | ||
|
||
public static bool TrySimpleType(string type, out ParameterType value) | ||
public static bool TryArrayType(string? type, string? itemType, out ParameterType? value) | ||
{ | ||
if (!Enum.TryParse(type, ignoreCase: true, result: out TypePrimitive primitive)) | ||
if (!TypeHelpers.TryTypePrimitive(type, out var primitive) || primitive == null) | ||
{ | ||
value = new ParameterType(); | ||
return false; | ||
} | ||
value = new ParameterType(primitive, null); | ||
|
||
value = TypeHelpers.TryTypePrimitive(itemType, out var itemPrimitive) && itemPrimitive != null | ||
? new ParameterType(primitive.Value, itemPrimitive.Value, default) | ||
: new ParameterType(primitive.Value, TypePrimitive.None, default); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
#nullable restore |
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,24 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace PSRule.Rules.Azure.Data.Template; | ||
|
||
#nullable enable | ||
|
||
internal static class TypeHelpers | ||
{ | ||
public static bool TryTypePrimitive(string? type, out TypePrimitive? value) | ||
{ | ||
if (string.IsNullOrEmpty(type) || !Enum.TryParse(type, ignoreCase: true, result: out TypePrimitive primitive)) | ||
{ | ||
value = default; | ||
return false; | ||
} | ||
value = primitive; | ||
return true; | ||
} | ||
} | ||
|
||
#nullable restore |
Oops, something went wrong.