fix
This commit is contained in:
4
config.py
Normal file
4
config.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
class Config:
|
||||||
|
db_connection_string = "postgresql+psycopg://postgres:Root12345678@10.10.8.83:32101/db"
|
||||||
|
enserver_url = "http://10.10.8.70:7000/xmlrpc"
|
||||||
28
main.py
28
main.py
@@ -10,14 +10,15 @@ from strawberry.fastapi import GraphQLRouter
|
|||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
from strawberry.scalars import JSON
|
from strawberry.scalars import JSON
|
||||||
from xmlrpc.client import ServerProxy
|
from xmlrpc.client import ServerProxy
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
return create_engine("postgresql+psycopg://postgres:Root12345678@10.10.8.83:32101/db", echo=True)
|
return create_engine(Config.db_connection_string, echo=True)
|
||||||
|
|
||||||
|
|
||||||
def exec_function(function: str, **kwargs):
|
def exec_function(function: str, **kwargs):
|
||||||
proxy = ServerProxy('http://10.10.8.70:7000/xmlrpc')
|
proxy = ServerProxy(Config.enserver_url)
|
||||||
result = proxy.__getattr__(function)(kwargs)
|
result = proxy.__getattr__(function)(kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -244,13 +245,13 @@ class Mutation:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@strawberry.mutation
|
@strawberry.mutation
|
||||||
def create_profile(self, user_id: int, scheme: str, json: str) -> int:
|
def create_profile(self, user_id: int, schema: str, branch: str, json: str) -> int:
|
||||||
sync_engine = connect()
|
sync_engine = connect()
|
||||||
with (Session(sync_engine) as session):
|
with (Session(sync_engine) as session):
|
||||||
user = session.query(User).get(user_id)
|
user = session.query(User).get(user_id)
|
||||||
if not user:
|
if not user:
|
||||||
return 0
|
return 0
|
||||||
profile = Profile(user_id=user_id, scheme=scheme, json=json)
|
profile = Profile(user_id=user_id, scheme=schema, branch=branch, json=json)
|
||||||
session.add_all([profile])
|
session.add_all([profile])
|
||||||
session.commit()
|
session.commit()
|
||||||
return profile.id
|
return profile.id
|
||||||
@@ -314,6 +315,21 @@ class Mutation:
|
|||||||
session.commit()
|
session.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@strawberry.mutation
|
||||||
|
def send_commit(self, bndname: str, schema: str, commit_id: str) -> bool:
|
||||||
|
sync_engine = connect()
|
||||||
|
with (Session(sync_engine) as session):
|
||||||
|
user = session.query(User).filter(User.bndname == bndname).one_or_none()
|
||||||
|
if user:
|
||||||
|
queue = Queue(
|
||||||
|
user_id=user.id,
|
||||||
|
commit_id=commit_id,
|
||||||
|
schema=schema,
|
||||||
|
)
|
||||||
|
session.add(queue)
|
||||||
|
session.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
sync_engine = connect()
|
sync_engine = connect()
|
||||||
@@ -342,7 +358,7 @@ def init():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# init()
|
# init()
|
||||||
uvicorn.run("main:app", port=9000, log_level="info")
|
uvicorn.run("main:app", port=9000, log_level="info", host='0.0.0.0')
|
||||||
|
|
||||||
|
|
||||||
schema = strawberry.Schema(query=Query, mutation=Mutation)
|
schema = strawberry.Schema(query=Query, mutation=Mutation)
|
||||||
@@ -351,7 +367,7 @@ graphql_app = GraphQLRouter(schema, graphiql=True)
|
|||||||
|
|
||||||
app = FastAPI(root_path="/graphql")
|
app = FastAPI(root_path="/graphql")
|
||||||
app.add_middleware(CORSMiddleware,
|
app.add_middleware(CORSMiddleware,
|
||||||
allow_origins=['http://127.0.0.1:3000', 'http://localhost:3000'],
|
allow_origins=['http://127.0.0.1:3000', 'http://localhost:3000', 'http://10.10.8.24:3000'],
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=['*'],
|
allow_methods=['*'],
|
||||||
allow_headers=['*']
|
allow_headers=['*']
|
||||||
|
|||||||
Reference in New Issue
Block a user