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

ad: clarify the confusion between displayName and service principal name #7651

Merged
merged 1 commit into from
Oct 23, 2018
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
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-role/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release History
===============
2.1.9
++++++
* `ad sp create-for-rbac`: clarify the confusion between displayName and service principal name
* support grant permissions to AAD apps

2.1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
short-summary: Create a service principal and configure its access to Azure resources.
parameters:
- name: --name -n
short-summary: Name or app URI to associate the RBAC with. If not present, a name will be generated.
short-summary: a URI to use as the logic name. It doesn't need to exist. If not present, CLI will generate one.
- name: --password -p
short-summary: The password used to log in.
long-summary: If not present and `--cert` is not specified, a random password will be generated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,14 +1028,18 @@ def create_service_principal_for_rbac(

app_display_name = None
if name and '://' not in name:
prefix = "http://"
app_display_name = name
name = "http://" + name # normalize be a valid graph service principal name
logger.warning('Changing "%s" to a valid URI of "%s%s", which is the required format'
' used for service principal names', name, prefix, name)
name = prefix + name # normalize be a valid graph service principal name

if name:
query_exp = 'servicePrincipalNames/any(x:x eq \'{}\')'.format(name)
aad_sps = list(graph_client.service_principals.list(filter=query_exp))
if aad_sps:
raise CLIError("'{}' already exists.".format(name))
app_display_name = name.split('://')[-1]

app_start_date = datetime.datetime.now(TZ_UTC)
app_end_date = app_start_date + relativedelta(years=years or 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def test_create_for_rbac_password_plumbed_through(self, graph_client_mock, auth_
# assert
self.assertEqual(result['password'], test_pwd)
self.assertEqual(result['name'], 'http://' + name)
self.assertEqual(result['displayName'], name)
self.assertEqual(result['appId'], test_app_id)

@mock.patch('azure.cli.command_modules.role.custom._auth_client_factory', autospec=True)
Expand Down