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

Grafana: add service account support #5599

Merged
merged 8 commits into from
Dec 7, 2022
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
11 changes: 10 additions & 1 deletion src/amg/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ Release History

0.1.2
++++++
* `az grafana create`: support guess users
* `az grafana create`: support guest users

0.2.0
++++++
* `az grafana api-key`: support api keys

0.3.0
++++++
* `az grafana service-account`: support service accounts

62 changes: 62 additions & 0 deletions src/amg/azext_amg/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,65 @@
type: command
short-summary: delete an api key.
"""

helps['grafana service-account'] = """
type: group
short-summary: Commands to manage service accounts.
"""

helps['grafana service-account create'] = """
type: command
short-summary: create a new service account.
yugangw-msft marked this conversation as resolved.
Show resolved Hide resolved
examples:
- name: Create a service account with admin role
text: |
az grafana service-account create -g myResourceGroup -n myGrafana --service-account myAccount --role admin
"""

helps['grafana service-account update'] = """
type: command
short-summary: update a service account.
examples:
- name: disable a service account
text: |
az grafana service-account update -g myResourceGroup -n myGrafana --service-account myAccount --is-disabled true
"""

helps['grafana service-account show'] = """
type: command
short-summary: show details of a service account.
"""

helps['grafana service-account list'] = """
type: command
short-summary: list existing service accounts.
"""

helps['grafana service-account delete'] = """
type: command
short-summary: delete a service account.
"""

helps['grafana service-account token'] = """
type: group
short-summary: Commands to manage service account tokens.
"""

helps['grafana service-account token create'] = """
type: command
short-summary: create a new service account token.
examples:
- name: create a service account token lasting 1 day
text: |
az grafana service-account token create -g myResourceGroup -n myGrafana --service-account myAccount --token myToken --time-to-live 1d
"""

helps['grafana service-account token list'] = """
type: command
short-summary: list existing service account tokens.
"""

helps['grafana service-account token delete'] = """
type: command
short-summary: delete a service account token.
"""
33 changes: 29 additions & 4 deletions src/amg/azext_amg/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def load_arguments(self, _):
from ._validators import process_missing_resource_group_parameter
from azext_amg.vendored_sdks.models import ZoneRedundancy
grafana_name_type = CLIArgumentType(options_list="--grafana-name",
help="Name of the Azure Managed Dashboard for Grafana.",
help="Name of the Azure Managed Grafana.",
id_part="name")
grafana_role_type = CLIArgumentType(arg_type=get_enum_type(["Admin", "Editor", "Viewer"]), options_list=["--role", "-r"],
help="Grafana role name")

with self.argument_context("grafana") as c:
c.argument("tags", tags_type)
Expand All @@ -23,7 +25,8 @@ def load_arguments(self, _):
c.argument("id", help=("The identifier (id) of a dashboard/data source is an auto-incrementing "
"numeric value and is only unique per Grafana install."))
c.argument("folder", help="id, uid, title which can identify a folder. CLI will search in the order of id, uid, and title, till finds a match")
c.argument("api_key", help="api key, a randomly generated string used to interact with Grafana endpoint; if missing, CLI will use logon user's credentials")
c.argument("api_key_or_token", options_list=["--api-key", "--token", '-t'],
help="api key or service account token, a randomly generated string used to interact with Grafana endpoint; if missing, CLI will use logon user's credentials")

with self.argument_context("grafana create") as c:
c.argument("grafana_name", grafana_name_type, options_list=["--name", "-n"], validator=None)
Expand All @@ -34,7 +37,8 @@ def load_arguments(self, _):

# api_key=None, deterministic_outbound_ip=None, public_network_access=None
with self.argument_context("grafana update") as c:
c.argument("api_key", get_enum_type(["Enabled", "Disabled"]), help="If enabled, you will be able to configur Grafana api keys")
c.argument("api_key_and_service_account", get_enum_type(["Enabled", "Disabled"]), options_list=['--api-key', '--service-account'],
help="If enabled, you will be able to configur Grafana api keys and service accounts")
c.argument("deterministic_outbound_ip", get_enum_type(["Enabled", "Disabled"]), options_list=["-i", "--deterministic-outbound-ip"],
help="if enabled, the Grafana workspace will have fixed egress IPs you can use them in the firewall of datasources")

Expand All @@ -52,9 +56,12 @@ def load_arguments(self, _):
with self.argument_context("grafana dashboard import") as c:
c.argument("definition", help="The complete dashboard model in json string, Grafana gallery id, a path or url to a file with such content")

with self.argument_context("grafana") as c:
c.argument("time_to_live", default="1d", help="The life duration. For example, 1d if your key is going to last fr one day. Supported units are: s,m,h,d,w,M,y")

with self.argument_context("grafana api-key") as c:
c.argument("key_name", help="api key name")
c.argument("role", get_enum_type(["Admin", "Editor", "Viewer"]), help="Grafana role name", default="Viewer")
c.argument("role", grafana_role_type, default="Viewer")
c.argument("time_to_live", default="1d", help="The API key life duration. For example, 1d if your key is going to last fr one day. Supported units are: s,m,h,d,w,M,y")

with self.argument_context("grafana api-key create") as c:
Expand Down Expand Up @@ -85,3 +92,21 @@ def load_arguments(self, _):

with self.argument_context("grafana user") as c:
c.argument("user", help="user login name or email")

with self.argument_context("grafana service-account") as c:
c.argument("service_account", help="id or name which can identify a service account")
c.argument("is_disabled", arg_type=get_three_state_flag(), help="disable the service account. default: false")

with self.argument_context("grafana service-account create") as c:
c.argument("role", grafana_role_type, default="Viewer")
c.argument("service_account", help="service account name")

with self.argument_context("grafana service-account update") as c:
c.argument("role", grafana_role_type)
c.argument("new_name", help="new name of the service account")

with self.argument_context("grafana service-account token") as c:
c.argument("token", help="id or name which can identify a service account token")

with self.argument_context("grafana service-account token create") as c:
c.argument("token", help="name of the new service account token")
14 changes: 13 additions & 1 deletion src/amg/azext_amg/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=line-too-long,too-many-statements

from ._validators import process_grafana_create_namespace

Expand Down Expand Up @@ -57,3 +57,15 @@ def load_command_table(self, _):
g.custom_command('create', 'create_api_key')
g.custom_command('list', 'list_api_keys')
g.custom_command('delete', 'delete_api_key')

with self.command_group('grafana service-account') as g:
g.custom_command('create', 'create_service_account')
g.custom_command('list', 'list_service_accounts')
g.custom_show_command('show', 'show_service_account')
g.custom_command('delete', 'delete_service_account')
g.custom_command('update', 'update_service_account')

with self.command_group('grafana service-account token') as g:
g.custom_command('create', 'create_service_account_token')
g.custom_command('list', 'list_service_account_tokens')
g.custom_command('delete', 'delete_service_account_token')
Loading