Skip to content

Commit

Permalink
Azure.Provisioning: Unify resolvers and newslot Literal expressions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tg-msft authored Oct 18, 2024
1 parent 7c7f12b commit c7ffa2c
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private static ProvisioningDeployment ProcessDeploymentInternal(ProvisioningPlan
}

// Patch up output references
foreach (ProvisioningOutput output in plan.Infrastructure.GetResources().OfType<ProvisioningOutput>())
foreach (ProvisioningOutput output in plan.Infrastructure.GetProvisionableResources().OfType<ProvisioningOutput>())
{
if (outputs.TryGetValue(output.BicepIdentifier, out object? value) &&
value is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public virtual void Add(Azure.Provisioning.Primitives.Provisionable resource) {
public virtual Azure.Provisioning.ProvisioningPlan Build(Azure.Provisioning.ProvisioningBuildOptions? options = null) { throw null; }
protected internal override System.Collections.Generic.IEnumerable<Azure.Provisioning.Expressions.BicepStatement> Compile() { throw null; }
protected internal System.Collections.Generic.IDictionary<string, System.Collections.Generic.IEnumerable<Azure.Provisioning.Expressions.BicepStatement>> CompileModules(Azure.Provisioning.ProvisioningBuildOptions? options = null) { throw null; }
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> GetResources() { throw null; }
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> GetProvisionableResources() { throw null; }
public static bool IsValidBicepIdentifier(string? bicepIdentifier) { throw null; }
public static string NormalizeBicepIdentifier(string? bicepIdentifier) { throw null; }
public virtual void Remove(Azure.Provisioning.Primitives.Provisionable resource) { }
Expand All @@ -108,8 +108,7 @@ public static void ValidateBicepIdentifier(string? bicepIdentifier, string? para
public partial class ProvisioningBuildOptions
{
public ProvisioningBuildOptions() { }
public System.Collections.Generic.IList<Azure.Provisioning.Primitives.InfrastructureResolver> InfrastructureResolvers { get { throw null; } set { } }
public System.Collections.Generic.IList<Azure.Provisioning.Primitives.PropertyResolver> PropertyResolvers { get { throw null; } set { } }
public System.Collections.Generic.IList<Azure.Provisioning.Primitives.InfrastructureResolver> InfrastructureResolvers { get { throw null; } }
public System.Random Random { get { throw null; } set { } }
}
public partial class ProvisioningOutput : Azure.Provisioning.ProvisioningVariable
Expand Down Expand Up @@ -597,7 +596,7 @@ public BinaryExpression(Azure.Provisioning.Expressions.BicepExpression left, Azu
public partial class BoolLiteralExpression : Azure.Provisioning.Expressions.LiteralExpression
{
public BoolLiteralExpression(bool value) : base (default(object)) { }
public bool Value { get { throw null; } }
public new bool Value { get { throw null; } }
}
public partial class CommentStatement : Azure.Provisioning.Expressions.BicepStatement
{
Expand Down Expand Up @@ -647,12 +646,12 @@ public InterpolatedStringExpression(string format, Azure.Provisioning.Expression
public partial class IntLiteralExpression : Azure.Provisioning.Expressions.LiteralExpression
{
public IntLiteralExpression(int value) : base (default(object)) { }
public int Value { get { throw null; } }
public new int Value { get { throw null; } }
}
public abstract partial class LiteralExpression : Azure.Provisioning.Expressions.BicepExpression
{
protected LiteralExpression(object? literalValue = null) { }
public object? LiteralValue { get { throw null; } }
protected LiteralExpression(object? value = null) { }
public object? Value { get { throw null; } }
}
public partial class MemberExpression : Azure.Provisioning.Expressions.BicepExpression
{
Expand Down Expand Up @@ -729,7 +728,7 @@ public SafeMemberExpression(Azure.Provisioning.Expressions.BicepExpression value
public partial class StringLiteralExpression : Azure.Provisioning.Expressions.LiteralExpression
{
public StringLiteralExpression(string value) : base (default(object)) { }
public string Value { get { throw null; } }
public new string Value { get { throw null; } }
}
public partial class TargetScopeStatement : Azure.Provisioning.Expressions.BicepStatement
{
Expand Down Expand Up @@ -780,7 +779,7 @@ public BicepValueReference(Azure.Provisioning.Primitives.ProvisionableConstruct
public partial class ClientCreatorOutputResolver : Azure.Provisioning.Primitives.InfrastructureResolver
{
public ClientCreatorOutputResolver() { }
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> ResolveResources(Azure.Provisioning.ProvisioningBuildOptions options, System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> resources) { throw null; }
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> ResolveResources(System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> resources, Azure.Provisioning.ProvisioningBuildOptions options) { throw null; }
}
public partial class DynamicResourceNamePropertyResolver : Azure.Provisioning.Primitives.ResourceNamePropertyResolver
{
Expand All @@ -799,15 +798,16 @@ public partial interface IClientCreator<TClient, TOptions> : Azure.Provisioning.
public abstract partial class InfrastructureResolver
{
protected InfrastructureResolver() { }
public System.Collections.Generic.IEnumerable<Azure.Provisioning.Infrastructure> GetNestedInfrastructure(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Infrastructure infrastructure) { throw null; }
public virtual void ResolveInfrastructure(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Infrastructure infrastructure) { }
public virtual System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> ResolveResources(Azure.Provisioning.ProvisioningBuildOptions options, System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> resources) { throw null; }
public virtual System.Collections.Generic.IEnumerable<Azure.Provisioning.Infrastructure> GetNestedInfrastructure(Azure.Provisioning.Infrastructure infrastructure, Azure.Provisioning.ProvisioningBuildOptions options) { throw null; }
public virtual void ResolveInfrastructure(Azure.Provisioning.Infrastructure infrastructure, Azure.Provisioning.ProvisioningBuildOptions options) { }
public virtual void ResolveProperties(Azure.Provisioning.Primitives.ProvisionableConstruct construct, Azure.Provisioning.ProvisioningBuildOptions options) { }
public virtual System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> ResolveResources(System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> resources, Azure.Provisioning.ProvisioningBuildOptions options) { throw null; }
}
public partial class LocationPropertyResolver : Azure.Provisioning.Primitives.PropertyResolver
public partial class LocationPropertyResolver : Azure.Provisioning.Primitives.InfrastructureResolver
{
public LocationPropertyResolver() { }
protected virtual Azure.Provisioning.BicepValue<Azure.Core.AzureLocation> GetDefaultLocation(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Primitives.ProvisionableConstruct construct) { throw null; }
public override void ResolveProperties(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Primitives.ProvisionableConstruct construct) { }
public override void ResolveProperties(Azure.Provisioning.Primitives.ProvisionableConstruct construct, Azure.Provisioning.ProvisioningBuildOptions options) { }
}
public partial class ModuleImport : Azure.Provisioning.Primitives.NamedProvisionableConstruct
{
Expand All @@ -827,18 +827,13 @@ protected NamedProvisionableConstruct(string bicepIdentifier) { }
public partial class OrderingInfrastructureResolver : Azure.Provisioning.Primitives.InfrastructureResolver
{
public OrderingInfrastructureResolver() { }
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> ResolveResources(Azure.Provisioning.ProvisioningBuildOptions options, System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> resources) { throw null; }
}
public abstract partial class PropertyResolver
{
protected PropertyResolver() { }
public abstract void ResolveProperties(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Primitives.ProvisionableConstruct construct);
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> ResolveResources(System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> resources, Azure.Provisioning.ProvisioningBuildOptions options) { throw null; }
}
public abstract partial class Provisionable
{
internal Provisionable() { }
protected internal abstract System.Collections.Generic.IEnumerable<Azure.Provisioning.Expressions.BicepStatement> Compile();
public virtual System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> GetResources() { throw null; }
public virtual System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> GetProvisionableResources() { throw null; }
protected internal virtual void Resolve(Azure.Provisioning.ProvisioningBuildOptions? options = null) { }
protected internal virtual void Validate(Azure.Provisioning.ProvisioningBuildOptions? options = null) { }
}
Expand All @@ -849,7 +844,7 @@ protected ProvisionableConstruct() { }
public Azure.Provisioning.Infrastructure? ParentInfrastructure { get { throw null; } }
protected internal override System.Collections.Generic.IEnumerable<Azure.Provisioning.Expressions.BicepStatement> Compile() { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> GetResources() { throw null; }
public override System.Collections.Generic.IEnumerable<Azure.Provisioning.Primitives.Provisionable> GetProvisionableResources() { throw null; }
protected internal void OverrideWithExpression(Azure.Provisioning.Expressions.BicepExpression reference) { }
protected internal override void Resolve(Azure.Provisioning.ProvisioningBuildOptions? options = null) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
Expand Down Expand Up @@ -882,11 +877,11 @@ public enum ResourceNameCharacters
Period = 32,
Parentheses = 64,
}
public abstract partial class ResourceNamePropertyResolver : Azure.Provisioning.Primitives.PropertyResolver
public abstract partial class ResourceNamePropertyResolver : Azure.Provisioning.Primitives.InfrastructureResolver
{
protected ResourceNamePropertyResolver() { }
public abstract Azure.Provisioning.BicepValue<string>? ResolveName(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Primitives.ProvisionableResource resource, Azure.Provisioning.Primitives.ResourceNameRequirements requirements);
public override void ResolveProperties(Azure.Provisioning.ProvisioningBuildOptions options, Azure.Provisioning.Primitives.ProvisionableConstruct construct) { }
public override void ResolveProperties(Azure.Provisioning.Primitives.ProvisionableConstruct construct, Azure.Provisioning.ProvisioningBuildOptions options) { }
protected static string SanitizeText(string text, Azure.Provisioning.Primitives.ResourceNameCharacters validCharacters) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
Expand Down
10 changes: 5 additions & 5 deletions sdk/provisioning/Azure.Provisioning/src/Expressions/AST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class IdentifierExpression(string name) : BicepExpression
internal override BicepWriter Write(BicepWriter writer) => writer.Append(Name);
}

public abstract class LiteralExpression(object? literalValue = null) : BicepExpression
public abstract class LiteralExpression(object? value = null) : BicepExpression
{
public object? LiteralValue { get; } = literalValue;
public object? Value { get; } = value;
}

public class NullLiteralExpression() : LiteralExpression()
Expand All @@ -42,19 +42,19 @@ public class NullLiteralExpression() : LiteralExpression()

public class BoolLiteralExpression(bool value) : LiteralExpression(value)
{
public bool Value { get; } = value;
public new bool Value { get => (bool)base.Value!; }
internal override BicepWriter Write(BicepWriter writer) => writer.Append(Value ? "true" : "false");
}

public class IntLiteralExpression(int value) : LiteralExpression(value)
{
public int Value { get; } = value;
public new int Value { get => (int)base.Value!; }
internal override BicepWriter Write(BicepWriter writer) => writer.Append(Value.ToString());
}

public class StringLiteralExpression(string value) : LiteralExpression(value)
{
public string Value { get; } = value;
public new string Value { get => (string)base.Value!; }
internal override BicepWriter Write(BicepWriter writer) =>
(Value == null) ?
writer.Append("null") :
Expand Down
14 changes: 7 additions & 7 deletions sdk/provisioning/Azure.Provisioning/src/Infrastructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Infrastructure(string bicepName = "main") : Provisionable
private Infrastructure? _parent = null;

/// <inheritdoc/>
public override IEnumerable<Provisionable> GetResources() => _resources;
public override IEnumerable<Provisionable> GetProvisionableResources() => _resources;
private readonly List<Provisionable> _resources = [];

/// <summary>
Expand Down Expand Up @@ -206,7 +206,7 @@ protected internal override void Validate(ProvisioningBuildOptions? options = nu
{
options ??= new();
base.Validate(options);
foreach (Provisionable resource in GetResources()) { resource.Validate(options); }
foreach (Provisionable resource in GetProvisionableResources()) { resource.Validate(options); }
}

/// <inheritdoc/>
Expand All @@ -215,12 +215,12 @@ protected internal override void Resolve(ProvisioningBuildOptions? options = def
options ??= new();
base.Resolve(options);

Provisionable[] cached = [.. GetResources()]; // Copy so Resolve can mutate
Provisionable[] cached = [.. GetProvisionableResources()]; // Copy so Resolve can mutate
foreach (Provisionable resource in cached) { resource.Resolve(options); }

foreach (InfrastructureResolver resolver in options.InfrastructureResolvers)
{
resolver.ResolveInfrastructure(options, this);
resolver.ResolveInfrastructure(this, options);
}
}

Expand Down Expand Up @@ -248,7 +248,7 @@ protected internal IDictionary<string, IEnumerable<BicepStatement>> CompileModul
List<Infrastructure> nested = [];
foreach (InfrastructureResolver resolver in options.InfrastructureResolvers)
{
nested.AddRange(resolver.GetNestedInfrastructure(options, this));
nested.AddRange(resolver.GetNestedInfrastructure(this, options));
}
foreach (Infrastructure infra in nested)
{
Expand All @@ -267,15 +267,15 @@ private List<BicepStatement> CompileInternal(ProvisioningBuildOptions? options)
statements.Add(new TargetScopeStatement(TargetScope));
}

IEnumerable<Provisionable> resources = GetResources();
IEnumerable<Provisionable> resources = GetProvisionableResources();

// Optionally customize the resources with the extensibility hooks on
// ProvisioningBuildOptions.
if (options is not null)
{
foreach (InfrastructureResolver resolver in options.InfrastructureResolvers)
{
resources = resolver.ResolveResources(options, resources);
resources = resolver.ResolveResources(resources, options);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public TClient CreateClient(
public class ClientCreatorOutputResolver : InfrastructureResolver
{
/// <inheritdoc/>
public override IEnumerable<Provisionable> ResolveResources(ProvisioningBuildOptions options, IEnumerable<Provisionable> resources)
public override IEnumerable<Provisionable> ResolveResources(IEnumerable<Provisionable> resources, ProvisioningBuildOptions options)
{
foreach (Provisionable resource in resources)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,47 @@ namespace Azure.Provisioning.Primitives;
public abstract class InfrastructureResolver
{
/// <summary>
/// Resolve any properties of the infrastructure.
/// Try to resolve the values of any unset properties in the given construct.
/// </summary>
/// <param name="construct">The construct with properties to resolve.</param>
/// <param name="options">The current build options.</param>
public virtual void ResolveProperties(
ProvisionableConstruct construct,
ProvisioningBuildOptions options)
{
}

/// <summary>
/// Resolve any properties of the infrastructure.
/// </summary>
/// <param name="infrastructure">The infrastructure to resolve properties of.</param>
/// <param name="options">The current build options.</param>
public virtual void ResolveInfrastructure(
ProvisioningBuildOptions options,
Infrastructure infrastructure)
Infrastructure infrastructure,
ProvisioningBuildOptions options)
{
}

/// <summary>
/// Process the collection of resources in the infrastructure.
/// </summary>
/// <param name="options">The current build options.</param>
/// <param name="resources">The existing resources to resolve.</param>
/// <param name="options">The current build options.</param>
public virtual IEnumerable<Provisionable> ResolveResources(
ProvisioningBuildOptions options,
IEnumerable<Provisionable> resources) =>
IEnumerable<Provisionable> resources,
ProvisioningBuildOptions options) =>
resources;

/// <summary>
/// Gets any nested infrastructure that should be composed separately.
/// </summary>
/// <param name="options">The current build options.</param>
/// <param name="infrastructure">
/// The infrastructure to inspect for any nested infrastructure.
/// </param>
/// <returns></returns>
public IEnumerable<Infrastructure> GetNestedInfrastructure(
ProvisioningBuildOptions options,
Infrastructure infrastructure) =>
/// <param name="options">The current build options.</param>
/// <returns>Nested infrastructure.</returns>
public virtual IEnumerable<Infrastructure> GetNestedInfrastructure(
Infrastructure infrastructure,
ProvisioningBuildOptions options) =>
[];
}
Loading

0 comments on commit c7ffa2c

Please sign in to comment.