Beispiel #1
0
async def delete_job(job_id: str, user: User, account: Account):
    scheduled_job = await ScheduledJobsService.get_job_by_id(
        job_id, user, account, ChronosScheduledJobsBackend())
    status_code = HTTPStatus.OK if scheduled_job else HTTPStatus.NOT_FOUND
    if scheduled_job:
        await ScheduledJobsService.delete_job(scheduled_job, user, account,
                                              ChronosScheduledJobsBackend())
    return json_response(ScheduledJobResource(job=scheduled_job).dict(),
                         status=status_code)
Beispiel #2
0
async def delete_job(request: web.Request, user: User, account: Account):
    job_id = request.match_info["job_id"]

    scheduled_job = await ScheduledJobsService.get_job_by_id(
        job_id, user, account, ChronosScheduledJobsBackend()
    )
    status_code = HTTPStatus.OK if scheduled_job else HTTPStatus.NOT_FOUND
    if scheduled_job:
        await ScheduledJobsService.delete_job(
            scheduled_job, user, account, ChronosScheduledJobsBackend()
        )
    return web.json_response(
        ScheduledJobResource(job=scheduled_job).dict(), status=status_code
    )
Beispiel #3
0
async def list_jobs(user: User, account: Account):

    jobs = await ScheduledJobsService.list_jobs(
        user, account, ChronosScheduledJobsBackend()
    )

    return web.json_response(ScheduledJobsListResource(jobs=jobs).dict())
Beispiel #4
0
 async def test_pass_auth_to_chronos_client(self):
     backend = ChronosScheduledJobsBackend()
     user, password = (
         settings.SCHEDULED_JOBS_SERVICE_AUTH.user,
         settings.SCHEDULED_JOBS_SERVICE_AUTH.password,
     )
     expected_auth_data = b64encode(
         f"{user}:{password}".encode("utf8")).decode("utf8")
     self.assertEqual(expected_auth_data, backend.client.auth_data)
Beispiel #5
0
async def index_jobs(request: web.Request):
    user = await User.from_alchemy_obj(request["user"])
    account = await Account.from_alchemy_obj(request["user"].current_account)
    job_id = request.match_info["job_id"]

    scheduled_job = await ScheduledJobsService.get_job_by_id(
        job_id, user, account, ChronosScheduledJobsBackend())
    status_code = HTTPStatus.OK if scheduled_job else HTTPStatus.NOT_FOUND
    return web.json_response(ScheduledJobResource(job=scheduled_job).dict(),
                             status=status_code)
Beispiel #6
0
    async def setUp(self):
        self.backend = ChronosScheduledJobsBackend()

        self.chronos_dev_job_fixture = get_fixture(
            "scheduled-jobs/chronos/dev-with-infra-in-name.json")

        self.asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            ChronosJob(**self.chronos_dev_job_fixture))

        self.user = User(**USER_WITH_MULTIPLE_ACCOUNTS_DICT)
        self.account = Account(**ACCOUNT_DEV_DICT)
Beispiel #7
0
async def create_job(job: ScheduledJob, user: User, account: Account):

    try:
        created_job = await ScheduledJobsService.create_job(
            job, user, account, ChronosScheduledJobsBackend())
    except DuplicateEntity as e:
        return json_response(
            ErrorResource(errors=[ErrorDetail(msg=str(e))]).dict(),
            status=HTTPStatus.UNPROCESSABLE_ENTITY,
        )
    return json_response(
        CreateScheduledJobResource(job=created_job).dict(),
        status=HTTPStatus.CREATED,
    )
Beispiel #8
0
async def _update_job(job: ScheduledJob, user: User,
                      account: Account) -> Response:
    try:
        updated_job = await ScheduledJobsService.update_job(
            job, user, account, ChronosScheduledJobsBackend())
    except NotFoundEntity as e:
        return json_response(
            ErrorResource(errors=[ErrorDetail(msg=str(e))]).dict(),
            status=HTTPStatus.NOT_FOUND,
        )

    return json_response(
        CreateScheduledJobResource(job=updated_job).dict(),
        status=HTTPStatus.ACCEPTED,
    )
Beispiel #9
0
 async def setUp(self):
     self.backend = ChronosScheduledJobsBackend()