Beispiel #1
0
 def get(self, project_id, id):
     if len(ProjectModel.find_by_id(project_id)) == 0:
         return {'message': 'Project not found'}, 404
     executions = ExecutionModel.find_by_id_and_project_id(id, project_id)
     if executions:
         return {'execution': executions[0].json()}
     return {'message': 'Execution not found'}, 404
Beispiel #2
0
    def post(self, project_id):
        if not ProjectModel.find_by_id(project_id):
            return {
                'message':
                "A project with id '{}' does not exist.".format(project_id)
            }, 404

        # Create a new execution
        execution = ExecutionModel(project_id=project_id)
        try:
            execution.exec()
        except Exception as e:
            logging.error(repr(e))
            return {"message": "An error occurred running the item."}, 500

        return {'execution': execution.json()}, 201
Beispiel #3
0
 def get(self, project_id):
     if len(ProjectModel.find_by_id(project_id)) == 0:
         return {'message': 'Project not found'}, 404
     return {
         'executions':
         list(
             map(lambda x: x.json(),
                 ExecutionModel.find_executions_by_project_id(project_id)))
     }
Beispiel #4
0
 def get(self, project_id, id):
     data = ExecutionOutput.parser.parse_args()
     if len(ProjectModel.find_by_id(project_id)) == 0:
         return {'message': 'Project not found'}, 404
     exec_output = ExecutionModel.get_output(id, project_id,
                                             data['first_requested_byte'],
                                             data['last_requested_byte'])
     if exec_output:
         return {'output': exec_output.json()}
     return {'message': 'Execution not found'}, 404
Beispiel #5
0
def bootstrap(force=False, dev=False, quiet=False):
    if not force:
        # verify and skip if it is not necessary
        if db.present():
            return
    db.delete_all()
    UserModel.create_table()
    UserProjectMap.create_table()
    ProjectModel.create_table()
    EnvironmentModel.create_table()
    SettingModel.create_table()
    MainSettingModel.create_table()
    InitProjectSettingModel.create_table()
    UserProjectMap.create_table()
    ProjectEnvironmentMap.create_table()
    ProjectSettingMap.create_table()

    #######
    # Users
    alphabet = string.ascii_letters + string.digits
    admin_password = ''.join(secrets.choice(alphabet) for i in range(20))
    new_user = UserModel(id=None,
                         username="******",
                         password=admin_password,
                         admin=1)
    new_user.save()
    if not quiet:
        print(f'################### Admin user created ##################')
        print(f'######### Admin password: "******" ########')
        print(f'#########################################################')
    if dev:
        logging.debug('Creation of the developping users')
        new_user = UserModel(id=None,
                             username="******",
                             password="******",
                             admin=1)
        new_user.save()
        new_user = UserModel(id=None,
                             username="******",
                             password="******",
                             admin=0)
        new_user.save()
        new_user = UserModel(id=None,
                             username="******",
                             password="******",
                             admin=0)
        new_user.save()
        new_user.username = "******"
        new_user.save()


##########
# Settings

# Main Settings
    new_setting = SettingModel(
        id=None,
        name="max_project_run_number",
        description="Number of executions per project that are stored",
        default_value=20)
    new_setting.save()
    new_main_setting = MainSettingModel(new_setting.name, new_setting.id)
    new_main_setting.save()

    new_setting = SettingModel(
        id=None,
        name="name_default_container_image",
        description="Default container image to use",
        value="fabrizio2210/docker_light-default_container",
        default_value="debian")
    new_setting.save()
    new_main_setting = MainSettingModel(new_setting.name, new_setting.id)
    new_main_setting.save()

    # Initial Project Settings
    new_setting = SettingModel(
        id=None,
        name="scm_url",
        description="Source Control Manager URL of the project")
    new_setting.save()
    new_main_setting = InitProjectSettingModel(new_setting.name,
                                               new_setting.id)
    new_main_setting.save()

    new_setting = SettingModel(id=None,
                               name="image_use_docker",
                               value=True,
                               default_value=True,
                               description="If the image use docker inside")
    new_setting.save()
    new_main_setting = InitProjectSettingModel(new_setting.name,
                                               new_setting.id)
    new_main_setting.save()

    ##############
    # Environments

    ############
    # Executions
    ExecutionModel.cleanup()
Beispiel #6
0
from db import db
from models.execution import ExecutionModel
from resources.user import UserRegister
from resources.userlogin import UserLogin, TokenRefresh
from resources.project import Project, ProjectList, NewProject
from resources.project_setting import ProjectSetting, ProjectSettingList
from resources.main_setting import MainSettingList, MainSetting
from resources.environment import EnvironmentList, Environment, NewEnvironment
from resources.execution import Execution, NewExecution, ExecutionList, ExecutionOutput
from utils.networking import get_my_ip
from utils.data import bootstrap


# Initialise from envrironment variables
db.set_db_filename(os.getenv('DB_PATH', '/tmp/data.db'))
ExecutionModel.set_projects_dir(os.getenv('PROJECTS_PATH', '/tmp/projects'))


app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True
app.config['JWT_HEADER_TYPE'] = "JWT" 
app.secret_key = os.getenv('JWT_SECRET', 'Qw2sGsa7ED34f6dAfgFSdLopdAdg')
api = Api(app)


# Initialise data
bootstrap(force=False)

# API
jwt = JWTManager(app)
api.add_resource(UserLogin,     '/api/auth')
Beispiel #7
0
 def delete(self, project_id, id):
     if len(ProjectModel.find_by_id(project_id)) == 0:
         return {'message': 'Project not found'}, 404
     if ExecutionModel.delete_by_id_and_project_id(id, project_id):
         return {'message': 'Item deleted.'}, 200
     return {'message': 'Item not found.'}, 404