-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,48 @@ | ||
using ARI.Commands; | ||
using Microsoft.Extensions.Configuration.Memory; | ||
using Microsoft.Extensions.Configuration; | ||
using Spectre.Console.Cli.Extensions.DependencyInjection; | ||
using Azure.Core; | ||
using Azure.Identity; | ||
|
||
var serviceCollection = new ServiceCollection() | ||
.AddCakeCore() | ||
.AddLogging(configure => | ||
configure | ||
.AddSimpleConsole(opts => | ||
public partial class Program | ||
{ | ||
static partial void AddServices(IServiceCollection services) | ||
{ | ||
services | ||
.AddCakeCore() | ||
.AddSingleton<AzureTokenService>( | ||
async (tenantId, scope) => | ||
{ | ||
opts.TimestampFormat = "yyyy-MM-dd HH:mm:ss "; | ||
}) | ||
.AddConfiguration( | ||
new ConfigurationBuilder() | ||
.Add(new MemoryConfigurationSource | ||
{ | ||
InitialData = new Dictionary<string, string?> | ||
{ | ||
{ "LogLevel:System.Net.Http.HttpClient", "Warning" } | ||
} | ||
}) | ||
.Build() | ||
)) | ||
.AddSingleton<AzureTokenService>( | ||
async (tenantId, scope) => | ||
{ | ||
var tokenCredential = new DefaultAzureCredential(); | ||
var accessToken = await tokenCredential.GetTokenAsync( | ||
new TokenRequestContext( | ||
tenantId: tenantId, | ||
scopes: new string[] { | ||
scope ?? "https://management.azure.com/.default" | ||
} | ||
) | ||
); | ||
return accessToken; | ||
} | ||
) | ||
.AddSingleton<InventoryCommand>() | ||
.AddSingleton<TokenService>() | ||
.AddSingleton<TenantService>() | ||
.AddSingleton<SubscriptionService>() | ||
.AddSingleton<ResourceGroupService>() | ||
.AddSingleton<ResourceService>() | ||
.AddSingleton<WebAppConfigService>() | ||
.AddSingleton<WebAppSettingsService>() | ||
.AddSingleton<MarkdownServiceBase, WebAppConfigurationServiceMarkdownService>() | ||
.AddSingleton<MarkdownServiceBase, WebAppSettingsServiceMarkdownService>(); | ||
|
||
serviceCollection.AddHttpClient(); | ||
var tokenCredential = new DefaultAzureCredential(); | ||
var accessToken = await tokenCredential.GetTokenAsync( | ||
new TokenRequestContext( | ||
tenantId: tenantId, | ||
scopes: [ | ||
scope ?? "https://management.azure.com/.default" | ||
] | ||
) | ||
); | ||
return accessToken; | ||
} | ||
) | ||
.AddSingleton<InventoryCommand>() | ||
.AddSingleton<TokenService>() | ||
.AddSingleton<TenantService>() | ||
.AddSingleton<SubscriptionService>() | ||
.AddSingleton<ResourceGroupService>() | ||
.AddSingleton<ResourceService>() | ||
.AddSingleton<WebAppConfigService>() | ||
.AddSingleton<WebAppSettingsService>() | ||
.AddSingleton<MarkdownServiceBase, WebAppConfigurationServiceMarkdownService>() | ||
.AddSingleton<MarkdownServiceBase, WebAppSettingsServiceMarkdownService>(); | ||
|
||
using var registrar = new DependencyInjectionRegistrar(serviceCollection); | ||
var app = new CommandApp(registrar); | ||
services.AddHttpClient(); | ||
} | ||
|
||
app.Configure( | ||
config => | ||
static partial void ConfigureApp(AppServiceConfig appServiceConfig) | ||
{ | ||
config.SetApplicationName("ari"); | ||
config.ValidateExamples(); | ||
appServiceConfig.SetApplicationName("ari"); | ||
|
||
config.AddCommand<InventoryCommand>("inventory") | ||
appServiceConfig.AddCommand<InventoryCommand>("inventory") | ||
.WithDescription("Example inventory command.") | ||
.WithExample(new[] { "inventory", "00000000-0000-0000-0000-000000000000", "outputpath" }); | ||
|
||
config.SetExceptionHandler( | ||
(ex , _) => AnsiConsole.WriteException(ex, ExceptionFormats.ShowLinks) | ||
); | ||
}); | ||
|
||
return await app.RunAsync(args); | ||
.WithExample(["inventory", "00000000-0000-0000-0000-000000000000", "outputpath"]); | ||
} | ||
} |