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

[Role] az ad sp create-for-rbac: Add alias --json-auth for --sdk-auth #26572

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ def refresh_accounts(self):
self._set_subscriptions(result, merge=False)

def get_sp_auth_info(self, subscription_id=None, name=None, password=None, cert_file=None):
"""Generate a JSON for --sdk-auth argument when used in:
- az ad sp create-for-rbac --sdk-auth
"""Generate a JSON for --json-auth argument when used in:
- az ad sp create-for-rbac --json-auth
"""
from collections import OrderedDict
account = self.get_subscription(subscription_id)
Expand Down
7 changes: 5 additions & 2 deletions src/azure-cli/azure/cli/command_modules/role/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ def load_arguments(self, _):
help='Role of the service principal.')
c.argument('skip_assignment', arg_type=get_three_state_flag(),
deprecate_info=c.deprecate(target='--skip-assignment', hide=True), help='No-op.')
c.argument('show_auth_for_sdk', options_list='--sdk-auth', deprecate_info=c.deprecate(target='--sdk-auth'),
help='output result in compatible with Azure SDK auth file', arg_type=get_three_state_flag())
c.argument('show_auth_in_json', options_list=['--sdk-auth', '--json-auth'],
AllyW marked this conversation as resolved.
Show resolved Hide resolved
deprecate_info=c.deprecate(target='--sdk-auth'),
help='Output service principal credential along with cloud endpoints in JSON format. '
'See https://learn.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't include /en-us in URLs in case this article supports multi-language in the future.

Copy link
Member

@jiasli jiasli Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I think it may not be a good idea to include this URL. People who don't know what --sdk-auth does most likely don't need to use it as well. 🤣

If we do include the URL, please submit a PR to https://github.com/MicrosoftDocs/azure-docs-cli repo and link the PR ID here.

Or, maybe we should link to https://learn.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli at command level for better discovery.

arg_type=get_three_state_flag())

with self.argument_context('ad sp owner list') as c:
c.argument('identifier', options_list=['--id'], help='service principal name, or object id or the service principal')
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/role/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ def list_service_principal_owners(client, identifier):
def create_service_principal_for_rbac(
# pylint:disable=too-many-statements,too-many-locals, too-many-branches, unused-argument
cmd, display_name=None, years=None, create_cert=False, cert=None, scopes=None, role=None,
show_auth_for_sdk=None, skip_assignment=False, keyvault=None):
show_auth_in_json=None, skip_assignment=False, keyvault=None):
import time

if role and not scopes or not role and scopes:
Expand Down Expand Up @@ -1272,7 +1272,7 @@ def create_service_principal_for_rbac(

logger.warning(CREDENTIAL_WARNING)

if show_auth_for_sdk:
if show_auth_in_json:
from azure.cli.core._profile import Profile
profile = Profile(cli_ctx=cmd.cli_ctx)
result = profile.get_sp_auth_info(scopes[0].split('/')[2] if scopes else None,
Expand Down