Skip to content

Commit

Permalink
Add worklaod identity as option for schema manager (#4766)
Browse files Browse the repository at this point in the history
* Add worklaod identity as option for schema manager

* remove incorrect test file

* move resources to correct location
  • Loading branch information
mikaelweave authored Jan 7, 2025
1 parent 30c0e50 commit 9937414
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Microsoft.Health.Fhir.SchemaManager/ApplyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public ApplyCommand(
AddOption(CommandOptions.ConnectionStringOption());
AddOption(CommandOptions.ManagedIdentityClientIdOption());
AddOption(CommandOptions.AuthenticationTypeOption());
AddOption(CommandOptions.EnableWorkloadIdentityOptions());
AddOption(CommandOptions.VersionOption());
AddOption(CommandOptions.NextOption());
AddOption(CommandOptions.LatestOption());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static IConfigurationBuilder AddSchemaCommandLine(this IConfigurationBuil
{ OptionAliases.ManagedIdentityClientId, OptionAliases.ManagedIdentityClientId },
{ OptionAliases.AuthenticationType, OptionAliases.AuthenticationType },
{ OptionAliases.Version, OptionAliases.Version },
{ OptionAliases.EnableWorkloadIdentityShort, OptionAliases.EnableWorkloadIdentity },
{ OptionAliases.EnableWorkloadIdentity, OptionAliases.EnableWorkloadIdentity },
};

configurationBuilder.AddCommandLine(args, switchMappings);
Expand Down
14 changes: 14 additions & 0 deletions src/Microsoft.Health.Fhir.SchemaManager/CommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public static Option AuthenticationTypeOption()
return authenticationTypeOption;
}

public static Option<string> EnableWorkloadIdentityOptions()
{
var enableWorkloadIdentityOptions = new Option<string>(
name: OptionAliases.EnableWorkloadIdentity,
description: Resources.EnableWorkloadIdentityDescription)
{
Arity = ArgumentArity.ZeroOrOne,
};

enableWorkloadIdentityOptions.AddAlias(OptionAliases.EnableWorkloadIdentityShort);

return enableWorkloadIdentityOptions;
}

public static Option VersionOption()
{
var versionOption = new Option<int>(
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.Health.Fhir.SchemaManager/OptionAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static class OptionAliases
public const string AuthenticationTypeShort = "-at";
public const string ConnectionString = "--connection-string";
public const string ConnectionStringShort = "-cs";
public const string EnableWorkloadIdentity = "--enable-workload-identity";
public const string EnableWorkloadIdentityShort = "-wi";
public const string Force = "--force";
public const string ForceShort = "-f";
public const string Latest = "--latest";
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<data name="ConnectionStringRequiredValidation" xml:space="preserve">
<value>You must include a connection string.</value>
</data>
<data name="EnableWorkloadIdentityDescription" xml:space="preserve">
<value>Enables the use of workload identity over managed identity.</value>
</data>
<data name="ForceOptionDescription" xml:space="preserve">
<value>The schema migration is run without validating the specified schema version.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public static IServiceCollection AddSchemaManager(this IServiceCollection servic

services.AddSqlServerManagement<SchemaVersion>();

// Optionally add support for Workload Identity
if (bool.TryParse(config[OptionAliases.EnableWorkloadIdentity], out bool enableWorkloadIdentity) && enableWorkloadIdentity)
{
services.EnableWorkloadManagedIdentity();
}

services.AddSingleton<BaseSchemaRunner>();
services.AddSingleton<IBaseSchemaRunner, FhirBaseSchemaRunner>();

Expand Down

0 comments on commit 9937414

Please sign in to comment.