Skip to content
Draft
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
8 changes: 8 additions & 0 deletions src/site/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Release History
===============

1.0.0b2
++++++
* Add `az site key create` command to create site keys linked to Azure Edge sites.
* Add `az site key show` command to get details of a specific site key.
* Add `az site key list` command to list all site keys in a resource group.
* Add `az site key delete` command to delete a site key.
* Add `az site key download` command to download a site key token to a file.

1.0.0b1
++++++
* Initial release.
50 changes: 50 additions & 0 deletions src/site/azext_site/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,53 @@
# pylint: disable=too-many-lines

from knack.help_files import helps # pylint: disable=unused-import

helps['site key'] = """
type: group
short-summary: Manage Site Keys for Azure Edge sites.
"""

helps['site key create'] = """
type: command
short-summary: Create a site key linked to a site.
examples:
- name: Create a site key
text: az site key create --name TestSiteKeyName --resource-group TestRGName --site-name TestSiteName
- name: Create a site key with custom token expiry
text: az site key create --name TestSiteKeyName --resource-group TestRGName --site-name TestSiteName --token-expiry-date "2026-05-01T00:00:00Z"
"""

helps['site key delete'] = """
type: command
short-summary: Delete a site key.
examples:
- name: Delete a site key
text: az site key delete --name TestSiteKeyName --resource-group TestRGName
"""

helps['site key list'] = """
type: command
short-summary: List all site keys in a resource group.
examples:
- name: List site keys
text: az site key list --resource-group TestRGName
"""

helps['site key show'] = """
type: command
short-summary: Get details of a specific site key.
examples:
- name: Show a site key
text: az site key show --name TestSiteKeyName --resource-group TestRGName
"""

helps['site key download'] = """
type: command
short-summary: Download the token for a site key.
long-summary: Downloads the site key token and saves it to a file. If --file is not specified, the token is saved to <key-name>.SiteKey in the current directory.
examples:
- name: Download a site key token
text: az site key download --name TestSiteKeyName --resource-group TestRGName
- name: Download to a specific file
text: az site key download --name TestSiteKeyName --resource-group TestRGName --file ./my-token.SiteKey
"""
23 changes: 23 additions & 0 deletions src/site/azext_site/aaz/latest/site/key/__cmd_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"site key",
)
class __CMDGroup(AAZCommandGroup):
"""Manage Site Keys for Azure Edge sites.
"""
pass


__all__ = ["__CMDGroup"]
16 changes: 16 additions & 0 deletions src/site/azext_site/aaz/latest/site/key/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._create import *
from ._delete import *
from ._list import *
from ._show import *
from ._download import *
272 changes: 272 additions & 0 deletions src/site/azext_site/aaz/latest/site/key/_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command(
"site key create",
)
class Create(AAZCommand):
"""Create a site key linked to a site.

:example: Create a site key at resource group scope
az site key create --name TestSiteKeyName --resource-group TestRGName --site-name TestSiteName

:example: Create a site key with custom token expiry
az site key create --name TestSiteKeyName --resource-group TestRGName --site-name TestSiteName --token-expiry-date "2026-05-01T00:00:00Z"
"""

_aaz_info = {
"version": "2026-04-01-preview",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.edge/sitekeys/{}", "2026-04-01-preview"],
]
}

def _handler(self, command_args):
super()._handler(command_args)
self._execute_operations()
return self._output()

_args_schema = None

@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
if cls._args_schema is not None:
return cls._args_schema
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)

# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.resource_group = AAZResourceGroupNameArg(
help="Name of the resource group",
required=True,
)
_args_schema.site_key_name = AAZStrArg(
options=["-n", "--name", "--site-key-name"],
help="Name of the SiteKey",
required=True,
fmt=AAZStrArgFormat(
pattern="^[a-zA-Z0-9][a-zA-Z0-9-_]{2,22}[a-zA-Z0-9]$",
),
)

# define Arg Group "Properties"

_args_schema = cls._args_schema
_args_schema.site_name = AAZStrArg(
options=["--site-name"],
arg_group="Properties",
help="Name of the site to link this key to. Used to construct the site ARM resource ID.",
required=True,
)
_args_schema.token_expiry_date = AAZStrArg(
options=["--token-expiry-date"],
arg_group="Properties",
help="Token expiry date in ISO 8601 format (e.g., 2026-05-01T00:00:00Z). Defaults to 7 days from now.",
)
# Hidden arg to hold the computed ARM resource ID for the site
_args_schema.site_resource_id = AAZStrArg(
options=["--site-resource-id"],
help="Full ARM resource ID of the site (computed automatically from --site-name).",
registered=False, # hidden from CLI
)
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
self.SiteKeysCreateOrUpdate(ctx=self.ctx)()
self.post_operations()

