Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify the tenantId #254

Merged
merged 1 commit into from
May 31, 2024
Merged
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
9 changes: 9 additions & 0 deletions migrationTool/GlobalOptionsBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ internal class GlobalOptionsBinder : BinderBase<GlobalOptions>
description: @"The directory where the logs are written. Defaults to the working directory"
);

private static readonly Option<string> _tenant = new Option<string>(
aliases: new[] { "--tenant" },
description: "The azure tenant to use")
{
Arity = ArgumentArity.ExactlyOne
};

private static readonly Option<string> _subscription = new Option<string>(
aliases: new[] { "--subscription", "-s" },
description: "The azure subscription to use")
Expand Down Expand Up @@ -51,6 +58,7 @@ public Command GetCommand()
var command = new RootCommand("Azure Media Services migration tool");
command.AddGlobalOption(_logLevel);
command.AddGlobalOption(_logDirectory);
command.AddGlobalOption(_tenant);
command.AddGlobalOption(_subscription);
command.AddGlobalOption(_resourceGroup);

Expand All @@ -60,6 +68,7 @@ public Command GetCommand()
public static GlobalOptions GetValue(BindingContext bindingContext)
{
return new GlobalOptions(
bindingContext.ParseResult.GetValueForOption(_tenant)!,
bindingContext.ParseResult.GetValueForOption(_subscription)!,
bindingContext.ParseResult.GetValueForOption(_resourceGroup)!,
CloudType.Azure, //TODO: add an option.
Expand Down
16 changes: 15 additions & 1 deletion migrationTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,22 @@ static void SetupServices(IServiceCollection collection, GlobalOptions options)
.WriteTo.File(options.LogFile)
.CreateLogger();

string tenantId = options.TenantId;
if (string.IsNullOrEmpty(tenantId))
{
collection
.AddSingleton<TokenCredential>(new DefaultAzureCredential(includeInteractiveCredentials: true));
}
else
{
var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions()
{
TenantId = tenantId,
});
collection.AddSingleton<TokenCredential>(credential);
}

collection
.AddSingleton<TokenCredential>(new DefaultAzureCredential(includeInteractiveCredentials: true))
.AddSingleton(options)
.AddSingleton(console)
.AddSingleton<IMigrationTracker<BlobContainerClient, AssetMigrationResult>, AssetMigrationTracker>()
Expand Down
1 change: 1 addition & 0 deletions migrationTool/contracts/GlobalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AMSMigrate.Contracts
{
public record GlobalOptions(
string TenantId,
string SubscriptionId,
string ResourceGroup,
CloudType CloudType,
Expand Down
Loading