Add pipfile, add ssh key handling
This commit is contained in:
parent
307446e596
commit
29d1247f42
4 changed files with 121 additions and 1 deletions
12
Pipfile
Normal file
12
Pipfile
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[[source]]
|
||||||
|
url = "https://pypi.python.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
name = "pypi"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
requests = "*"
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3.7"
|
57
Pipfile.lock
generated
Normal file
57
Pipfile.lock
generated
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"_meta": {
|
||||||
|
"hash": {
|
||||||
|
"sha256": "0fd749b30be70c938b01b5bf9e870b04e9c3648dea04f51a2feb9da5ac5a8f8c"
|
||||||
|
},
|
||||||
|
"pipfile-spec": 6,
|
||||||
|
"requires": {
|
||||||
|
"python_version": "3.7"
|
||||||
|
},
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"name": "pypi",
|
||||||
|
"url": "https://pypi.python.org/simple",
|
||||||
|
"verify_ssl": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"certifi": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
|
||||||
|
"sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae"
|
||||||
|
],
|
||||||
|
"version": "==2019.3.9"
|
||||||
|
},
|
||||||
|
"chardet": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
|
||||||
|
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
|
||||||
|
],
|
||||||
|
"version": "==3.0.4"
|
||||||
|
},
|
||||||
|
"idna": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407",
|
||||||
|
"sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"
|
||||||
|
],
|
||||||
|
"version": "==2.8"
|
||||||
|
},
|
||||||
|
"requests": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4",
|
||||||
|
"sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==2.22.0"
|
||||||
|
},
|
||||||
|
"urllib3": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:b246607a25ac80bedac05c6f282e3cdaf3afb65420fd024ac94435cabe6e18d1",
|
||||||
|
"sha256:dbe59173209418ae49d485b87d1681aefa36252ee85884c31346debd19463232"
|
||||||
|
],
|
||||||
|
"version": "==1.25.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"develop": {}
|
||||||
|
}
|
4
ungleich
4
ungleich
|
@ -6,8 +6,9 @@ from ungleich_dns import ungleichDNS
|
||||||
from ungleich_ripe import ungleichRIPE
|
from ungleich_ripe import ungleichRIPE
|
||||||
from ungleich_account import Account_Create
|
from ungleich_account import Account_Create
|
||||||
from ungleich_weather import ungleichWeather
|
from ungleich_weather import ungleichWeather
|
||||||
|
from ungleich_ssh_key import SSHKey
|
||||||
|
|
||||||
VERSION = "0.0.3"
|
VERSION = "0.0.4"
|
||||||
|
|
||||||
class ungleichCLI(object):
|
class ungleichCLI(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -17,6 +18,7 @@ class ungleichCLI(object):
|
||||||
dns = ungleichDNS(self.parser, self.parser_parents)
|
dns = ungleichDNS(self.parser, self.parser_parents)
|
||||||
ripe = ungleichRIPE(self.parser, self.parser_parents)
|
ripe = ungleichRIPE(self.parser, self.parser_parents)
|
||||||
ripe = Account_Create(self.parser, self.parser_parents)
|
ripe = Account_Create(self.parser, self.parser_parents)
|
||||||
|
SSHKey(self.parser, self.parser_parents)
|
||||||
ungleichWeather(self.parser, self.parser_parents)
|
ungleichWeather(self.parser, self.parser_parents)
|
||||||
|
|
||||||
def _init_parser(self):
|
def _init_parser(self):
|
||||||
|
|
49
ungleich_ssh_key.py
Normal file
49
ungleich_ssh_key.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
class SSHKey(object):
|
||||||
|
def __init__(self, parser, parents):
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
|
self.parser['sshkey'] = self.parser['sub'].add_parser(
|
||||||
|
'sshkey',
|
||||||
|
help="Manage SSH keys",
|
||||||
|
parents=[parents])
|
||||||
|
|
||||||
|
self.parser['sshkey'].add_argument('--user',
|
||||||
|
help='Username on the host',
|
||||||
|
required=False,
|
||||||
|
default="root")
|
||||||
|
self.parser['sshkey'].add_argument('--key',
|
||||||
|
help='Name of the key',
|
||||||
|
required=True)
|
||||||
|
self.parser['sshkey'].add_argument('--key-dir',
|
||||||
|
help='Directory holding keys',
|
||||||
|
default=os.path.join(os.environ['HOME'], "vcs/ungleich-ssh-keys/"),
|
||||||
|
required=false)
|
||||||
|
self.parser['sshkey'].add_argument('--host',
|
||||||
|
help='Host to use',
|
||||||
|
required=True)
|
||||||
|
self.parser['sshkey'].add_argument('--delete',
|
||||||
|
help='Delete key instead of adding',
|
||||||
|
action="store_true")
|
||||||
|
self.parser['sshkey'].set_defaults(func=self._manage_key)
|
||||||
|
|
||||||
|
|
||||||
|
def _manage_key(self, args):
|
||||||
|
if args.delete:
|
||||||
|
print("Not yet supported to delete, sorry :-)")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
keyfile = os.path.join(args.keydir, "{}.pub".format(args.key))
|
||||||
|
|
||||||
|
if not os.path.exists(keyfile):
|
||||||
|
print("Key for {} does not exist in {}. Aborting".format(args.key, args.keydir))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
cmd = 'cat {} | ssh {} "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"'.format(keyfile, args.host)
|
||||||
|
|
||||||
|
subprocess.run(cmd, shell=True)
|
Loading…
Reference in a new issue