-
Notifications
You must be signed in to change notification settings - Fork 1.5k
spring-cloud: add support to enable/disable MSI #1523
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| from knack.log import get_logger | ||
| from .azure_storage_file import FileService | ||
| from azure.cli.core.util import sdk_no_wait | ||
| from azure.cli.core.profiles import ResourceType, get_sdk | ||
| from ast import literal_eval | ||
| from azure.cli.core.commands import cached_put | ||
| from ._utils import _get_rg_location | ||
|
|
@@ -100,7 +101,8 @@ def app_create(cmd, client, resource_group, service, name, | |
| runtime_version=None, | ||
| jvm_options=None, | ||
| env=None, | ||
| enable_persistent_storage=None): | ||
| enable_persistent_storage=None, | ||
| assign_identity=None): | ||
| apps = _get_all_apps(client, resource_group, service) | ||
| if name in apps: | ||
| raise CLIError("App '{}' already exists.".format(name)) | ||
|
|
@@ -119,8 +121,14 @@ def app_create(cmd, client, resource_group, service, name, | |
| resource = client.services.get(resource_group, service) | ||
| location = resource.location | ||
|
|
||
| app_resource = models.AppResource() | ||
| app_resource.properties = properties | ||
| app_resource.location = location | ||
| if assign_identity is True: | ||
| app_resource.identity = models.ManagedIdentityProperties(type="systemassigned") | ||
|
|
||
| poller = client.apps.create_or_update( | ||
| resource_group, service, name, properties, location) | ||
| resource_group, service, name, app_resource) | ||
| while poller.done() is False: | ||
| sleep(APP_CREATE_OR_UPDATE_SLEEP_INTERVAL) | ||
|
|
||
|
|
@@ -147,7 +155,10 @@ def app_create(cmd, client, resource_group, service, name, | |
| properties = models.AppResourceProperties( | ||
| active_deployment_name=DEFAULT_DEPLOYMENT_NAME, public=is_public) | ||
|
|
||
| app_poller = client.apps.update(resource_group, service, name, properties, location) | ||
| app_resource.properties = properties | ||
| app_resource.location = location | ||
|
|
||
| app_poller = client.apps.update(resource_group, service, name, app_resource) | ||
| logger.warning( | ||
| "[4/4] Updating app '{}' (this operation can take a while to complete)".format(name)) | ||
| while not poller.done() or not app_poller.done(): | ||
|
|
@@ -178,9 +189,13 @@ def app_update(cmd, client, resource_group, service, name, | |
| resource = client.services.get(resource_group, service) | ||
| location = resource.location | ||
|
|
||
| app_resource = models.AppResource() | ||
| app_resource.properties = properties | ||
| app_resource.location = location | ||
|
|
||
| logger.warning("[1/2] updating app '{}'".format(name)) | ||
| poller = client.apps.update( | ||
| resource_group, service, name, properties, location) | ||
| resource_group, service, name, app_resource) | ||
| while poller.done() is False: | ||
| sleep(APP_CREATE_OR_UPDATE_SLEEP_INTERVAL) | ||
|
|
||
|
|
@@ -425,6 +440,69 @@ def app_tail_log(cmd, client, resource_group, service, name, instance=None, foll | |
| raise exceptions[0] | ||
|
|
||
|
|
||
| def app_identity_assign(cmd, client, resource_group, service, name, role=None, scope=None): | ||
| app_resource = models.AppResource() | ||
| identity = models.ManagedIdentityProperties(type="systemassigned") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you have plan to support other type? if yes better to expose type as a param with default value
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet. But we can refactor code if we will support in future. |
||
| properties = models.AppResourceProperties() | ||
| resource = client.services.get(resource_group, service) | ||
| location = resource.location | ||
|
|
||
| app_resource.identity = identity | ||
| app_resource.properties = properties | ||
| app_resource.location = location | ||
| client.apps.update(resource_group, service, name, app_resource) | ||
| app = client.apps.get(resource_group, service, name) | ||
| if role: | ||
| principal_id = app.identity.principal_id | ||
|
|
||
| from azure.cli.core.commands import arm as _arm | ||
| identity_role_id = _arm.resolve_role_id(cmd.cli_ctx, role, scope) | ||
| from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
| assignments_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_AUTHORIZATION).role_assignments | ||
| RoleAssignmentCreateParameters = get_sdk(cmd.cli_ctx, ResourceType.MGMT_AUTHORIZATION, | ||
| 'RoleAssignmentCreateParameters', mod='models', | ||
| operation_group='role_assignments') | ||
| parameters = RoleAssignmentCreateParameters(role_definition_id=identity_role_id, principal_id=principal_id) | ||
| logger.info("Creating an assignment with a role '%s' on the scope of '%s'", identity_role_id, scope) | ||
| retry_times = 36 | ||
| assignment_name = _arm._gen_guid() | ||
| for l in range(0, retry_times): | ||
| try: | ||
| assignments_client.create(scope=scope, role_assignment_name=assignment_name, | ||
| parameters=parameters) | ||
| break | ||
| except CloudError as ex: | ||
| if 'role assignment already exists' in ex.message: | ||
| logger.info('Role assignment already exists') | ||
| break | ||
| elif l < retry_times and ' does not exist in the directory ' in ex.message: | ||
| sleep(APP_CREATE_OR_UPDATE_SLEEP_INTERVAL) | ||
| logger.warning('Retrying role assignment creation: %s/%s', l + 1, | ||
| retry_times) | ||
| continue | ||
| else: | ||
| raise | ||
| return app | ||
|
|
||
|
|
||
| def app_identity_remove(cmd, client, resource_group, service, name): | ||
| app_resource = models.AppResource() | ||
| identity = models.ManagedIdentityProperties(type="none") | ||
| properties = models.AppResourceProperties() | ||
| resource = client.services.get(resource_group, service) | ||
| location = resource.location | ||
|
|
||
| app_resource.identity = identity | ||
| app_resource.properties = properties | ||
| app_resource.location = location | ||
| return client.apps.update(resource_group, service, name, app_resource) | ||
|
|
||
|
|
||
| def app_identity_show(cmd, client, resource_group, service, name): | ||
| app = client.apps.get(resource_group, service, name) | ||
| return app.identity | ||
|
|
||
|
|
||
| def app_set_deployment(cmd, client, resource_group, service, name, deployment): | ||
| deployments = _get_all_deployments(client, resource_group, service, name) | ||
| active_deployment = client.apps.get( | ||
|
|
@@ -441,7 +519,11 @@ def app_set_deployment(cmd, client, resource_group, service, name, deployment): | |
| resource = client.services.get(resource_group, service) | ||
| location = resource.location | ||
|
|
||
| return client.apps.update(resource_group, service, name, properties, location) | ||
| app_resource = models.AppResource() | ||
| app_resource.properties = properties | ||
| app_resource.location = location | ||
|
|
||
| return client.apps.update(resource_group, service, name, app_resource) | ||
|
|
||
|
|
||
| def deployment_create(cmd, client, resource_group, service, app, name, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,14 @@ class TraceProxyState(str, Enum): | |
| updating = "Updating" | ||
|
|
||
|
|
||
| class ManagedIdentityType(str, Enum): | ||
|
|
||
| none = "None" | ||
| system_assigned = "SystemAssigned" | ||
| user_assigned = "UserAssigned" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep |
||
| system_assigned_user_assigned = "SystemAssigned,UserAssigned" | ||
|
|
||
|
|
||
| class TestKeyType(str, Enum): | ||
|
|
||
| primary = "Primary" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.