2019-08-13 06:30:19 +00:00
|
|
|
import urllib.request
|
|
|
|
import json
|
|
|
|
|
|
|
|
UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch"
|
|
|
|
|
|
|
|
|
|
|
|
class ungleichPay(object):
|
|
|
|
def __init__(self, parser, parents):
|
|
|
|
self.parser = parser
|
|
|
|
|
|
|
|
self.parser['customers-list'] = self.parser['sub'].add_parser(
|
|
|
|
'customers-list',
|
|
|
|
help="List customers who have an active VM at ungleich",
|
|
|
|
parents=[parents])
|
2019-08-13 07:56:55 +00:00
|
|
|
self.parser['customers-list'].add_argument('--username', required=True)
|
|
|
|
self.parser['customers-list'].add_argument('--realm', required=True)
|
|
|
|
self.parser['customers-list'].add_argument(
|
2019-08-13 06:30:19 +00:00
|
|
|
'--token', required=True,
|
|
|
|
help="A valid token obtained from ungleich"
|
|
|
|
)
|
2019-08-13 07:56:55 +00:00
|
|
|
self.parser['customers-list'].add_argument(
|
2019-08-13 07:33:59 +00:00
|
|
|
'--ungleich-pay-server', required=False,
|
|
|
|
help="A valid ungleich pay server url"
|
|
|
|
)
|
2019-08-13 06:30:19 +00:00
|
|
|
self.parser['customers-list'].set_defaults(func=self.customers_list)
|
|
|
|
|
|
|
|
def customers_list(self, args):
|
2019-08-13 07:56:55 +00:00
|
|
|
customers_list_endpoint = "/customers-list/"
|
2019-08-13 07:33:59 +00:00
|
|
|
if args.ungleich_pay_server:
|
|
|
|
request_url = args.ungleich_pay_server + customers_list_endpoint
|
|
|
|
else:
|
|
|
|
request_url = UNGLEICH_PAY_SERVER_URL + customers_list_endpoint
|
2019-08-13 06:30:19 +00:00
|
|
|
req = urllib.request.Request(url=request_url,
|
|
|
|
method='GET',
|
|
|
|
headers={
|
|
|
|
"username": args.username,
|
|
|
|
"realm": args.realm,
|
|
|
|
"token": args.token,
|
|
|
|
"Accept": "application/json"
|
|
|
|
})
|
|
|
|
response = urllib.request.urlopen(req)
|
|
|
|
response_json = json.loads(response.read().decode('utf-8'))
|
|
|
|
print(response_json.data)
|