diff --git a/README.rst b/README.rst index 4d20b5b..3216f84 100644 --- a/README.rst +++ b/README.rst @@ -82,7 +82,7 @@ You'll have ``boxpy`` command created for you as well. .. code:: shell-session $ boxpy -V - boxpy 1.11.3 + boxpy 1.11.6 Other option is simply link it somewhere in the path: diff --git a/box.py b/box.py index 0c0e3f0..6458d54 100755 --- a/box.py +++ b/box.py @@ -18,7 +18,7 @@ import requests import yaml -__version__ = "1.11.3" +__version__ = "1.11.6" CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache')) CLOUD_IMAGE = "ci.iso" @@ -46,7 +46,6 @@ ssh: boxpy_data: cpus: 1 disk_size: 6144 - key: ~/.ssh/id_rsa memory: 1024 ''' COMPLETIONS = {'bash': '''\ @@ -542,10 +541,24 @@ class Config: self.ssh_key_path = os.path.join(os.path.expanduser("~/.ssh"), self.ssh_key_path) if not os.path.exists(self.ssh_key_path): - raise BoxConfError(f'Cannot find ssh public key: {self.key}') + if self.key: + raise BoxConfError(f"Cannot find ssh public key: '{self.key}'") + else: + raise BoxConfError(f"Cannot find any default ssh public key") def _set_defaults(self): conf = yaml.safe_load(USER_DATA) + conf['boxpy_data']['key'] = '' + # find out if there are SSH keys already. Set the first key found + for key in ['id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', + 'id_mldsa44_ed25519', 'id_rsa']: + if os.path.exists(os.path + .join(os.path + .expanduser('~/.ssh'), key)): + conf['boxpy_data']['key'] = key + break + else: + LOG.warning("There is no usable default key found in ~/.ssh") # update attributes with default values for key, val in conf['boxpy_data'].items():