added account creation command

This commit is contained in:
wcolmenares 2019-05-30 05:23:43 -04:00
commit 0c45d87616
7 changed files with 52 additions and 55 deletions

View file

@ -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.

View file

@ -17,7 +17,7 @@ ungleich --help
## 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

View file

@ -1,2 +0,0 @@
[metadata]
description-file = README.md

View file

@ -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"
]
},
)

View file

@ -4,6 +4,7 @@ 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
VERSION = "0.0.3" VERSION = "0.0.3"
@ -14,6 +15,7 @@ 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)
def _init_parser(self): def _init_parser(self):
self.parser = {} self.parser = {}

30
ungleich_account.py Normal file
View 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)

View file

@ -10,14 +10,24 @@ 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.""" """A dev endpoint for reverse-dns service."""
r = requests.post( r = requests.post(
'https://en53kfc0hydpg.x.pipedream.net', 'https://dev.william.ungleich.cloud',
json={'username': args.user, 'token': args.token, 'ipaddress': args.set_reverse, 'name': args.name}) json={
return r.text 'username': args.user,
'token': args.token,
'ipaddress': args.set_reverse,
'name': args.name,
'email': args.email,
'realm': args.realm
})
print(r.text)