Skip to content

Commit

Permalink
fixup! fs_storage: support SSH private keys authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
sebalix committed Jan 29, 2024
1 parent c0b3315 commit 11f29f1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ def _get_filesystem(self) -> fsspec.AbstractFileSystem:
# paramiko.pkey.PKey object
pkey_file = io.StringIO(options["pkey"])
pkey = self._get_ssh_private_key(

Check warning on line 383 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L382-L383

Added lines #L382 - L383 were not covered by tests
pkey_file, passphrase=options.get("passphrase")
pkey_file,
pkey_type=options.pop("pkey_type"), # Remove extra parameter
passphrase=options.get("passphrase"),
)
options["pkey"] = pkey

Check warning on line 388 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L388

Added line #L388 was not covered by tests
options = self._recursive_add_odoo_storage_path(options)
Expand Down Expand Up @@ -411,12 +413,13 @@ def _detect_ssh_private_key_type(self, pkey_file):
if keytype:
return keytype

Check warning on line 414 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L414

Added line #L414 was not covered by tests

def _get_ssh_private_key(self, pkey_file, passphrase=None):
def _get_ssh_private_key(self, pkey_file, pkey_type=None, passphrase=None):
"""Build the expected `paramiko.pkey.PKey` object."""
keytype = self._detect_ssh_private_key_type(pkey_file)
if not keytype:
if not pkey_type:
pkey_type = self._detect_ssh_private_key_type(pkey_file)

Check warning on line 419 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L419

Added line #L419 was not covered by tests
if not pkey_type:
raise paramiko.SSHException("not a valid private key file")
return SSH_PKEYS[keytype].from_private_key(pkey_file, password=passphrase)
return SSH_PKEYS[pkey_type].from_private_key(pkey_file, password=passphrase)

Check warning on line 422 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L421-L422

Added lines #L421 - L422 were not covered by tests

# Deprecated methods used to ease the migration from the storage_backend addons
# to the fs_storage addons. These methods will be removed in the future (Odoo 18)
Expand Down

0 comments on commit 11f29f1

Please sign in to comment.