Compare commits
24 commits
Author | SHA1 | Date | |
---|---|---|---|
|
79abf872f2 | ||
|
49f1229aca | ||
|
d28748618d | ||
|
5766e65b20 | ||
|
29d1247f42 | ||
10e8af17e5 | |||
56c341805b | |||
f38e1bda14 | |||
bdb21e285a | |||
9772a479b6 | |||
|
307446e596 | ||
8c02790666 | |||
|
b8794b900b | ||
5d14de9045 | |||
4dd9b8cb29 | |||
78d2083e4d | |||
a185cf6a32 | |||
0c45d87616 | |||
d6e29ead71 | |||
d4d03d6add | |||
64f9e32e8c | |||
6f3d4a9890 | |||
|
7d5a33178c | ||
0e47c9f253 |
12 changed files with 263 additions and 59 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
__pycache__/
|
9
LICENSE
9
LICENSE
|
@ -1,9 +0,0 @@
|
||||||
LICENSE
|
|
||||||
|
|
||||||
Copyright
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
16
Pipfile
Normal file
16
Pipfile
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[[source]]
|
||||||
|
url = "https://pypi.python.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
name = "pypi"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
requests = "*"
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3.7"
|
||||||
|
|
||||||
|
[packages.apixu]
|
||||||
|
git = "https://github.com/apixu/apixu-python.git"
|
||||||
|
ref = "master"
|
61
Pipfile.lock
generated
Normal file
61
Pipfile.lock
generated
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"_meta": {
|
||||||
|
"hash": {
|
||||||
|
"sha256": "ca9c2522bf07f03d1588afe76e9f6fc73bc1efec20d4f155d82b709efaf14a56"
|
||||||
|
},
|
||||||
|
"pipfile-spec": 6,
|
||||||
|
"requires": {
|
||||||
|
"python_version": "3.7"
|
||||||
|
},
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"name": "pypi",
|
||||||
|
"url": "https://pypi.python.org/simple",
|
||||||
|
"verify_ssl": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"apixu": {
|
||||||
|
"git": "https://github.com/apixu/apixu-python.git",
|
||||||
|
"ref": "master"
|
||||||
|
},
|
||||||
|
"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": {}
|
||||||
|
}
|
35
README.md
35
README.md
|
@ -5,19 +5,30 @@ It is intended to be used by ungleich engineers and skilled customers.
|
||||||
|
|
||||||
## Requirements / Installation
|
## Requirements / Installation
|
||||||
|
|
||||||
* ensure you have python3
|
* ensure you have **python3** and **pipenv**
|
||||||
* git clone this repo
|
* git clone this repo
|
||||||
|
* cd into this repo
|
||||||
|
* run the following command
|
||||||
|
```
|
||||||
|
pipenv install
|
||||||
|
pipenv shell
|
||||||
|
```
|
||||||
|
|
||||||
## Usage general
|
## Usage general
|
||||||
|
|
||||||
```
|
```
|
||||||
ungleich --help
|
ungleich --help
|
||||||
```
|
```
|
||||||
|
## Usage: Weather
|
||||||
|
|
||||||
|
```
|
||||||
|
ungleich weather
|
||||||
|
```
|
||||||
|
|
||||||
## Usage: DNS
|
## Usage: DNS
|
||||||
|
|
||||||
```
|
```
|
||||||
ungleich dns --set-reverse <ip> --user <username> --token <token> --name mirror.example.com
|
ungleich dns --set-reverse <ip> --user <username> --token <token> --realm <realm> --email <email> --name mirror.example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage: RIPE
|
### Usage: RIPE
|
||||||
|
@ -30,3 +41,23 @@ ungleich ripe-add-route6 \
|
||||||
--description "First REST /32"
|
--description "First REST /32"
|
||||||
--password "very secure"
|
--password "very secure"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Usage: Account
|
||||||
|
|
||||||
|
Creating a new account object:
|
||||||
|
|
||||||
|
```
|
||||||
|
ungleich account --create-user <username> --name <firstname> --lastname <lastname> --email <email>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage: SSH Key
|
||||||
|
|
||||||
|
Requires you to have
|
||||||
|
https://code.ungleich.ch/ungleich-public/ungleich-ssh-keys/ checked
|
||||||
|
out in ~/vcs/ungleich-ssh-keys
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
ungleich sshkey --key raul.ascencio --host dev.raul.ungleich.cloud
|
||||||
|
```
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
[metadata]
|
|
||||||
description-file = README.md
|
|
34
setup.py
34
setup.py
|
@ -1,34 +0,0 @@
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
|
|
||||||
def readme():
|
|
||||||
with open('README.md') as f:
|
|
||||||
README = f.read()
|
|
||||||
return README
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name='ungleich-cli',
|
|
||||||
version='1.0.0',
|
|
||||||
description="A Python package for ungleich dns administration.",
|
|
||||||
long_description=readme(),
|
|
||||||
long_description_content_type="text/markdown",
|
|
||||||
author="William Colmenares",
|
|
||||||
author_email="colmenares.william@gmail.com",
|
|
||||||
license="MIT",
|
|
||||||
classifiers=[
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Programming Language :: Python :: 3.6",
|
|
||||||
],
|
|
||||||
|
|
||||||
py_modules=['ungleichcli'],
|
|
||||||
install_requires=[
|
|
||||||
'requests',
|
|
||||||
],
|
|
||||||
entry_points={
|
|
||||||
"console_scripts": [
|
|
||||||
"ungleich-cli=ungleichcli:cli"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
)
|
|
8
ungleich
8
ungleich
|
@ -4,8 +4,11 @@ import argparse
|
||||||
|
|
||||||
from ungleich_dns import ungleichDNS
|
from ungleich_dns import ungleichDNS
|
||||||
from ungleich_ripe import ungleichRIPE
|
from ungleich_ripe import ungleichRIPE
|
||||||
|
from ungleich_account import Account_Create
|
||||||
|
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):
|
||||||
|
@ -14,6 +17,9 @@ class ungleichCLI(object):
|
||||||
# FIXME: make it generic
|
# FIXME: make it generic
|
||||||
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)
|
||||||
|
SSHKey(self.parser, self.parser_parents)
|
||||||
|
ungleichWeather(self.parser, self.parser_parents)
|
||||||
|
|
||||||
def _init_parser(self):
|
def _init_parser(self):
|
||||||
self.parser = {}
|
self.parser = {}
|
||||||
|
|
30
ungleich_account.py
Normal file
30
ungleich_account.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import requests
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
class Account_Create(object):
|
||||||
|
def __init__(self, parser, parents):
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
|
self.parser['account'] = self.parser['sub'].add_parser(
|
||||||
|
'account',
|
||||||
|
help="Create a valid ungleich account",
|
||||||
|
parents=[parents])
|
||||||
|
|
||||||
|
self.parser['account'].add_argument('--create-user', help='REQUIRED: Username', required=True)
|
||||||
|
self.parser['account'].add_argument('--name', help='User\'s firstname', type=str, required=True)
|
||||||
|
self.parser['account'].add_argument('--lastname', help='User\'s lastname', type=str, required=True)
|
||||||
|
self.parser['account'].add_argument('--email', help='Email', required=True)
|
||||||
|
self.parser['account'].set_defaults(func=self._handle_account)
|
||||||
|
|
||||||
|
def _handle_account(self, args):
|
||||||
|
"""Reverse account endpoint."""
|
||||||
|
r = requests.post(
|
||||||
|
'https://account.ungleich.ch/create/',
|
||||||
|
data={
|
||||||
|
'username': args.create_user,
|
||||||
|
'firstname': args.name,
|
||||||
|
'lastname': args.lastname,
|
||||||
|
'email': args.email
|
||||||
|
})
|
||||||
|
print(r.text)
|
|
@ -1,5 +1,7 @@
|
||||||
import requests
|
|
||||||
|
import urllib.request
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
|
|
||||||
class ungleichDNS(object):
|
class ungleichDNS(object):
|
||||||
def __init__(self, parser, parents):
|
def __init__(self, parser, parents):
|
||||||
|
@ -10,14 +12,31 @@ class ungleichDNS(object):
|
||||||
help="Manage DNS entries @ ungleich",
|
help="Manage DNS entries @ ungleich",
|
||||||
parents=[parents])
|
parents=[parents])
|
||||||
|
|
||||||
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', metavar='', required=True)
|
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', required=True)
|
||||||
self.parser['dns'].add_argument('--user', help='Your ungleich username', metavar='', required=True)
|
self.parser['dns'].add_argument('--user', help='Your ungleich username', required=True)
|
||||||
self.parser['dns'].add_argument('--token', help='Your ungleich 6 digit OTP generated token', metavar='', type=int, required=True)
|
self.parser['dns'].add_argument('--token', help='Your ungleich 6 digit OTP generated token', type=int, required=True)
|
||||||
self.parser['dns'].add_argument('--name', help='Hostname', metavar='', required=True)
|
self.parser['dns'].add_argument('--name', help='Hostname', required=True)
|
||||||
|
self.parser['dns'].add_argument('--email', help='registered email', required=True)
|
||||||
|
self.parser['dns'].add_argument('--realm', help='Otp realm', required=True)
|
||||||
|
self.parser['dns'].set_defaults(func=self._handle_dns)
|
||||||
|
|
||||||
def _handle_dns(self):
|
def _handle_dns(self, args):
|
||||||
"""A dummy endpoint, to check what endpoint will be reverse-dns service."""
|
"""Reverse dns endpoint."""
|
||||||
r = requests.post(
|
url = 'https://dns.service.ungleich.ch'
|
||||||
'https://en53kfc0hydpg.x.pipedream.net',
|
req = urllib.request.Request(
|
||||||
json={'username': args.user, 'token': args.token, 'ipaddress': args.set_reverse, 'name': args.name})
|
url=url,
|
||||||
return r.text
|
method='POST',
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
data=json.dumps({
|
||||||
|
'username': args.user,
|
||||||
|
'token': args.token,
|
||||||
|
'ipaddress': args.set_reverse,
|
||||||
|
'name': args.name,
|
||||||
|
'email': args.email,
|
||||||
|
'realm': args.realm
|
||||||
|
}).encode('utf-8')
|
||||||
|
)
|
||||||
|
response = urllib.request.urlopen(req).read()
|
||||||
|
print(json.loads(response))
|
||||||
|
|
51
ungleich_ssh_key.py
Normal file
51
ungleich_ssh_key.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/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/current"),
|
||||||
|
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.key_dir, "{}.pub".format(args.key))
|
||||||
|
|
||||||
|
if not os.path.exists(keyfile):
|
||||||
|
print("Key for {} does not exist in {}. Aborting".format(args.key, args.key_dir))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
cmd = 'cat {} | ssh {}@{} "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"'.format(keyfile,
|
||||||
|
args.user,
|
||||||
|
args.host)
|
||||||
|
|
||||||
|
subprocess.run(cmd, shell=True)
|
34
ungleich_weather.py
Normal file
34
ungleich_weather.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import argparse
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from apixu.client import ApixuClient
|
||||||
|
|
||||||
|
|
||||||
|
def get_loc():
|
||||||
|
response = requests.get('http://ip-api.com/json/')
|
||||||
|
data = json.loads(response.content)
|
||||||
|
|
||||||
|
return data['city'], data['countryCode']
|
||||||
|
|
||||||
|
|
||||||
|
class ungleichWeather(object):
|
||||||
|
def __init__(self, parser, parents):
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
|
self.parser['weather'] = self.parser['sub'].add_parser(
|
||||||
|
'weather',
|
||||||
|
help="Weather Enquiries",
|
||||||
|
parents=[parents])
|
||||||
|
self.parser['weather'].set_defaults(func=ungleichWeather.forecast_weather)
|
||||||
|
|
||||||
|
def forecast_weather(args):
|
||||||
|
_city, _country_code = get_loc()
|
||||||
|
print("Weather for {}\n".format(_city))
|
||||||
|
|
||||||
|
client = ApixuClient("cc33a1e3237a4b78b3174104190206")
|
||||||
|
|
||||||
|
forecast = client.forecast(q=f'{ _city},{_country_code}', days=7)
|
||||||
|
print(f"{'Date':^12}|{'Min Temp':^10}|{'Max Temp':^10}|{'Condition':^15}")
|
||||||
|
print(f"{'*'*47:^47}")
|
||||||
|
for day in forecast['forecast']['forecastday']:
|
||||||
|
print(f"{day['date']:^12}|{day['day']['mintemp_c']:^10}|{day['day']['maxtemp_c']:^10}|{day['day']['condition']['text']:^15}")
|
Loading…
Reference in a new issue