Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions sdk/provisioning/Generator/src/GenerateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using CommandLine;

namespace Generator;

internal class GenerateOptions
{
[Option(longName: "filter", shortName: 'f', Required = false, Hidden = false)]
public string? Filter { get; set; }

[Option(longName: "schema", shortName: 's', Required = false, Default = true, Hidden = false)]
public bool GenerateSchema { get; set; }
}
1 change: 1 addition & 0 deletions sdk/provisioning/Generator/src/Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" VersionOverride="2.9.1"/>
<PackageReference Include="Azure.Identity" />
</ItemGroup>

Expand Down
190 changes: 105 additions & 85 deletions sdk/provisioning/Generator/src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,97 +1,117 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Azure.Provisioning.Generator.Model;
using Azure.Provisioning.Generator.Specifications;
using CommandLine;
using System;
using System.Collections.Generic;

// Collect all the specs to generate
List<Specification> baselineSpecs =
[
new ArmSpecification(),
new ResourcesSpecification(),
new AuthorizationSpecification(),
new ManagedServiceIdentitiesSpecification(),
];
List<Specification> rpSpecs =
[
new AppContainersSpecification(),
new AppServiceSpecification(),
new AppConfigurationSpecification(),
new ApplicationInsightsSpecification(),
new CommunicationSpecification(),
new CognitiveServicesSpecification(),
new ContainerRegistrySpecification(),
new ContainerServiceSpecification(),
new CosmosDBSpecification(),
//new DnsSpecification(), // the Dns's mgmt SDK is majority hand-crafted, therefore here we just use this to generate a scaffold, and then hand-craft the rest.
new EventGridSpecification(),
new EventHubsSpecification(),
new FrontDoorSpecification(),
new KeyVaultSpecification(),
new KubernetesSpecification(),
new KubernetesConfigurationSpecification(),
new KustoSpecification(),
new NetworkSpecification(),
new OperationalInsightsSpecification(),
new PostgreSqlSpecification(),
new RedisSpecification(),
new RedisEnterpriseSpecification(),
new SearchSpecification(),
new ServiceBusSpecification(),
new SignalRSpecification(),
new SqlSpecification(),
new StorageSpecification(),
new WebPubSubSpecification(),
];
namespace Generator;

// Generate the specs
Dictionary<string, string> failures = [];
foreach (Specification spec in baselineSpecs)
internal static class Program
{
try
{
Console.WriteLine($"Generating {spec.Name}...");
spec.Build();
}
catch (Exception ex)
public static int Main(string[] args)
{
failures[spec.Name] = ex.Message;
return Parser.Default.ParseArguments<GenerateOptions>(args)
.MapResult(
Generate,
errs => 1);
}
}
// defines the filter to be the first argument
string? filter = null;
if (args.Length > 0)
{
filter = args[0];
Console.WriteLine($"Filtering to only generate specifications matching '{filter}'");
}
foreach (Specification spec in rpSpecs)
{
if (filter is not null && spec.Name != filter)
{
Console.WriteLine($"Skipping {spec.Name}...");
continue;
}
try
{
Console.WriteLine($"Generating {spec.Name}...");
spec.Build();
}
catch (Exception ex)
{
failures[spec.Name] = ex.Message;
}
}
Console.WriteLine("\n\nFinished generating all specifications.\n\n");
if (failures.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
foreach (KeyValuePair<string, string> failure in failures)

private static int Generate(GenerateOptions options)
{
Console.WriteLine($"{failure.Key}: {failure.Value}");
Console.WriteLine("\n\n");
// Collect all the specs to generate
List<Specification> baselineSpecs =
[
new ArmSpecification(),
new ResourcesSpecification(),
new AuthorizationSpecification(),
new ManagedServiceIdentitiesSpecification(),
];
List<Specification> rpSpecs =
[
new AppContainersSpecification(),
new AppServiceSpecification(),
new AppConfigurationSpecification(),
new ApplicationInsightsSpecification(),
new CommunicationSpecification(),
new CognitiveServicesSpecification(),
new ContainerRegistrySpecification(),
new ContainerServiceSpecification(),
new CosmosDBSpecification(),
//new DnsSpecification(), // the Dns's mgmt SDK is majority hand-crafted, therefore here we just use this to generate a scaffold, and then hand-craft the rest.
new EventGridSpecification(),
new EventHubsSpecification(),
new FrontDoorSpecification(),
new KeyVaultSpecification(),
new KubernetesSpecification(),
new KubernetesConfigurationSpecification(),
new KustoSpecification(),
new NetworkSpecification(),
new OperationalInsightsSpecification(),
new PostgreSqlSpecification(),
new RedisSpecification(),
new RedisEnterpriseSpecification(),
new SearchSpecification(),
new ServiceBusSpecification(),
new SignalRSpecification(),
new SqlSpecification(),
new StorageSpecification(),
new WebPubSubSpecification(),
];

// Generate the specs
Dictionary<string, string> failures = [];
foreach (Specification spec in baselineSpecs)
{
try
{
Console.WriteLine($"Generating {spec.Name}...");
// spec.Build(options.GenerateSchema);
spec.Build();
}
catch (Exception ex)
{
failures[spec.Name] = ex.Message;
}
}
// defines the filter to be the first argument
string? filter = options.Filter;
if (filter is not null)
{
Console.WriteLine($"Filtering to only generate specifications matching '{filter}'");
}
foreach (Specification spec in rpSpecs)
{
if (filter is not null && spec.Name != filter)
{
Console.WriteLine($"Skipping {spec.Name}...");
continue;
}
try
{
Console.WriteLine($"Generating {spec.Name}...");
// spec.Build(options.GenerateSchema);
spec.Build();
}
catch (Exception ex)
{
failures[spec.Name] = ex.Message;
}
}
Console.WriteLine("\n\nFinished generating all specifications.\n\n");
if (failures.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
foreach (KeyValuePair<string, string> failure in failures)
{
Console.WriteLine($"{failure.Key}: {failure.Value}");
Console.WriteLine("\n\n");
}
}
Console.WriteLine($"{failures.Count} Failure{(failures.Count == 1 ? "" : "s")}.\n");

return failures.Count == 0 ? 0 : 1;
}
}
Console.WriteLine($"{failures.Count} Failure{(failures.Count == 1 ? "" : "s")}.\n");