Skip to content

Commit

Permalink
List credentials for different users via parameter --user (Azure#1111)
Browse files Browse the repository at this point in the history
* List credentials for different users via parameter `--user`

* fix the description

* aks-preview extension release v0.4.25

* update index.json

Co-authored-by: Zim Kalinowski <zikalino@microsoft.com>
  • Loading branch information
bingosummer and Zim Kalinowski committed Jan 9, 2020
1 parent d43e2ff commit e9e953e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/aks-preview/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

Release History
===============
0.4.25
+++++
* List credentials for different users via parameter `--user`

0.4.24
+++++
* added custom header support

0.4.23
+++++
* Enable GA support of apiserver authorized IP ranges via paramater `--api-server-authorized-ip-ranges` in `az aks create` and `az aks update`
* Enable GA support of apiserver authorized IP ranges via parameter `--api-server-authorized-ip-ranges` in `az aks create` and `az aks update`

0.4.21
+++++
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@
- name: --admin -a
type: bool
short-summary: "Get cluster administrator credentials. Default: cluster user credentials."
- name: --user -u
type: string
short-summary: "Get credentials for the user. Only valid when --admin is False. Default: cluster user credentials."
- name: --file -f
type: string
short-summary: Kubernetes configuration file to update. Use "-" to print YAML to stdout instead.
Expand Down
3 changes: 2 additions & 1 deletion src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
validate_ssh_key, validate_max_pods, validate_nodes_count, validate_ip_ranges,
validate_nodepool_name, validate_vm_set_type, validate_load_balancer_sku,
validate_load_balancer_outbound_ips, validate_load_balancer_outbound_ip_prefixes,
validate_taints, validate_priority, validate_eviction_policy, validate_acr)
validate_taints, validate_priority, validate_eviction_policy, validate_acr, validate_user)


def load_arguments(self, _):
Expand Down Expand Up @@ -142,6 +142,7 @@ def load_arguments(self, _):

with self.argument_context('aks get-credentials') as c:
c.argument('admin', options_list=['--admin', '-a'], default=False)
c.argument('user', options_list=['--user', '-u'], default='clusterUser', validator=validate_user)
c.argument('path', options_list=['--file', '-f'], type=file_type, completer=FilesCompleter(),
default=os.path.join(os.path.expanduser('~'), '.kube', 'config'))

Expand Down
6 changes: 6 additions & 0 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,9 @@ def validate_eviction_policy(namespace):
def validate_acr(namespace):
if namespace.attach_acr and namespace.detach_acr:
raise CLIError('Cannot specify "--attach-acr" and "--detach-acr" at the same time.')


def validate_user(namespace):
if namespace.user.lower() != "clusteruser" and \
namespace.user.lower() != "clustermonitoringuser":
raise CLIError("--user can only be clusterUser or clusterMonitoringUser")
9 changes: 7 additions & 2 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,14 +1069,19 @@ def aks_get_credentials(cmd, # pylint: disable=unused-argument
resource_group_name,
name,
admin=False,
user='clusterUser',
path=os.path.join(os.path.expanduser('~'), '.kube', 'config'),
overwrite_existing=False):
credentialResults = None
if admin:
credentialResults = client.list_cluster_admin_credentials(resource_group_name, name)
else:
credentialResults = client.list_cluster_user_credentials(resource_group_name, name)

if user.lower() == 'clusteruser':
credentialResults = client.list_cluster_user_credentials(resource_group_name, name)
elif user.lower() == 'clustermonitoringuser':
credentialResults = client.list_cluster_monitoring_user_credentials(resource_group_name, name)
else:
raise CLIError("The user is invalid.")
if not credentialResults:
raise CLIError("No Kubernetes credentials found.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,71 @@ def list_cluster_user_credentials(
return deserialized
list_cluster_user_credentials.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterUserCredential'}

def list_cluster_monitoring_user_credentials(
self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config):
"""Gets cluster monitoring user credential of a managed cluster.
Gets cluster monitoring user credential of the managed cluster with a
specified resource group and name.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:param resource_name: The name of the managed cluster resource.
:type resource_name: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: CredentialResults or ClientRawResponse if raw=true
:rtype:
~azure.mgmt.containerservice.v2019_10_01.models.CredentialResults or
~msrest.pipeline.ClientRawResponse
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
# Construct URL
url = self.list_cluster_monitoring_user_credentials.metadata['url']
path_format_arguments = {
'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', min_length=1),
'resourceName': self._serialize.url("resource_name", resource_name, 'str', max_length=63, min_length=1, pattern=r'^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
if self.config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
if custom_headers:
header_parameters.update(custom_headers)
if self.config.accept_language is not None:
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
exp = CloudError(response)
exp.request_id = response.headers.get('x-ms-request-id')
raise exp

deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('CredentialResults', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
list_cluster_monitoring_user_credentials.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterMonitoringUserCredential'}

def get(
self, resource_group_name, resource_name, custom_headers=None, raw=False, **operation_config):
"""Gets a managed cluster.
Expand Down
2 changes: 1 addition & 1 deletion src/aks-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from codecs import open as open1
from setuptools import setup, find_packages

VERSION = "0.4.24"
VERSION = "0.4.25"
CLASSIFIERS = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
Expand Down
10 changes: 5 additions & 5 deletions src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
],
"aks-preview": [
{
"downloadUrl": "https://azurecliaks.blob.core.windows.net/azure-cli-extension/aks_preview-0.4.24-py2.py3-none-any.whl",
"filename": "aks_preview-0.4.24-py2.py3-none-any.whl",
"downloadUrl": "https://azurecliaks.blob.core.windows.net/azure-cli-extension/aks_preview-0.4.25-py2.py3-none-any.whl",
"filename": "aks_preview-0.4.25-py2.py3-none-any.whl",
"metadata": {
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.49",
Expand Down Expand Up @@ -88,9 +88,9 @@
"metadata_version": "2.0",
"name": "aks-preview",
"summary": "Provides a preview for upcoming AKS features",
"version": "0.4.24"
"version": "0.4.25"
},
"sha256Digest": "93e70b30da3620975b52b5fe8ae8b97064ce8ba9922d4fbd33dcdaf68a2c861f"
"sha256Digest": "58f04bc4417783b102ae83481338e9a16567a9183a021dff5a1f6c444b591f80"
}
],
"alias": [
Expand Down Expand Up @@ -2626,4 +2626,4 @@
]
},
"formatVersion": "1"
}
}

0 comments on commit e9e953e

Please sign in to comment.