Skip to content

Commit 1ff741f

Browse files
authored
Merge pull request #2 from jneprz/personal/johnli1/simplify_sftp
Personal/johnli1/simplify sftp
2 parents 778aa7e + e73af1f commit 1ff741f

30 files changed

+2854
-2958
lines changed

src/sftp/azext_sftp/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ def __init__(self, cli_ctx=None):
3333
from azure.cli.core.commands import CliCommandType
3434
from azext_sftp._client_factory import cf_sftp
3535

36-
sftp_custom = CliCommandType(
37-
operations_tmpl='azext_sftp.custom#{}',
38-
client_factory=cf_sftp)
39-
40-
super(SftpCommandsLoader, self).__init__(
36+
super().__init__(
4137
cli_ctx=cli_ctx,
42-
custom_command_type=sftp_custom)
38+
custom_command_type=CliCommandType(
39+
operations_tmpl='azext_sftp.custom#{}',
40+
client_factory=cf_sftp))
4341

4442
def load_command_table(self, args):
4543
"""Load the command table for SFTP commands."""

src/sftp/azext_sftp/_help.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
helps['sftp'] = """
1111
type: group
12-
short-summary: Commands to connect to Azure Storage Accounts via SFTP
12+
short-summary: Generate SSH certificates and access Azure Storage blob data via SFTP
1313
long-summary: |
1414
These commands allow you to generate certificates and connect to Azure Storage Accounts using SFTP.
1515
@@ -46,16 +46,16 @@
4646
The certificate can be used with 'az sftp connect' or with standard SFTP clients.
4747
examples:
4848
- name: Generate a certificate using an existing public key
49-
text: az sftp cert --public-key-file ~/.ssh/id_rsa.pub --file ~/my_cert.pub
49+
text: az sftp cert --public-key-file ~/.ssh/id_rsa.pub --output-file ~/my_cert.pub
5050
- name: Generate a certificate and create a new key pair in the same directory
51-
text: az sftp cert --file ~/my_cert.pub
51+
text: az sftp cert --output-file ~/my_cert.pub
5252
- name: Generate a certificate with custom SSH client folder
53-
text: az sftp cert --file ~/my_cert.pub --ssh-client-folder "C:\\Program Files\\OpenSSH"
53+
text: az sftp cert --output-file ~/my_cert.pub --ssh-client-folder "C:\\Program Files\\OpenSSH"
5454
"""
5555

