You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
from marshmallow_dataclass import dataclass, class_schema
|
|
from flask import Flask
|
|
from flask_smorest import Api, Blueprint
|
|
## from authlib.integrations.flask_oauth2 import ResourceProtector, current_token
|
|
|
|
|
|
## # Define a protected resource with JWT validation
|
|
## resource_protector = ResourceProtector()
|
|
|
|
## def validate_token():
|
|
## token = current_token
|
|
## claims = jwt.decode(token['access_token'], verify=False)
|
|
## issuer = claims['iss']
|
|
## jwks_uri = issuer + '/.well-known/jwks.json'
|
|
## # perform JWK set discovery and verification
|
|
## # return True if the token is valid, False otherwise
|
|
## return True
|
|
|
|
|
|
@dataclass
|
|
class FileTransfer:
|
|
s3: str
|
|
pesit: str
|
|
|
|
FileTransferSchema = class_schema(FileTransfer)()
|
|
|
|
transfer_blp = Blueprint('transfer', 'transfer')
|
|
|
|
|
|
@transfer_blp.route('/send', methods=['POST'])
|
|
@transfer_blp.arguments(FileTransferSchema, location='json')
|
|
@transfer_blp.response(200, description="Success")
|
|
@transfer_blp.response(400, description="Bad Request")
|
|
def send_file(transfer: FileTransfer):
|
|
"""Send a file from S3 to PeSIT.
|
|
|
|
:param transfer: A JSON object with "source" and "destination" fields.
|
|
:type transfer: FileTransfer
|
|
:return: A message indicating success or failure.
|
|
:rtype: str
|
|
"""
|
|
|
|
print("SEND")
|
|
|
|
@transfer_blp.route('/receive', methods=['POST'])
|
|
@transfer_blp.arguments(FileTransferSchema, location='json')
|
|
@transfer_blp.response(200, description="Success")
|
|
@transfer_blp.response(400, description="Bad Request")
|
|
def receive_file(transfer: FileTransfer):
|
|
"""Receive a file from PeSIT to S3"
|
|
|
|
:param transfer: A JSON object with "source" and "destination" fields.
|
|
:type transfer: FileTransfer
|
|
:return: A message indicating success or failure.
|
|
:rtype: str
|
|
"""
|
|
|
|
print("RECEIVE")
|
|
|
|
app = Flask(__name__)
|
|
app.config["API_TITLE"] = "S3/PeSIT proxy"
|
|
app.config["API_VERSION"] = "v1"
|
|
app.config["OPENAPI_VERSION"] = "3.0.2"
|
|
app.config["OPENAPI_URL_PREFIX"] = "oapi"
|
|
app.config["OPENAPI_REDOC_PATH"] = "redoc"
|
|
app.config["OPENAPI_REDOC_URL"] = "https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"
|
|
app.config["OPENAPI_SWAGGER_UI_PATH"] = "swagger"
|
|
app.config["OPENAPI_SWAGGER_UI_URL"] = "https://cdn.jsdelivr.net/npm/swagger-ui-dist/"
|
|
|
|
# OpenAPI endpoints: /oapi/openapi.json
|
|
# /oapi/redoc
|
|
# /opai/swagger
|
|
|
|
api = Api(app)
|
|
|
|
# register the transfer blueprint
|
|
api.register_blueprint(transfer_blp)
|
|
|
|
def main(debug: bool = False):
|
|
app.run(debug=debug)
|
|
|
|
if __name__ == "__main__":
|
|
main(debug=True)
|