This commit is contained in:
parent
0ee6390c81
commit
24d5200bdf
106
src/resources.py
106
src/resources.py
@ -48,16 +48,17 @@ class SignupApi(Resource):
|
|||||||
abort(417, INVALID_JSON_SCHEMA_MSG)
|
abort(417, INVALID_JSON_SCHEMA_MSG)
|
||||||
|
|
||||||
user = VideonUser(name=userobj['name'], password=userobj['password'])
|
user = VideonUser(name=userobj['name'], password=userobj['password'])
|
||||||
try:
|
|
||||||
user.hash_password()
|
user.hash_password()
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(409, "user already exists")
|
|
||||||
|
|
||||||
expires = datetime.timedelta(days=7)
|
expires = datetime.timedelta(days=7)
|
||||||
access_token = create_access_token(identity=str(user.name), expires_delta=expires)
|
access_token = create_access_token(identity=str(user.name), expires_delta=expires)
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning(e)
|
||||||
|
abort(409, "user already exists")
|
||||||
return {'token': access_token}, 200
|
return {'token': access_token}, 200
|
||||||
|
|
||||||
|
|
||||||
@ -86,12 +87,7 @@ class LoginApi(Resource):
|
|||||||
current_app.logger.info(e)
|
current_app.logger.info(e)
|
||||||
abort(401, "unauthorized")
|
abort(401, "unauthorized")
|
||||||
|
|
||||||
try:
|
|
||||||
user.last_logon = datetime.datetime.now()
|
user.last_logon = datetime.datetime.now()
|
||||||
db.session.add(user)
|
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.exception(e)
|
|
||||||
abort(503, DB_ERROR_MSG)
|
|
||||||
|
|
||||||
expires = datetime.timedelta(days=7)
|
expires = datetime.timedelta(days=7)
|
||||||
access_token = create_access_token(identity=str(user.name), expires_delta=expires)
|
access_token = create_access_token(identity=str(user.name), expires_delta=expires)
|
||||||
@ -106,6 +102,7 @@ class MeApi(Resource):
|
|||||||
|
|
||||||
usermetadataschema = UserMetadataSchema(many=False)
|
usermetadataschema = UserMetadataSchema(many=False)
|
||||||
|
|
||||||
|
@jwt_required
|
||||||
def get(self):
|
def get(self):
|
||||||
username = get_jwt_identity()
|
username = get_jwt_identity()
|
||||||
# username = "jozska"
|
# username = "jozska"
|
||||||
@ -148,13 +145,13 @@ class UserParameterApi(Resource):
|
|||||||
"""
|
"""
|
||||||
user = VideonUser.query.filter_by(name=username).first_or_404()
|
user = VideonUser.query.filter_by(name=username).first_or_404()
|
||||||
|
|
||||||
try:
|
|
||||||
db.session.delete(user)
|
db.session.delete(user)
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.exception(e)
|
|
||||||
abort(503, DB_ERROR_MSG)
|
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning(e)
|
||||||
|
abort(410, DB_ERROR_MSG)
|
||||||
return self.usermetadataschema.dump(user), 200
|
return self.usermetadataschema.dump(user), 200
|
||||||
|
|
||||||
@jwt_required
|
@jwt_required
|
||||||
@ -176,14 +173,14 @@ class UserParameterApi(Resource):
|
|||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(417, INVALID_JSON_SCHEMA_MSG)
|
abort(417, INVALID_JSON_SCHEMA_MSG)
|
||||||
|
|
||||||
try:
|
|
||||||
user.password = userobj['password']
|
user.password = userobj['password']
|
||||||
user.hash_password()
|
user.hash_password()
|
||||||
|
|
||||||
|
try:
|
||||||
|
db.session.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
abort(503, DB_ERROR_MSG)
|
abort(412, DB_ERROR_MSG)
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
return self.usermetadataschema.dump(user), 200
|
return self.usermetadataschema.dump(user), 200
|
||||||
|
|
||||||
|
|
||||||
@ -219,6 +216,7 @@ class CreateIngestResource(Resource):
|
|||||||
ingest.stream_key = str(uuid4())
|
ingest.stream_key = str(uuid4())
|
||||||
try:
|
try:
|
||||||
db.session.add(ingest)
|
db.session.add(ingest)
|
||||||
|
db.session.commit()
|
||||||
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).create_resource()
|
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).create_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
@ -229,13 +227,13 @@ class CreateIngestResource(Resource):
|
|||||||
neighbourobj = StreamResource.query.filter_by(id=neighbour).first_or_404()
|
neighbourobj = StreamResource.query.filter_by(id=neighbour).first_or_404()
|
||||||
if neighbourobj.resource_type == StreamResourceTypeEnum.INGEST:
|
if neighbourobj.resource_type == StreamResourceTypeEnum.INGEST:
|
||||||
abort(400, "ingest cannot be a downstream component")
|
abort(400, "ingest cannot be a downstream component")
|
||||||
try:
|
|
||||||
neighbourobj.parent_id = ingest.id
|
neighbourobj.parent_id = ingest.id
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not set neighbourhood")
|
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(ingest), 200
|
return self.streamresourceschema.dump(ingest), 200
|
||||||
|
|
||||||
|
|
||||||
@ -273,20 +271,21 @@ class CreateRestreamResource(Resource):
|
|||||||
restream.parent_id = restreamobj['inputNeighbour']
|
restream.parent_id = restreamobj['inputNeighbour']
|
||||||
try:
|
try:
|
||||||
db.session.add(restream)
|
db.session.add(restream)
|
||||||
|
db.session.commit()
|
||||||
Kubectl(name=restream.id, resourcetype="restream",
|
Kubectl(name=restream.id, resourcetype="restream",
|
||||||
stream_key=restream.stream_key, push_urls=restreamobj['outputURLs']).create_resource()
|
stream_key=restream.stream_key, push_urls=restreamobj['outputURLs']).create_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "object already exists")
|
abort(409, "object already exists")
|
||||||
for url in restreamobj['outputURLs']:
|
for url in restreamobj['outputURLs']:
|
||||||
try:
|
|
||||||
outputurl = OutputUrls(output_url=url, streamresource_id=restream.id)
|
outputurl = OutputUrls(output_url=url, streamresource_id=restream.id)
|
||||||
db.session.add(outputurl)
|
db.session.add(outputurl)
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not add all outputurls")
|
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(restream), 200
|
return self.streamresourceschema.dump(restream), 200
|
||||||
|
|
||||||
|
|
||||||
@ -334,23 +333,24 @@ class CreateEncodeResource(Resource):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
db.session.add(encoder)
|
db.session.add(encoder)
|
||||||
|
db.session.commit()
|
||||||
Kubectl(name=encoder.id, resourcetype="encoder",
|
Kubectl(name=encoder.id, resourcetype="encoder",
|
||||||
stream_key=encoder.stream_key).create_resource()
|
stream_key=encoder.stream_key).create_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
abort(503, "object already exists")
|
abort(409, "object already exists")
|
||||||
|
|
||||||
for neighbour in encoderobj['outputNeighbours']:
|
for neighbour in encoderobj['outputNeighbours']:
|
||||||
neighbour = StreamResource.query.filter_by(id=neighbour).first_or_404()
|
neighbour = StreamResource.query.filter_by(id=neighbour).first_or_404()
|
||||||
if neighbour.resource_type == StreamResourceTypeEnum.INGEST:
|
if neighbour.resource_type == StreamResourceTypeEnum.INGEST:
|
||||||
abort(400, "ingest cannot be a downstream component")
|
abort(400, "ingest cannot be a downstream component")
|
||||||
try:
|
|
||||||
neighbour.parent_id = encoder.id
|
neighbour.parent_id = encoder.id
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not add all neighbours")
|
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(encoder), 200
|
return self.streamresourceschema.dump(encoder), 200
|
||||||
|
|
||||||
|
|
||||||
@ -423,12 +423,12 @@ class ManipulateStreamResource(Resource):
|
|||||||
abort(422, "invalid arguments")
|
abort(422, "invalid arguments")
|
||||||
try:
|
try:
|
||||||
db.session.delete(streamreousrce)
|
db.session.delete(streamreousrce)
|
||||||
|
db.session.commit()
|
||||||
Kubectl(name=streamreousrce.id, resourcetype=streamreousrce.resource_type).delete_resource()
|
Kubectl(name=streamreousrce.id, resourcetype=streamreousrce.resource_type).delete_resource()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
abort(503, DB_ERROR_MSG)
|
abort(410, DB_ERROR_MSG)
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
return self.streamresourceschema.dump(streamreousrce), 200
|
return self.streamresourceschema.dump(streamreousrce), 200
|
||||||
|
|
||||||
|
|
||||||
@ -471,33 +471,25 @@ class ModifyIngressResource(Resource):
|
|||||||
for removeneighbours in listdiffer.elementsinfirstlistbutnotinsecond(currentoutputneighboursids,
|
for removeneighbours in listdiffer.elementsinfirstlistbutnotinsecond(currentoutputneighboursids,
|
||||||
ingestobj['outputNeighbours']):
|
ingestobj['outputNeighbours']):
|
||||||
neighbourobj = StreamResource.query.filter_by(id=removeneighbours).first_or_404()
|
neighbourobj = StreamResource.query.filter_by(id=removeneighbours).first_or_404()
|
||||||
try:
|
|
||||||
neighbourobj.parent_id = None
|
neighbourobj.parent_id = None
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not remove neighbourhood")
|
|
||||||
|
|
||||||
for addneighbours in listdiffer.elementsinsecondlistbutnotinfirst(currentoutputneighboursids,
|
for addneighbours in listdiffer.elementsinsecondlistbutnotinfirst(currentoutputneighboursids,
|
||||||
ingestobj['outputNeighbours']):
|
ingestobj['outputNeighbours']):
|
||||||
neighbourobj = StreamResource.query.filter_by(id=addneighbours).first_or_404()
|
neighbourobj = StreamResource.query.filter_by(id=addneighbours).first_or_404()
|
||||||
if neighbourobj.resource_type == StreamResourceTypeEnum.INGEST:
|
if neighbourobj.resource_type == StreamResourceTypeEnum.INGEST:
|
||||||
abort(400, "ingest cannot be a downstream component")
|
abort(400, "ingest cannot be a downstream component")
|
||||||
try:
|
|
||||||
neighbourobj.parent_id = ingest.id
|
neighbourobj.parent_id = ingest.id
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not remove neighbourhood")
|
|
||||||
else:
|
else:
|
||||||
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).update_resource()
|
Kubectl(name=ingest.id, resourcetype="ingest", stream_key=ingest.stream_key).update_resource()
|
||||||
if currentoutputneighbours:
|
if currentoutputneighbours:
|
||||||
for currentneighbour in currentoutputneighbours:
|
for currentneighbour in currentoutputneighbours:
|
||||||
try:
|
|
||||||
currentneighbour.parent_id = None
|
currentneighbour.parent_id = None
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not remove neighbourhood")
|
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(ingest), 200
|
return self.streamresourceschema.dump(ingest), 200
|
||||||
|
|
||||||
|
|
||||||
@ -547,25 +539,21 @@ class ModifyRestreamResource(Resource):
|
|||||||
restreamobj['outputURLs']):
|
restreamobj['outputURLs']):
|
||||||
elementtodelete = OutputUrls.query.filter_by(output_url=deleteoutputurl,
|
elementtodelete = OutputUrls.query.filter_by(output_url=deleteoutputurl,
|
||||||
streamresource_id=restream.id).first_or_404()
|
streamresource_id=restream.id).first_or_404()
|
||||||
try:
|
|
||||||
db.session.delete(elementtodelete)
|
db.session.delete(elementtodelete)
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not delete url")
|
|
||||||
for addoutputurl in listdiffer.elementsinsecondlistbutnotinfirst(currentoutputurlurls,
|
for addoutputurl in listdiffer.elementsinsecondlistbutnotinfirst(currentoutputurlurls,
|
||||||
restreamobj['outputURLs']):
|
restreamobj['outputURLs']):
|
||||||
elementtoadd = OutputUrls(output_url=addoutputurl, streamresource_id=restream.id)
|
elementtoadd = OutputUrls(output_url=addoutputurl, streamresource_id=restream.id)
|
||||||
try:
|
|
||||||
db.session.add(elementtoadd)
|
db.session.add(elementtoadd)
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "object already exists")
|
|
||||||
|
|
||||||
if currentoutputurlurls != restreamobj['outputURLs']:
|
if currentoutputurlurls != restreamobj['outputURLs']:
|
||||||
Kubectl(name=restream.id, resourcetype="restream", stream_key=restream.stream_key,
|
Kubectl(name=restream.id, resourcetype="restream", stream_key=restream.stream_key,
|
||||||
push_urls=restreamobj['outputURLs']).update_resource()
|
push_urls=restreamobj['outputURLs']).update_resource()
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(restream), 200
|
return self.streamresourceschema.dump(restream), 200
|
||||||
|
|
||||||
|
|
||||||
@ -633,11 +621,7 @@ class ModifyEncodeResource(Resource):
|
|||||||
else:
|
else:
|
||||||
if currentoutputneighbours:
|
if currentoutputneighbours:
|
||||||
for currentneighbour in currentoutputneighbours:
|
for currentneighbour in currentoutputneighbours:
|
||||||
try:
|
|
||||||
currentneighbour.parent_id = None
|
currentneighbour.parent_id = None
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.warning(e)
|
|
||||||
abort(503, "could not remove neighbourhood")
|
|
||||||
|
|
||||||
childurls = []
|
childurls = []
|
||||||
for child in encode.children:
|
for child in encode.children:
|
||||||
@ -646,7 +630,11 @@ class ModifyEncodeResource(Resource):
|
|||||||
Kubectl(name=encode.id, resourcetype="encoder",
|
Kubectl(name=encode.id, resourcetype="encoder",
|
||||||
stream_key=encode.stream_key, encode_push_urls=str(childurls)).update_resource()
|
stream_key=encode.stream_key, encode_push_urls=str(childurls)).update_resource()
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(encode), 200
|
return self.streamresourceschema.dump(encode), 200
|
||||||
|
|
||||||
|
|
||||||
@ -682,5 +670,9 @@ class CoordModifyResource(Resource):
|
|||||||
resource.x = coordobj['x']
|
resource.x = coordobj['x']
|
||||||
resource.y = coordobj['y']
|
resource.y = coordobj['y']
|
||||||
|
|
||||||
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
abort(412, DB_ERROR_MSG)
|
||||||
return self.streamresourceschema.dump(resource), 200
|
return self.streamresourceschema.dump(resource), 200
|
||||||
|
Loading…
Reference in New Issue
Block a user