Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/helpIndex.latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
"tags": ""
},
"sshkey": {
"summary": "Manage ssh public key with vm.",
"summary": "Manage Ssh Public Key.",
"tags": ""
},
"stack": {
Expand Down
15 changes: 0 additions & 15 deletions src/azure-cli/azure/cli/command_modules/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,11 @@ def load_command_table(self, args):
args=args
)
load_command_table(self, args)
try:
# When generated commands are required uncomment the following two lines.
from .generated.commands import load_command_table as load_command_table_generated
load_command_table_generated(self, args)
from .manual.commands import load_command_table as load_command_table_manual
load_command_table_manual(self, args)
except ImportError:
pass
return self.command_table

def load_arguments(self, command):
from azure.cli.command_modules.vm._params import load_arguments
load_arguments(self, command)
try:
from .generated._params import load_arguments as load_arguments_generated
load_arguments_generated(self, command)
from .manual._params import load_arguments as load_arguments_manual
load_arguments_manual(self, command)
except ImportError:
pass


COMMAND_LOADER_CLS = ComputeCommandsLoader
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from azure.cli.core.aaz import *


@register_command_group(
"sshkey",
)
class __CMDGroup(AAZCommandGroup):
"""Manage Ssh Public Key
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .__cmd_group import *
from ._create import *
from ._delete import *
from ._generate_key_pair import *
from ._list import *
from ._show import *
from ._update import *
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from azure.cli.core.aaz import *


@register_command(
"sshkey create",
)
class Create(AAZCommand):
"""Create a new SSH public key resource.

Expand Down Expand Up @@ -48,6 +51,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
options=["-n", "--name", "--ssh-public-key-name"],
help="The name of the SSH public key.",
required=True,
fmt=AAZStrArgFormat(
pattern="",
),
)

# define Arg Group "Parameters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from azure.cli.core.aaz import *


@register_command(
"sshkey delete",
confirmation="Are you sure you want to perform this operation?",
)
class Delete(AAZCommand):
"""Delete a SSH public key.

Expand Down Expand Up @@ -49,6 +53,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
help="The name of the SSH public key.",
required=True,
id_part="name",
fmt=AAZStrArgFormat(
pattern="",
),
)
return cls._args_schema

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# --------------------------------------------------------------------------------------------
# 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 *


class GenerateKeyPair(AAZCommand):
"""Generate an SSH public/private key pair for an SSH public key resource.

:example: Generate an RSA SSH key pair.
az sshkey generate-key-pair --resource-group myResourceGroup --ssh-public-key-name mySshPublicKeyName --encryption-type RSA
"""

_aaz_info = {
"version": "2025-04-01",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/sshpublickeys/{}/generatekeypair", "2025-04-01"],
]
}

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(
required=True,
)
_args_schema.ssh_public_key_name = AAZStrArg(
options=["--ssh-public-key-name"],
help="The name of the SSH public key.",
required=True,
id_part="name",
fmt=AAZStrArgFormat(
pattern="",
),
)

# define Arg Group "Parameters"

_args_schema = cls._args_schema
_args_schema.encryption_type = AAZStrArg(
options=["--encryption-type"],
arg_group="Parameters",
help="The encryption type of the SSH keys to be generated. See SshEncryptionTypes for possible set of values. If not provided, will default to RSA",
enum={"Ed25519": "Ed25519", "RSA": "RSA"},
)
return cls._args_schema

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

@register_callback
def pre_operations(self):
pass

@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 SshPublicKeysGenerateKeyPair(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]:
return self.on_200(session)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}/generateKeyPair",
**self.url_parameters
)

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

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

@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"resourceGroupName", self.ctx.args.resource_group,
required=True,
),
**self.serialize_url_param(
"sshPublicKeyName", self.ctx.args.ssh_public_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", "2025-04-01",
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": {"client_flatten": True}}
)
_builder.set_prop("encryptionType", AAZStrType, ".encryption_type")

return self.serialize_content(_content_value)

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

_schema_on_200 = None

@classmethod
def _build_schema_on_200(cls):
if cls._schema_on_200 is not None:
return cls._schema_on_200

cls._schema_on_200 = AAZObjectType()

_schema_on_200 = cls._schema_on_200
_schema_on_200.id = AAZStrType(
flags={"required": True},
)
_schema_on_200.private_key = AAZStrType(
serialized_name="privateKey",
flags={"required": True},
)
_schema_on_200.public_key = AAZStrType(
serialized_name="publicKey",
flags={"required": True},
)

return cls._schema_on_200


class _GenerateKeyPairHelper:
"""Helper class for GenerateKeyPair"""


__all__ = ["GenerateKeyPair"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from azure.cli.core.aaz import *


@register_command(
"sshkey list",
)
class List(AAZCommand):
"""List all of the SSH public keys in the subscription. Use the nextLink property in the response to get the next page of SSH public keys.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from azure.cli.core.aaz import *


@register_command(
"sshkey show",
)
class Show(AAZCommand):
"""Get information about a SSH public key.

Expand Down Expand Up @@ -49,6 +52,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
help="The name of the SSH public key.",
required=True,
id_part="name",
fmt=AAZStrArgFormat(
pattern="",
),
)
return cls._args_schema

Expand Down
Loading
Loading