Focus on creating a VPN as a first test case
This commit is contained in:
parent
13292db39e
commit
315aaded41
3 changed files with 106 additions and 7 deletions
|
@ -6,7 +6,10 @@ The pay module for the uncloud
|
|||
- uses [Stripe](https://stripe.com/docs/api) as the payment gateway.
|
||||
- uses [ldap3](https://github.com/cannatag/ldap3) for ldap authentication.
|
||||
|
||||
## Getting started
|
||||
|
||||
## Getting started as a user
|
||||
|
||||
|
||||
|
||||
**TODO**
|
||||
|
||||
|
@ -40,4 +43,4 @@ http --json GET http://[::]:5000/order/list email=your_email_here password=your_
|
|||
|
||||
```shell script
|
||||
http --json http://[::]:5000/user/register_payment card_number=4111111111111111 cvc=123 expiry_year=2020 expiry_month=8 card_holder_name="The test user" email=your_email_here password=your_password_here
|
||||
```
|
||||
```
|
||||
|
|
|
@ -82,8 +82,84 @@ class Order(Resource):
|
|||
|
||||
@staticmethod
|
||||
def post():
|
||||
print("{} {}".format(data, config))
|
||||
data = request.get_json(silent=True) or {}
|
||||
print("{} {}".format(data, config))
|
||||
|
||||
|
||||
class Product(Resource):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
self.products = []
|
||||
self.products.append(
|
||||
{ "name": "membership-free",
|
||||
"description": """
|
||||
This membership gives you access to the API and includes a VPN
|
||||
with 1 IPv6 address.
|
||||
See https://redmine.ungleich.ch/issues/7747?
|
||||
""",
|
||||
"uuid": "a3883466-0012-4d01-80ff-cbf7469957af",
|
||||
"recurring": True,
|
||||
"recurring_time_frame": "per_year",
|
||||
"features": [
|
||||
{ "name": "membership",
|
||||
"price_one_time": 0,
|
||||
"price_recurring": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
self.products.append(
|
||||
{ "name": "membership-standard",
|
||||
"description": """
|
||||
This membership gives you access to the API and includes an IPv6-VPN with
|
||||
one IPv6 address ("Road warrior")
|
||||
See https://redmine.ungleich.ch/issues/7747?
|
||||
""",
|
||||
"uuid": "1d85296b-0863-4dd6-a543-a6d5a4fbe4a6",
|
||||
"recurring": True,
|
||||
"recurring_time_frame": "per_month",
|
||||
"features": [
|
||||
{ "name": "membership",
|
||||
"price_one_time": 0,
|
||||
"price_recurring": 5
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
)
|
||||
self.products.append(
|
||||
{ "name": "membership-premium",
|
||||
"description": """
|
||||
This membership gives you access to the API and includes an
|
||||
IPv6-VPN with a /48 IPv6 network.
|
||||
See https://redmine.ungleich.ch/issues/7747?
|
||||
""",
|
||||
"uuid": "bfd63fd2-d227-436f-a8b8-600de74dd6ce",
|
||||
"recurring": True,
|
||||
"recurring_time_frame": "per_month",
|
||||
"features": [
|
||||
{ "name": "membership",
|
||||
"price_one_time": 0,
|
||||
"price_recurring": 5
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def post():
|
||||
data = request.get_json(silent=True) or {}
|
||||
print("{} {}".format(data, config))
|
||||
|
||||
def get(self):
|
||||
data = request.get_json(silent=True) or {}
|
||||
print("{} {}".format(data, config))
|
||||
|
||||
return self.products
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -97,7 +173,8 @@ if __name__ == '__main__':
|
|||
config['ldap_url']="ldaps://ldap1.ungleich.ch"
|
||||
|
||||
api = Api(app)
|
||||
api.add_resource(Order, '/order', resource_class_args=( config, ))
|
||||
api.add_resource(Order, '/orders', resource_class_args=( config, ))
|
||||
api.add_resource(Product, '/products', resource_class_args=( config, ))
|
||||
api.add_resource(Membership, '/membership', resource_class_args=( config, ))
|
||||
|
||||
app.run(host='::', port=5000, debug=True)
|
25
ldaptest.py
25
ldaptest.py
|
@ -1,8 +1,27 @@
|
|||
import ldap3
|
||||
from ldap3 import Server, Connection, ObjectDef, Reader, ALL
|
||||
import os
|
||||
import sys
|
||||
|
||||
server = Server("ldaps://ldap1.ungleich.ch")
|
||||
conn = Connection(server, 'cn=Nico Schottelius,ou=users,dc=ungleich,dc=ch', os.environ['PW'], auto_bind=True)
|
||||
def is_valid_ldap_user(username, password):
|
||||
server = Server("ldaps://ldap1.ungleich.ch")
|
||||
is_valid = False
|
||||
|
||||
print(conn)
|
||||
try:
|
||||
conn = Connection(server, 'cn={},ou=users,dc=ungleich,dc=ch'.format(username), password, auto_bind=True)
|
||||
is_valid = True
|
||||
except Exception as e:
|
||||
print("user: {}".format(e))
|
||||
|
||||
try:
|
||||
conn = Connection(server, 'uid={},ou=customer,dc=ungleich,dc=ch'.format(username), password, auto_bind=True)
|
||||
is_valid = True
|
||||
except Exception as e:
|
||||
print("customer: {}".format(e))
|
||||
|
||||
|
||||
return is_valid
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(is_valid_ldap_user(sys.argv[1], sys.argv[2]))
|
||||
|
|
Loading…
Reference in a new issue