Beispiel #1
0
 def __init__(self):
     self._consul = ConsulHandler()
     self._redis_info = self._consul.get_redis_info()
     self._host: str = self._redis_info["host"]
     self._port: int = self._redis_info["port"]
     self._password: Optional[str] = os.getenv("REDIS_PASSWORD")
     self._db: int = self._redis_info["db"]
Beispiel #2
0
    def __init__(self):
        self._consul = ConsulHandler()
        self._db_info = self._consul.get_db_info()
        self._sql: str = self._db_info["dialect"]
        self._db: str = self._db_info["db"]
        self._host: str = self._db_info["host"]
        self._user: str = self._db_info["user"]
        self._password: str = os.getenv("DB_PASSWORD")

        self._autocommit: bool = False
        self._autoflush: bool = False
Beispiel #3
0
class DatabaseConfig:
    def __init__(self):
        self._consul = ConsulHandler()
        self._db_info = self._consul.get_db_info()
        self._sql: str = self._db_info["dialect"]
        self._db: str = self._db_info["db"]
        self._host: str = self._db_info["host"]
        self._user: str = self._db_info["user"]
        self._password: str = os.getenv("DB_PASSWORD")

        self._autocommit: bool = False
        self._autoflush: bool = False

    @property
    def address(self) -> str:
        return str(
            f"{self._sql}+pymysql://{self._user}:{self._password}@{self._host}/{self._db}?charset=utf8"
        )

    @property
    def autocommit(self) -> bool:
        return self._autocommit

    @property
    def autoflush(self) -> bool:
        return self._autoflush
Beispiel #4
0
    def get_parents_with_student_uuid(self, uuid, student_uuid, x_request_id):
        address = ConsulHandler().auth_address
        channel = grpc.insecure_channel(address)
        student_stub = auth_student_pb2_grpc.AuthStudentStub(channel)

        metadata = (("x-request-id", x_request_id),
                    ("span-context",
                     str(open_tracing.tracer.active_span).split()[0]))

        response = student_stub.GetParentWithStudentUUID(
            auth_student_pb2.GetParentWithStudentUUIDRequest(
                UUID=uuid, StudentUUID=student_uuid),
            metadata=metadata)

        if response.Status != 200: return None

        return response
Beispiel #5
0
    def get_teacher_inform(self, uuid, teacher_uuid, x_request_id):
        address = ConsulHandler().auth_address
        channel = grpc.insecure_channel(address)
        teacher_stub = auth_teacher_pb2_grpc.AuthTeacherStub(channel)

        metadata = (("x-request-id", x_request_id),
                    ("span-context",
                     str(open_tracing.tracer.active_span).split()[0]))

        response = teacher_stub.GetTeacherInformWithUUID(
            auth_teacher_pb2.GetTeacherInformWithUUIDRequest(
                UUID=uuid, TeacherUUID=teacher_uuid),
            metadata=metadata)

        if response.Status != 200: return None

        return response
Beispiel #6
0
    def get_uuid_with_inform(self, uuid, x_request_id, grade=None, group=None):
        address = ConsulHandler().auth_address
        channel = grpc.insecure_channel(address)
        student_stub = auth_student_pb2_grpc.AuthStudentStub(channel)

        metadata = (("x-request-id", x_request_id),
                    ("span-context",
                     str(open_tracing.tracer.active_span).split()[0]))

        response = student_stub.GetStudentUUIDsWithInform(
            auth_student_pb2.GetStudentUUIDsWithInformRequest(UUID=uuid,
                                                              Grade=grade,
                                                              Group=group),
            metadata=metadata)

        if response.Status != 200: return None

        return response.StudentUUIDs
Beispiel #7
0
    def get_club_informs_with_floor(self, uuid, floor, x_request_id):
        address = ConsulHandler().club_address
        channel = grpc.insecure_channel(address)
        student_stub = club_student_pb2_grpc.ClubStudentStub(channel)

        metadata = (("x-request-id", x_request_id),
                    ("span-context",
                     str(open_tracing.tracer.active_span).split()[0]))

        club_response = student_stub.GetClubUUIDsWithFloor(
            club_student_pb2.GetClubUUIDsWithFloorRequest(UUID=uuid,
                                                          floor=str(floor)),
            metadata=metadata)

        response = student_stub.GetClubInformsWithUUIDs(
            club_student_pb2.GetClubInformsWithUUIDsRequest(
                UUID=uuid, ClubUUIDs=club_response.ClubUUIDs),
            metadata=metadata)

        if response.Status != 200: return None

        return response
Beispiel #8
0
class CacheConfig:
    def __init__(self):
        self._consul = ConsulHandler()
        self._redis_info = self._consul.get_redis_info()
        self._host: str = self._redis_info["host"]
        self._port: int = self._redis_info["port"]
        self._password: Optional[str] = os.getenv("REDIS_PASSWORD")
        self._db: int = self._redis_info["db"]

    @property
    def host(self) -> str:
        return self._host

    @property
    def port(self) -> int:
        return self._port

    @property
    def password(self) -> Optional[str]:
        return self._password

    @property
    def db(self) -> int:
        return self._db
Beispiel #9
0
from application import gRPCApplication

from infrastructure.config.grpc_config import gRPCAppConfig
from infrastructure.consul.consul_handler import ConsulHandler

if __name__ == "__main__":
    app = gRPCApplication(gRPCAppConfig(), ConsulHandler())
    app.serve()