@register_callback
def pre_operations(self):
# Construct siteResourceId from --site-name, --resource-group, and subscription
args = self.ctx.args
site_resource_id = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Edge/sites/{}".format(
self.ctx.subscription_id,
args.resource_group.to_serialized_data(),
args.site_name.to_serialized_data(),
)
args.site_resource_id = site_resource_id

@register_callback
def post_operations(self):
pass

def _output(self, *args, **kwargs):
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
return result

class SiteKeysCreateOrUpdate(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
request = self.make_request()
session = self.client.send_request(request=request, stream=False, **kwargs)
if session.http_response.status_code in [200, 201]:
return self.on_200_201(session)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/siteKeys/{siteKeyName}",
**self.url_parameters
)

@property
def method(self):
return "PUT"

@property
def error_format(self):
return "MgmtErrorFormat"

@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"resourceGroupName", self.ctx.args.resource_group,
required=True,
),
**self.serialize_url_param(
"siteKeyName", self.ctx.args.site_key_name,
required=True,
),
**self.serialize_url_param(
"subscriptionId", self.ctx.subscription_id,
required=True,
),
}
return parameters

@property
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2026-04-01-preview",
required=True,
),
}
return parameters

@property
def header_parameters(self):
parameters = {
**self.serialize_header_param(
"Content-Type", "application/json",
),
**self.serialize_header_param(
"Accept", "application/json",
),
}
return parameters

@property
def content(self):
_content_value, _builder = self.new_content_builder(
self.ctx.args,
typ=AAZObjectType,
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
)
_builder.set_prop("identity", AAZObjectType)
_builder.set_prop("properties", AAZObjectType)

identity = _builder.get(".identity")
if identity is not None:
identity.set_const("type", "SystemAssigned", AAZStrType)

properties = _builder.get(".properties")
if properties is not None:
properties.set_prop("siteResourceId", AAZStrType, ".site_resource_id")
properties.set_prop("tokenExpiryDate", AAZStrType, ".token_expiry_date")

return self.serialize_content(_content_value)

def on_200_201(self, session):
data = self.deserialize_http_content(session)
self.ctx.set_var(
"instance",
data,
schema_builder=self._build_schema_on_200_201
)

_schema_on_200_201 = None

@classmethod
def _build_schema_on_200_201(cls):
if cls._schema_on_200_201 is not None:
return cls._schema_on_200_201

cls._schema_on_200_201 = AAZObjectType()

_schema_on_200_201 = cls._schema_on_200_201
_schema_on_200_201.id = AAZStrType(
flags={"read_only": True},
)
_schema_on_200_201.name = AAZStrType(
flags={"read_only": True},
)
_schema_on_200_201.properties = AAZObjectType()
_schema_on_200_201.system_data = AAZObjectType(
serialized_name="systemData",
flags={"read_only": True},
)
_schema_on_200_201.type = AAZStrType(
flags={"read_only": True},
)

properties = cls._schema_on_200_201.properties
properties.generated_date = AAZStrType(
serialized_name="generatedDate",
flags={"read_only": True},
)
properties.provisioning_state = AAZStrType(
serialized_name="provisioningState",
flags={"read_only": True},
)
properties.site_resource_id = AAZStrType(
serialized_name="siteResourceId",
)
properties.token_expiry_date = AAZStrType(
serialized_name="tokenExpiryDate",
)

system_data = cls._schema_on_200_201.system_data
system_data.created_at = AAZStrType(
serialized_name="createdAt",
)
system_data.created_by = AAZStrType(
serialized_name="createdBy",
)
system_data.created_by_type = AAZStrType(
serialized_name="createdByType",
)
system_data.last_modified_at = AAZStrType(
serialized_name="lastModifiedAt",
)
system_data.last_modified_by = AAZStrType(
serialized_name="lastModifiedBy",
)
system_data.last_modified_by_type = AAZStrType(
serialized_name="lastModifiedByType",
)

return cls._schema_on_200_201


class _CreateHelper:
"""Helper class for Create"""


__all__ = ["Create"]
Loading
Loading