Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

@@ 515-536 (lines=22) @@
512
        evc.sync()
513
        return JSONResponse("Operation successful", status_code=201)
514
515
    @rest("/v2/evc/metadata/{key}", methods=["DELETE"])
516
    @validate_openapi(spec)
517
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
518
        """Delete metada from a bulk of EVCs"""
519
        data = get_json_or_400(request, self.controller.loop)
520
        key = request.path_params["key"]
521
        circuit_ids = data.pop("circuit_ids")
522
        self.mongo_controller.update_evcs_metadata(
523
            circuit_ids, {key: ""}, "del"
524
        )
525
526
        fail_evcs = []
527
        for _id in circuit_ids:
528
            try:
529
                evc = self.circuits[_id]
530
                evc.remove_metadata(key)
531
            except KeyError:
532
                fail_evcs.append(_id)
533
534
        if fail_evcs:
535
            raise HTTPException(404, detail=fail_evcs)
536
        return JSONResponse("Operation successful")
537
538
    @rest("/v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
539
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 474-493 (lines=20) @@
471
                detail=f"circuit_id {circuit_id} not found."
472
            ) from error
473
474
    @rest("/v2/evc/metadata", methods=["POST"])
475
    @validate_openapi(spec)
476
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
477
        """Add metadata to a bulk of EVCs."""
478
        data = get_json_or_400(request, self.controller.loop)
479
        circuit_ids = data.pop("circuit_ids")
480
481
        self.mongo_controller.update_evcs_metadata(circuit_ids, data, "add")
482
483
        fail_evcs = []
484
        for _id in circuit_ids:
485
            try:
486
                evc = self.circuits[_id]
487
                evc.extend_metadata(data)
488
            except KeyError:
489
                fail_evcs.append(_id)
490
491
        if fail_evcs:
492
            raise HTTPException(404, detail=fail_evcs)
493
        return JSONResponse("Operation successful", status_code=201)
494
495
    @rest("/v2/evc/{circuit_id}/metadata", methods=["POST"])
496
    @validate_openapi(spec)