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

Sentry #20

Merged
merged 7 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 26 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,63 @@ Pypi Seite: https://pypi.org/project/cryptic-game/
$ pip3 install cryptic-game
```

tanneberger marked this conversation as resolved.
Show resolved Hide resolved
## Features

- Endpoint Mapping
- automatic input validation
- Database Control
- Sentry and Logger -> Stacktraces and given Data

## Quick Start

```python
from cryptic import MicroService, get_config, Config
from uuid import uuid4
from sqlalchemy import Column, String
from typing import Union
from scheme import *
from typing import Union, Dict
from scheme import Text, UUID

config: Config = get_config("debug") # this sets config to debug mode
ms: MicroService = MicroService(name="echo")
wrapper = ms.get_wrapper()
db_wrapper = ms.get_wrapper()

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


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


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

if can_pay:
mypet: Test = Test.create(data["your_pets_name"])

if __name__ == '__main__':
ms.run()
return {"uuid": mypet.uuid}
else:
return {"error": "you_need_a_valid_wallet"}


class Test(wrapper.Base):
__tablename__: str = 'test'
class Test(db_wrapper.Base):
__tablename__: str = "test"

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

@staticmethod
def create(name: str) -> 'Test':
def create(name: str) -> "Test":
my_test: Test = Test(uuid=str(uuid4()), name=name)
wrapper.session.add(my_test)
wrapper.session.commit()

db_wrapper.session.add(my_test)
db_wrapper.session.commit()

return my_test


if __name__ == '__main__':
if __name__ == "__main__":
ms.run()
```

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

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

### Environment variables
use-to marked this conversation as resolved.
Show resolved Hide resolved

| key | default value |
|-------------------|---------------|
| SERVER_HOST | 127.0.0.1 |
| SERVER_PORT | 1239 |

## Wiki

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