-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add national cloud support (#332)
feat: add national cloud support Allows logging in to national clouds using the `--environment` CLI option. See microsoftgraph/msgraph-cli#396 perf: enable concurrent io when clearing the token cache
- Loading branch information
1 parent
e9b73fc
commit f78f591
Showing
13 changed files
with
192 additions
and
62 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
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
73 changes: 73 additions & 0 deletions
73
src/Microsoft.Graph.Cli.Core/Authentication/CloudEnvironment.cs
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using Azure.Identity; | ||
using Microsoft.Graph; | ||
using Microsoft.Graph.Cli.Core.Utils; | ||
|
||
|
||
/// <summary> | ||
/// The cloud environment to use | ||
/// </summary> | ||
public enum CloudEnvironment | ||
{ | ||
/// <summary> | ||
/// Global environment. | ||
/// </summary> | ||
Global, | ||
/// <summary> | ||
/// US Government cloud environment. | ||
/// </summary> | ||
USGov, | ||
/// <summary> | ||
/// US Government Department of Defense (DoD) cloud environment. | ||
/// </summary> | ||
USGovDoD, | ||
/// <summary> | ||
/// China cloud environment. | ||
/// </summary> | ||
China, | ||
} | ||
|
||
/// <summary> | ||
/// Provides methods for the <see cref="CloudEnvironment"/> class. | ||
/// </summary> | ||
public static class CloudEnvironmentExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the authority URL for the specified cloud environment. | ||
/// </summary> | ||
/// <param name="environment">The cloud environment.</param> | ||
/// <returns>The authority URL.</returns> | ||
/// <exception cref="ArgumentException"> | ||
/// If the cloud environment is not one of the <see cref="CloudEnvironment"/> members. | ||
/// </exception> | ||
public static Uri Authority(this CloudEnvironment environment) | ||
{ | ||
return environment switch | ||
{ | ||
CloudEnvironment.Global => AzureAuthorityHosts.AzurePublicCloud, | ||
CloudEnvironment.USGov or CloudEnvironment.USGovDoD => AzureAuthorityHosts.AzureGovernment, | ||
CloudEnvironment.China => AzureAuthorityHosts.AzureChina, | ||
_ => throw new ArgumentException("Unknown cloud environment", nameof(environment)) | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the GraphClient Cloud identifier. | ||
/// </summary> | ||
/// <param name="environment">The cloud environment.</param> | ||
/// <returns>The cloud identifier to be used by the graph client.</returns> | ||
/// <exception cref="ArgumentException"> | ||
/// If the cloud environment is not one of the <see cref="CloudEnvironment"/> members. | ||
/// </exception> | ||
public static string GraphClientCloud(this CloudEnvironment environment) | ||
{ | ||
return environment switch | ||
{ | ||
CloudEnvironment.Global => GraphClientFactory.Global_Cloud, | ||
CloudEnvironment.USGov => GraphClientFactory.USGOV_Cloud, | ||
CloudEnvironment.USGovDoD => GraphClientFactory.USGOV_DOD_Cloud, | ||
CloudEnvironment.China => GraphClientFactory.China_Cloud, | ||
_ => throw new ArgumentException("Unknown cloud environment", nameof(environment)) | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.