Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit e192354

Browse files
author
Digging Tool
committed
added sentry and logging (#19)
1 parent c9a980e commit e192354

File tree

4 files changed

+146
-141
lines changed

4 files changed

+146
-141
lines changed

README.md

+26-32
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,63 @@ Pypi Seite: https://pypi.org/project/cryptic-game/
1010
$ pip3 install cryptic-game
1111
```
1212

13+
## Features
14+
15+
- Endpoint Mapping
16+
- automatic input validation
17+
- Database Control
18+
- Sentry and Logger -> Stacktraces and given Data
19+
1320
## Quick Start
1421

1522
```python
1623
from cryptic import MicroService, get_config, Config
1724
from uuid import uuid4
1825
from sqlalchemy import Column, String
19-
from typing import Union
20-
from scheme import *
26+
from typing import Union, Dict
27+
from scheme import Text, UUID
2128

2229
config: Config = get_config("debug") # this sets config to debug mode
2330
ms: MicroService = MicroService(name="echo")
24-
wrapper = ms.get_wrapper()
31+
db_wrapper = ms.get_wrapper()
2532

26-
user_device: dict = {
27-
'user_uuid': Text(nonempty=True),
28-
'device_uuid': Email(nonempty=True),
29-
'active': Boolean(required=True, default=True),
30-
'somedata': Integer(minimum=0, default=0),
31-
}
32-
# just giving an empty dictionary will be interpreted as no validation required.
33+
requirement: Dict[str, Text] = {"your_pets_name": Text(required=True), "wallet": UUID()}
3334

3435

3536
@ms.microservice_endpoint(path=["microservice"])
3637
def handle(data: dict, microservice: str):
37-
# excepts from other ms right data
38-
return {"name": data["yourname"]}
38+
return {"myname": "microservice"}
3939

4040

41-
@ms.user_endpoint(path=["user"], requires=user_device)
41+
@ms.user_endpoint(path=["user"], requires=requirement)
4242
def handle(data: dict, user: str):
43-
# Input is now already validated
44-
print(user, data["active"])
45-
return {"ok": True}
43+
can_pay: bool = ms.contact_microservice("currency", ["exists"], {"source_uuid": data["wallet"]})["exists"]
4644

45+
if can_pay:
46+
mypet: Test = Test.create(data["your_pets_name"])
4747

48-
if __name__ == '__main__':
49-
ms.run()
48+
return {"uuid": mypet.uuid}
49+
else:
50+
return {"error": "you_need_a_valid_wallet"}
5051

5152

52-
class Test(wrapper.Base):
53-
__tablename__: str = 'test'
53+
class Test(db_wrapper.Base):
54+
__tablename__: str = "test"
5455

5556
uuid: Union[Column, str] = Column(String(36), primary_key=True, unique=True)
5657
name: Union[Column, str] = Column(String(255), nullable=False)
5758

5859
@staticmethod
59-
def create(name: str) -> 'Test':
60+
def create(name: str) -> "Test":
6061
my_test: Test = Test(uuid=str(uuid4()), name=name)
61-
62-
wrapper.session.add(my_test)
63-
wrapper.session.commit()
62+
63+
db_wrapper.session.add(my_test)
64+
db_wrapper.session.commit()
6465

6566
return my_test
6667

6768

68-
if __name__ == '__main__':
69+
if __name__ == "__main__":
6970
ms.run()
7071
```
7172

@@ -77,13 +78,6 @@ Required are all modules in the `requirements.txt`.
7778

7879
Your microservice will be supported by the [game-server of cryptic](https://github.com/cryptic-game/server).
7980

80-
### Environment variables
81-
82-
| key | default value |
83-
|-------------------|---------------|
84-
| SERVER_HOST | 127.0.0.1 |
85-
| SERVER_PORT | 1239 |
86-
8781
## Wiki
8882

8983
Visit our [wiki](https://github.com/cryptic-game/python3-lib/wiki) for more information.

0 commit comments

Comments
 (0)