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

rbac: improve 'create-for-rbac' #1499

Merged
merged 4 commits into from
Dec 8, 2016
Merged

Conversation

yugangw-msft
Copy link
Contributor

@yugangw-msft yugangw-msft commented Dec 7, 2016

Fix #1190, Fix #1332
Includes:

  1. Make it reliable with retires, while the root cause of the replicate latency is being tracked by ICM ticket and investigated by AAD service team
  2. Default to create a role assignment, using the scope of current subscription root with role of "contributor".
  3. Support re-entry in the command. Say, if you have SP created in the previous run, you can run it again to continue to the end

//cc: @colemickens, @ahmetalpbalkan

@yugangw-msft
Copy link
Contributor Author

//cc: @derekbekoe @tjprescott

def _create_role_assignment(role, assignee, resource_group_name=None, scope=None,
ocp_aad_session_key=None):
def _create_role_assignment(role, assignee, resource_group_name=None, scope=None, #pylint: disable=too-many-arguments
ocp_aad_session_key=None, resolve_assignee=True):
Copy link
Member

Choose a reason for hiding this comment

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

Should we have help for this parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is an internal method which is not exposed as a command

@@ -399,18 +399,22 @@ def _build_application_creds(password=None, key_value=None, key_type=None,#pylin
def create_service_principal(identifier):
return _create_service_principal(identifier)

def _create_service_principal(identifier, retain_raw_response=False):
def _create_service_principal(identifier, retain_raw_response=False, resolve_app=True):
Copy link
Member

Choose a reason for hiding this comment

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

Add help for this parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same like my previous comment

import time
graph_client = _graph_client_factory()
role_client = _auth_client_factory().role_assignments
role = role or 'contributor'
Copy link
Member

Choose a reason for hiding this comment

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

The parameter default is Contributor. Does the casing matter?
Actually, do you need this or statement if there is a default set at the top?

Copy link
Contributor Author

@yugangw-msft yugangw-msft Dec 7, 2016

Choose a reason for hiding this comment

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

Casing doesn't matter, but yes this code is redundant as we have a default set at the top

time.sleep(5)
else:
logger.warning("Creating service principal failed for appid '%s'. Trace followed:\n%s",
name, ex.response.headers) #pylint: disable=no-member
Copy link
Member

Choose a reason for hiding this comment

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

Should we log the detailed trace to logger.debug and then raise CLIError("Creating service principal failed for appid '%s'.").

It appears that logging a warning and then calling raise would print the full stacktrace to the console?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let us do it later.
For now, logging as a warn by default will display the correlation id to give it to the service team to investigate. Using --debug changes the timing and hence it becomes hard to reproduce.

except Exception as ex: #pylint: disable=broad-except
#pylint: disable=line-too-long
if 'The appId of the service principal does not reference a valid application object' in str(ex):
time.sleep(5)
Copy link
Member

Choose a reason for hiding this comment

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

Consider: Add logger.warning message indicating that it is retrying something and what retry number you're currently on e.g. (Retry 3/12).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

break
except Exception as ex:
if ' does not exist in the directory ' in str(ex):
time.sleep(5)
Copy link
Member

Choose a reason for hiding this comment

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

Again, suggest retry warning messages so user is informed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

@yugangw-msft
Copy link
Contributor Author

@derekbekoe, please take another look.

@derekbekoe
Copy link
Member

@yugangw-msft Have the changes been pushed here?

@yugangw-msft
Copy link
Contributor Author

@derekbekoe, sorry, I just now pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants