Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Fix: getting started script reuse aad application (#569)
Browse files Browse the repository at this point in the history
* start fix for existing aad application

* add start_date graph rbac client bug workaround

* remove debug

* typos
  • Loading branch information
jafreck authored May 21, 2018
1 parent 603a413 commit 3d16cf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 20 additions & 5 deletions account_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml
from azure.common import credentials
from azure.graphrbac import GraphRbacManagementClient
from azure.graphrbac.models import ApplicationCreateParameters, PasswordCredential, ServicePrincipalCreateParameters
from azure.graphrbac.models import ApplicationCreateParameters, ApplicationUpdateParameters, PasswordCredential, ServicePrincipalCreateParameters
from azure.graphrbac.models.graph_error import GraphErrorException
from azure.mgmt.authorization import AuthorizationManagementClient
from azure.mgmt.batch import BatchManagementClient
Expand Down Expand Up @@ -189,6 +189,7 @@ def create_aad_user(credentials, tenant_id, **kwargs):
display_name=display_name,
password_credentials=[
PasswordCredential(
start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
value=application_credential,
key_id=uuid.uuid4()
Expand All @@ -210,7 +211,21 @@ def create_aad_user(credentials, tenant_id, **kwargs):
confirmation_prompt = "Previously created application with name {} found. "\
"Would you like to use it? (y/n): ".format(application.display_name)
prompt_for_confirmation(confirmation_prompt, e, ValueError("Response not recognized. Please try again."))

password_credentials = list(graph_rbac_client.applications.list_password_credentials(application_object_id=application.object_id))
password_credentials.append(
PasswordCredential(
start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
value=application_credential,
key_id=uuid.uuid4()
)
)
graph_rbac_client.applications.patch(
application_object_id=application.object_id,
parameters=ApplicationUpdateParameters(
password_credentials=password_credentials
)
)
service_principal = next(graph_rbac_client.service_principals.list(
filter="appId eq '{}'".format(application.app_id)))
else:
Expand Down Expand Up @@ -254,7 +269,7 @@ def create_role_assignment(credentials, subscription_id, scope, principal_id):

def format_secrets(**kwargs):
'''
Retuns the secrets for the created resources to be placed in secrets.yaml
Returns the secrets for the created resources to be placed in secrets.yaml
The following form is returned:
service_principal:
Expand Down Expand Up @@ -381,7 +396,7 @@ def stop(self):
with Spinner():
storage_account_id = create_storage_account(creds, subscription_id, **kwargs)
kwargs["storage_account_id"] = storage_account_id
print("Created Storage group.")
print("Created Storage account.")

# create batch account
with Spinner():
Expand All @@ -397,8 +412,8 @@ def stop(self):
aad_cred, subscirption_id, tenant_id = profile.get_login_credentials(
resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id
)

application_id, service_principal_object_id, application_credential = create_aad_user(aad_cred, tenant_id, **kwargs)

print("Created Azure Active Directory service principal.")

with Spinner():
Expand Down
4 changes: 2 additions & 2 deletions account_setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

echo "Installing depdendencies..." &&
echo "Installing dependencies..." &&
pip install --force-reinstall --upgrade --user pyyaml==3.12 azure==3.0.0 azure-cli-core==2.0.30 msrestazure==0.4.25 > /dev/null 2>&1 &&
echo "Finished installing depdencies." &&
echo "Finished installing dependencies." &&
echo "Getting account setup script..." &&
wget -q https://raw.githubusercontent.com/Azure/aztk/v0.7.0/account_setup.py -O account_setup.py &&
chmod 755 account_setup.py &&
Expand Down

0 comments on commit 3d16cf3

Please sign in to comment.