Compare commits
No commits in common. "master" and "0.0.3" have entirely different histories.
12 changed files with 59 additions and 263 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
__pycache__/
|
|
9
LICENSE
Normal file
9
LICENSE
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
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
16
Pipfile
|
@ -1,16 +0,0 @@
|
||||||
[[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
61
Pipfile.lock
generated
|
@ -1,61 +0,0 @@
|
||||||
{
|
|
||||||
"_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,30 +5,19 @@ It is intended to be used by ungleich engineers and skilled customers.
|
||||||
|
|
||||||
## Requirements / Installation
|
## Requirements / Installation
|
||||||
|
|
||||||
* ensure you have **python3** and **pipenv**
|
* ensure you have python3
|
||||||
* 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> --realm <realm> --email <email> --name mirror.example.com
|
ungleich dns --set-reverse <ip> --user <username> --token <token> --name mirror.example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage: RIPE
|
### Usage: RIPE
|
||||||
|
@ -41,23 +30,3 @@ 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
|
|
||||||
```
|
|
||||||
|
|
2
setup.cfg
Normal file
2
setup.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[metadata]
|
||||||
|
description-file = README.md
|
34
setup.py
Normal file
34
setup.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
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,11 +4,8 @@ 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.4"
|
VERSION = "0.0.3"
|
||||||
|
|
||||||
class ungleichCLI(object):
|
class ungleichCLI(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -17,9 +14,6 @@ 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 = {}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
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,7 +1,5 @@
|
||||||
|
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):
|
||||||
|
@ -12,31 +10,14 @@ 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', required=True)
|
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', metavar='', required=True)
|
||||||
self.parser['dns'].add_argument('--user', help='Your ungleich username', required=True)
|
self.parser['dns'].add_argument('--user', help='Your ungleich username', metavar='', 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('--token', help='Your ungleich 6 digit OTP generated token', metavar='', type=int, required=True)
|
||||||
self.parser['dns'].add_argument('--name', help='Hostname', required=True)
|
self.parser['dns'].add_argument('--name', help='Hostname', metavar='', 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, args):
|
def _handle_dns(self):
|
||||||
"""Reverse dns endpoint."""
|
"""A dummy endpoint, to check what endpoint will be reverse-dns service."""
|
||||||
url = 'https://dns.service.ungleich.ch'
|
r = requests.post(
|
||||||
req = urllib.request.Request(
|
'https://en53kfc0hydpg.x.pipedream.net',
|
||||||
url=url,
|
json={'username': args.user, 'token': args.token, 'ipaddress': args.set_reverse, 'name': args.name})
|
||||||
method='POST',
|
return r.text
|
||||||
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))
|
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#!/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)
|
|
|
@ -1,34 +0,0 @@
|
||||||
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