3445b5d800148a4a9f252ecbdf4cd54b2fbdf3c8,apps/domain/src/main/core/services/infra_service.py,,del_worker_msg,#Any#Any#Any#,203

Before Change


    // Owner / Admin
    if users.can_manage_infrastructure(user_id=_current_user_id):
        node.environments.delete_associations(environment_id=_worker_id)
        node.environments.delete(id=_worker_id)
    else:  // Env Owner
        envs = [
            int(env.id)
            for env in node.environments.get_environments(user=_current_user_id)

After Change


def del_worker_msg(
    msg: DeleteWorkerMessage, node: AbstractNode, verify_key: VerifyKey
) -> DeleteWorkerResponse:
    try:
        // Get Payload Content
        worker_id = msg.content.get("worker_id", None)
        _current_user_id = msg.content.get("current_user", None)

        users = node.users
        if not _current_user_id:
            _current_user_id = users.first(
                verify_key=verify_key.encode(encoder=HexEncoder).decode("utf-8")
            ).id

        is_admin = users.can_manage_infrastructure(user_id=_current_user_id)

        envs = [
            int(env.id)
            for env in node.environments.get_environments(user=_current_user_id)
        ]
        created_by_current_user = int(worker_id) in envs

        // Owner / Admin
        if not is_admin and not created_by_current_user:
            raise AuthorizationError("You"re not allowed to delete this worker!")

        env = node.environments.first(id=worker_id)
        _config = Config(provider=env.provider, app=Config(name="worker", id=worker_id))

        success = Provider(_config).destroy()
        if success:
            node.environments.set(
                id=worker_id, state=states["destroyed"], destroyed_at=datetime.now()
            )
        else:
            raise Exception("Worker deletion failed")

        return DeleteWorkerResponse(
            address=msg.reply_to,
            status_code=200,
            content={"msg": "Worker was deleted successfully!"},
        )
    except Exception as e:
        return DeleteWorkerResponse(
            address=msg.reply_to, status_code=False, content={"error": str(e)}
        )


// def update_worker_msg(
//     msg: UpdateWorkerMessage,
//     node: AbstractNode,
//     verify_key: VerifyKey,
// ) -> UpdateWorkerResponse:
//     // Get Payload Content
//     _worker_id = msg.content.get("worker_id", None)
//     _current_user_id = msg.content.get("current_user", None)
//
//     env_parameters = {
//         i: msg.content[i]
//         for i in msg.content.keys()
//         if i in list(Environment.__table__.columns.keys())
//     }
//
//     users = node.users
//     if not _current_user_id:
//         _current_user_id = users.first(
//             verify_key=verify_key.encode(encoder=HexEncoder).decode("utf-8")
//         ).id
//
//     _current_user = users.first(id=_current_user_id)
//
//     // Owner / Admin
//     if users.can_manage_infrastructure(user_id=_current_user_id):
//         node.environments.modify({"id": _worker_id}, env_parameters)
//     else:  // Env Owner
//         envs = [
//             int(env.id)
//             for env in node.environments.get_environments(user=_current_user_id)
//         ]
//         if int(_worker_id) in envs:
//             node.environments.modify({"id": _worker_id}, env_parameters)
//         else:
//             raise AuthorizationError(
//                 "You"re not allowed to update this environment information!"
//             )
//     return UpdateWorkerResponse(
//         address=msg.reply_to,
//         status_code=200,
//         content={"msg": "Worker was updated succesfully!"},
//     )


class DomainInfrastructureService(ImmediateNodeServiceWithReply):

    msg_handler_map = {
        CreateWorkerMessage: create_worker_msg,
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 8

Non-data size: 3

Instances


Project Name: OpenMined/Grid
Commit Name: 3445b5d800148a4a9f252ecbdf4cd54b2fbdf3c8
Time: 2021-03-14
Author: sachinkumar04428@gmail.com
File Name: apps/domain/src/main/core/services/infra_service.py
Class Name:
Method Name: del_worker_msg


Project Name: ray-project/ray
Commit Name: 708dff6d8f7dd6f7919e06c1845f1fea0cca5b89
Time: 2020-04-20
Author: misraujval@gmail.com
File Name: python/ray/tune/durable_trainable.py
Class Name: DurableTrainable
Method Name: delete_checkpoint


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 223abdede96295f7fba58a1d1e1fb63a961c33f5
Time: 2019-10-09
Author: gguuss@gmail.com
File Name: iot/api-client/manager/manager.py
Class Name:
Method Name: delete_registry


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 34577913e8d62f0db23231f4882263b6825fa271
Time: 2017-08-28
Author: jonwayne@google.com
File Name: pubsub/cloud-client/quickstart_test.py
Class Name:
Method Name: temporary_topic


Project Name: comic/grand-challenge.org
Commit Name: c2a9ae3627fb4944a240439baa1082f539a100ec
Time: 2017-12-12
Author: pkcakeout@gmail.com
File Name: app/jqfileupload/widgets/uploader.py
Class Name:
Method Name: cleanup_stale_files


Project Name: comic/grand-challenge.org
Commit Name: 099b3eab0b64801e0a0bb54c5a7c8189baad0222
Time: 2012-11-27
Author: w.s.kerkstra@gmail.com
File Name: django/filetransfers/views.py
Class Name:
Method Name: delete_handler


Project Name: numerai/submission-criteria
Commit Name: e0a76816c32a7fbe2cec98d52605f13a1f2fe540
Time: 2018-11-20
Author: anson@numer.ai
File Name: submission_criteria/file_manager.py
Class Name: FileManager
Method Name: clean_up


Project Name: comic/grand-challenge.org
Commit Name: 4272398c0f1aebc3e21df81beba69c3a171fa567
Time: 2012-11-27
Author: w.s.kerkstra@gmail.com
File Name: django/filetransfers/views.py
Class Name:
Method Name: delete_handler