Skip to content

Commit ce5e8a3

Browse files
committed
Adding support for cloud-specific authentication token.
1 parent 05a5d8f commit ce5e8a3

18 files changed

+43036
-34006
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from azure.core.credentials import TokenCredential
2+
from azure.cli.core.auth.util import resource_to_scopes
3+
4+
# Enable passing in custom token audience that takes precedence over SDK's hardcoded audience.
5+
# Users can configure an audience based on their cloud.
6+
class AppConfigurationCliCredential(TokenCredential):
7+
8+
def __init__(self, credential: TokenCredential, resource: str = None):
9+
self._impl = credential
10+
self._resource = resource
11+
12+
def get_token(self, *scopes, **kwargs):
13+
14+
if self._resource is not None:
15+
scopes = resource_to_scopes(self._resource)
16+
17+
return self._impl.get_token(*scopes, **kwargs)

src/azure-cli/azure/cli/command_modules/appconfig/_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,18 @@ def get_appconfig_data_client(cmd, name, connection_string, auth_mode, endpoint)
177177
raise CLIError(str(ex) + "\nYou may be able to resolve this issue by providing App Configuration endpoint instead of name.")
178178

179179
from azure.cli.core._profile import Profile
180+
from azure.cli.core.cloud import get_active_cloud
181+
from ._credential import AppConfigurationCliCredential
180182
profile = Profile(cli_ctx=cmd.cli_ctx)
181183
cred, _, _ = profile.get_login_credentials()
184+
185+
current_cloud = get_active_cloud(cmd.cli_ctx)
186+
token_audience = None
187+
if hasattr(current_cloud.endpoints, "appconfig_auth_token_audience"):
188+
token_audience = current_cloud.endpoints.appconfig_auth_token_audience
189+
182190
try:
183-
azconfig_client = AzureAppConfigurationClient(credential=cred,
191+
azconfig_client = AzureAppConfigurationClient(credential=AppConfigurationCliCredential(cred._credential, token_audience),
184192
base_url=endpoint,
185193
user_agent=HttpHeaders.USER_AGENT)
186194
except (ValueError, TypeError) as ex:

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_appconfig_to_appconfig_import_export.yaml

Lines changed: 1533 additions & 1398 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_aad_auth.yaml

Lines changed: 1196 additions & 897 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_credential.yaml

Lines changed: 733 additions & 577 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_feature_filter.yaml

Lines changed: 6506 additions & 5213 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_identity.yaml

Lines changed: 210 additions & 160 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_import_export.yaml

Lines changed: 12147 additions & 9170 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_import_export_naming_conventions.yaml

Lines changed: 2870 additions & 2312 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/appconfig/tests/latest/recordings/test_azconfig_import_export_new_fm_schema.yaml

Lines changed: 3122 additions & 2500 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)