5656
helps['sftp connect'] = """
5757
type: command
58-
short-summary: Connect to Azure Storage Account via SFTP
58+
short-summary: Access Azure Storage blob data via SFTP
5959
long-summary: |
6060
Establish an SFTP connection to an Azure Storage Account.
6161
@@ -79,7 +79,7 @@
7979
SECURITY:
8080
- Generated credentials are automatically cleaned up after connection
8181
- Temporary files stored in secure temporary directories
82-
- Certificate validity is checked and renewed if expired
82+
- OpenSSH handles certificate validation during connection
8383
examples:
8484
- name: Connect with automatic certificate generation (fully managed - RECOMMENDED)
8585
text: az sftp connect --storage-account mystorageaccount

src/sftp/azext_sftp/_params.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
def load_arguments(self, _):
99

1010
with self.argument_context('sftp cert') as c:
11-
c.argument('cert_path', options_list=['--file', '-f'],
11+
c.argument('cert_path', options_list=['--output-file', '-o'],
1212
help='The file path to write the SSH cert to, defaults to public key path with -aadcert.pub appended')
1313
c.argument('public_key_file', options_list=['--public-key-file', '-p'],
1414
help='The RSA public key file path. If not provided, '
15-
'generated key pair is stored in the same directory as --file.')
15+
'generated key pair is stored in the same directory as --output-file.')
1616
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
1717
help='Folder path that contains ssh executables (ssh-keygen, ssh). '
1818
'Default to ssh executables in your PATH or C:\\Windows\\System32\\OpenSSH on Windows.')
@@ -35,10 +35,8 @@ def load_arguments(self, _):
3535
'a certificate will be generated automatically from this key.')
3636
c.argument('sftp_args', options_list=['--sftp-args'],
3737
help='Additional arguments to pass to the SFTP client. '
38-
'Example: "-v" for verbose output, "-o ConnectTimeout=30" for custom timeout.')
38+
'Example: "-v" for verbose output, "-b batchfile.txt" for batch commands, '
39+
'"-o ConnectTimeout=30" for custom timeout.')
3940
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
4041
help='Path to folder containing SSH client executables (ssh, sftp, ssh-keygen). '
4142
'Default: Uses executables from PATH or C:\\Windows\\System32\\OpenSSH on Windows.')
42-
c.argument('sftp_batch_commands', options_list=['--batch-commands'],
43-
help='SFTP batch commands to execute after connecting (non-interactive mode). '
44-
'Separate commands with \\n. Example: "ls\\nget file.txt\\nbye"')

src/sftp/azext_sftp/_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def storage_account_name_or_id_validator(cmd, namespace):
1313
Validator for storage account name or resource ID.
1414
Converts storage account name to full resource ID if needed.
1515
"""
16-
if namespace.storage_account:
16+
if hasattr(namespace, 'storage_account') and namespace.storage_account:
1717
if not is_valid_resource_id(namespace.storage_account):
1818
if not hasattr(namespace, 'resource_group_name') or not namespace.resource_group_name:
1919
raise azclierror.RequiredArgumentMissingError(

src/sftp/azext_sftp/commands.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,11 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
"""
7-
Command definitions for the Azure CLI SFTP extension.
8-
9-
This module defines the available SFTP commands and their routing
10-
to the appropriate custom functions.
11-
"""
6+
"""Command definitions for the Azure CLI SFTP extension."""
127

138

149
def load_command_table(self, _):
15-
"""
16-
Load command table for SFTP extension.
17-
18-
Commands:
19-
- sftp cert: Generate SSH certificates for SFTP authentication
20-
- sftp connect: Connect to Azure Storage Account via SFTP
21-
"""
10+
"""Load command table for SFTP extension."""
2211
with self.command_group('sftp') as g:
2312
g.custom_command('cert', 'sftp_cert')
2413
g.custom_command('connect', 'sftp_connect')

src/sftp/azext_sftp/connectivity_utils.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@
1212

1313

1414
def format_relay_info_string(relay_info):
15-
relay_info_string = json.dumps(
16-
{
17-
"relay": {
18-
"namespaceName": relay_info['namespaceName'],
19-
"namespaceNameSuffix": relay_info['namespaceNameSuffix'],
20-
"hybridConnectionName": relay_info['hybridConnectionName'],
21-
"accessKey": relay_info['accessKey'],
22-
"expiresOn": relay_info['expiresOn'],
23-
"serviceConfigurationToken": relay_info['serviceConfigurationToken']
24-
}
25-
})
26-
result_bytes = relay_info_string.encode("ascii")
27-
enc = base64.b64encode(result_bytes)
28-
base64_result_string = enc.decode("ascii")
29-
return base64_result_string
15+
"""Format relay information as base64-encoded JSON string."""
16+
relay_data = {
17+
"relay": {
18+
"namespaceName": relay_info['namespaceName'],
19+
"namespaceNameSuffix": relay_info['namespaceNameSuffix'],
20+
"hybridConnectionName": relay_info['hybridConnectionName'],
21+
"accessKey": relay_info['accessKey'],
22+
"expiresOn": relay_info['expiresOn'],
23+
"serviceConfigurationToken": relay_info['serviceConfigurationToken']
24+
}
25+
}
26+
return base64.b64encode(json.dumps(relay_data).encode("ascii")).decode("ascii")

src/sftp/azext_sftp/constants.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
# File system constants
99
WINDOWS_INVALID_FOLDERNAME_CHARS = "\\/*:<>?\"|"
1010

11-
# Default SSH/SFTP configuration
12-
DEFAULT_SSH_PORT = 22
13-
DEFAULT_SFTP_PORT = 22
14-
AZURE_STORAGE_SFTP_PORT = 22
11+
# Default ports
12+
DEFAULT_SSH_PORT = DEFAULT_SFTP_PORT = AZURE_STORAGE_SFTP_PORT = 22
1513

1614
# SSH/SFTP client configuration
1715
SSH_CONNECT_TIMEOUT = 30

0 commit comments

Comments
 (0)