diff --git a/CHANGELOG.md b/CHANGELOG.md index 052cb56f7..ad2085e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `ComputeTaskFailureReport` renamed in `AssetFailureReport` ([#727](https://github.com/Substra/substra-backend/pull/727)) - Field `AssetFailureReport.compute_task_key` renamed to `asset_key` ([#727](https://github.com/Substra/substra-backend/pull/727)) -- Docker images are no longer removed at the end of a compute plan ([#777](https://github.com/Substra/substra-backend/pull/777) +- Docker images are no longer removed at the end of a compute plan ([#777](https://github.com/Substra/substra-backend/pull/777)) +- Rename `LEDGER_CHANNEL` to `CHANNELS` and `LEDGER_MSP_ID` to `MSP_ID` ([#794](https://github.com/Substra/substra-backend/pull/794)) ### Removed diff --git a/backend/api/events/reactor.py b/backend/api/events/reactor.py index 65cdf2687..d9718a7e8 100644 --- a/backend/api/events/reactor.py +++ b/backend/api/events/reactor.py @@ -59,7 +59,7 @@ def consume(health_service: health.HealthService): exception_raised, ), ) - for channel_name in settings.LEDGER_CHANNELS.keys() + for channel_name in settings.CHANNELS.keys() ] for consumer in consumers: diff --git a/backend/api/serializers/utils.py b/backend/api/serializers/utils.py index 3e394bb31..555675e5c 100644 --- a/backend/api/serializers/utils.py +++ b/backend/api/serializers/utils.py @@ -83,4 +83,4 @@ def get_channel_choices() -> list[str]: """ Get serializer choices from channels settings. """ - return list(settings.LEDGER_CHANNELS.keys()) + return list(settings.CHANNELS.keys()) diff --git a/backend/api/tests/views/test_utils.py b/backend/api/tests/views/test_utils.py index 2472b3770..c44459923 100644 --- a/backend/api/tests/views/test_utils.py +++ b/backend/api/tests/views/test_utils.py @@ -25,7 +25,7 @@ MEDIA_ROOT = tempfile.mkdtemp() -@override_settings(LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}) +@override_settings(CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}) class PermissionMixinDownloadFileTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_authentication.py b/backend/api/tests/views/test_views_authentication.py index 4c9f6c722..4c813161b 100644 --- a/backend/api/tests/views/test_views_authentication.py +++ b/backend/api/tests/views/test_views_authentication.py @@ -24,7 +24,7 @@ @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, ) class AuthenticationTests(APITestCase): def setUp(self): diff --git a/backend/api/tests/views/test_views_compute_plan_graph.py b/backend/api/tests/views/test_views_compute_plan_graph.py index e1cc58804..2bbffb2fc 100644 --- a/backend/api/tests/views/test_views_compute_plan_graph.py +++ b/backend/api/tests/views/test_views_compute_plan_graph.py @@ -97,7 +97,7 @@ def create_compute_graph(): @override_settings( - MEDIA_ROOT=MEDIA_ROOT, LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} + MEDIA_ROOT=MEDIA_ROOT, CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} ) class ComputePlanGraphViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_computeplan.py b/backend/api/tests/views/test_views_computeplan.py index db4eeefb6..8b4c0cfa6 100644 --- a/backend/api/tests/views/test_views_computeplan.py +++ b/backend/api/tests/views/test_views_computeplan.py @@ -53,7 +53,7 @@ class AuthenticatedAPITestCase(APITestCase): @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={ + CHANNELS={ "mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}, "yourchannel": {"chaincode": {"name": "yourcc"}, "model_export_enabled": True}, }, diff --git a/backend/api/tests/views/test_views_computetask.py b/backend/api/tests/views/test_views_computetask.py index a1b4bd4ed..153ceb722 100644 --- a/backend/api/tests/views/test_views_computetask.py +++ b/backend/api/tests/views/test_views_computetask.py @@ -155,7 +155,7 @@ def tearDown(self): @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, ) class TaskBulkCreateViewTests(ComputeTaskViewTests): def test_task_bulk_create(self): @@ -253,7 +253,7 @@ def mock_register_compute_task(orc_request): @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, ) class GenericTaskViewTests(ComputeTaskViewTests): def setUp(self): diff --git a/backend/api/tests/views/test_views_datamanager.py b/backend/api/tests/views/test_views_datamanager.py index 910d2ffdd..0826cbbe1 100644 --- a/backend/api/tests/views/test_views_datamanager.py +++ b/backend/api/tests/views/test_views_datamanager.py @@ -29,8 +29,8 @@ @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, - LEDGER_MSP_ID="MyTestOrg", + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + MSP_ID="MyTestOrg", ) class DataManagerViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_datasample.py b/backend/api/tests/views/test_views_datasample.py index b2949e77b..51bb4b316 100644 --- a/backend/api/tests/views/test_views_datasample.py +++ b/backend/api/tests/views/test_views_datasample.py @@ -51,7 +51,7 @@ def mock_register_datasamples(orc_request): @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, ) @override_settings(DEFAULT_DOMAIN="https://localhost") class DataSampleViewTests(APITestCase): diff --git a/backend/api/tests/views/test_views_failed_asset_logs.py b/backend/api/tests/views/test_views_failed_asset_logs.py index 5fe6db3d4..962e9cfa3 100644 --- a/backend/api/tests/views/test_views_failed_asset_logs.py +++ b/backend/api/tests/views/test_views_failed_asset_logs.py @@ -22,7 +22,7 @@ def asset_failure_report() -> tuple[ComputeTask, AssetFailureReport]: factory.create_computeplan(), factory.create_function(), public=False, - owner=conf.settings.LEDGER_MSP_ID, + owner=conf.settings.MSP_ID, ) failure_report = factory.create_computetask_logs(compute_task.key) return compute_task, failure_report @@ -47,8 +47,8 @@ def test_download_local_logs_success( """An authorized user download logs located on the organization.""" compute_task, failure_report = asset_failure_report - assert compute_task.owner == conf.settings.LEDGER_MSP_ID # local - assert conf.settings.LEDGER_MSP_ID in compute_task.logs_permission_authorized_ids # allowed + assert compute_task.owner == conf.settings.MSP_ID # local + assert conf.settings.MSP_ID in compute_task.logs_permission_authorized_ids # allowed res = get_logs(key=compute_task.key, client=authenticated_client) @@ -66,7 +66,7 @@ def test_download_logs_failure_forbidden( """An authenticated user cannot download logs if he is not authorized.""" compute_task, failure_report = asset_failure_report - assert compute_task.owner == conf.settings.LEDGER_MSP_ID # local + assert compute_task.owner == conf.settings.MSP_ID # local compute_task.logs_permission_authorized_ids = [] # not allowed compute_task.save() @@ -83,8 +83,8 @@ def test_download_local_logs_failure_not_found( """An authorized user attempt to download logs that are not referenced in the database.""" compute_task, failure_report = asset_failure_report - assert compute_task.owner == conf.settings.LEDGER_MSP_ID # local - assert conf.settings.LEDGER_MSP_ID in compute_task.logs_permission_authorized_ids # allowed + assert compute_task.owner == conf.settings.MSP_ID # local + assert conf.settings.MSP_ID in compute_task.logs_permission_authorized_ids # allowed failure_report.delete() # not found res = get_logs(key=compute_task.key, client=authenticated_client) @@ -102,7 +102,7 @@ def test_download_remote_logs_success( compute_task, failure_report = asset_failure_report outgoing_organization = "outgoing-organization" compute_task.logs_owner = outgoing_organization # remote - compute_task.logs_permission_authorized_ids = [conf.settings.LEDGER_MSP_ID, outgoing_organization] # allowed + compute_task.logs_permission_authorized_ids = [conf.settings.MSP_ID, outgoing_organization] # allowed compute_task.save() organization_models.OutgoingOrganization.objects.create( organization_id=outgoing_organization, secret=organization_models.Organization.generate_password() @@ -129,7 +129,7 @@ def test_download_remote_logs_success( @pytest.fixture def incoming_organization_user(settings: conf.Settings) -> organization_auth.OrganizationUser: incoming_organization = "incoming-organization" - settings.LEDGER_CHANNELS.update({incoming_organization: {"chaincode": {"name": "mycc2"}}}) + settings.CHANNELS.update({incoming_organization: {"chaincode": {"name": "mycc2"}}}) return organization_auth.OrganizationUser(username=incoming_organization) @@ -146,9 +146,9 @@ def test_organization_download_logs_success( """An authorized organization can download logs from another organization.""" compute_task, failure_report = asset_failure_report - compute_task.logs_owner = conf.settings.LEDGER_MSP_ID # local (incoming request from remote) + compute_task.logs_owner = conf.settings.MSP_ID # local (incoming request from remote) compute_task.logs_permission_authorized_ids = [ - conf.settings.LEDGER_MSP_ID, + conf.settings.MSP_ID, incoming_organization_user.username, ] # incoming user allowed compute_task.channel = incoming_organization_user.username @@ -173,8 +173,8 @@ def test_organization_download_logs_forbidden( """An unauthorized organization cannot download logs from another organization.""" compute_task, failure_report = asset_failure_report - compute_task.logs_owner = conf.settings.LEDGER_MSP_ID # local (incoming request from remote) - compute_task.logs_permission_authorized_ids = [conf.settings.LEDGER_MSP_ID] # incoming user not allowed + compute_task.logs_owner = conf.settings.MSP_ID # local (incoming request from remote) + compute_task.logs_permission_authorized_ids = [conf.settings.MSP_ID] # incoming user not allowed compute_task.channel = incoming_organization_user.username compute_task.save() diff --git a/backend/api/tests/views/test_views_function.py b/backend/api/tests/views/test_views_function.py index ace51eedd..47f83f642 100644 --- a/backend/api/tests/views/test_views_function.py +++ b/backend/api/tests/views/test_views_function.py @@ -30,7 +30,7 @@ @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, ) class FunctionViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_info.py b/backend/api/tests/views/test_views_info.py index bc36efaa9..4a4fdb6b9 100644 --- a/backend/api/tests/views/test_views_info.py +++ b/backend/api/tests/views/test_views_info.py @@ -10,7 +10,7 @@ from orchestrator.resources import OrchestratorVersion -@override_settings(LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}) +@override_settings(CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}) class InfoViewTests(APITestCase): url = "/info/" diff --git a/backend/api/tests/views/test_views_metadata.py b/backend/api/tests/views/test_views_metadata.py index fb409753c..03167d91c 100644 --- a/backend/api/tests/views/test_views_metadata.py +++ b/backend/api/tests/views/test_views_metadata.py @@ -14,7 +14,7 @@ @override_settings( - MEDIA_ROOT=MEDIA_ROOT, LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} + MEDIA_ROOT=MEDIA_ROOT, CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} ) class ComputePlanMetadataViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_model.py b/backend/api/tests/views/test_views_model.py index cdf929feb..a459819bb 100644 --- a/backend/api/tests/views/test_views_model.py +++ b/backend/api/tests/views/test_views_model.py @@ -30,8 +30,8 @@ @override_settings( MEDIA_ROOT=MEDIA_ROOT, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, - LEDGER_MSP_ID=TEST_ORG, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + MSP_ID=TEST_ORG, ) class ModelViewTests(APITestCase): client_class = AuthenticatedClient @@ -293,7 +293,7 @@ def test_model_download_by_organization_for_worker(self): is_proxied_request=False, ) - @override_settings(LEDGER_CHANNELS={CHANNEL: {"model_export_enabled": True}}) + @override_settings(CHANNELS={CHANNEL: {"model_export_enabled": True}}) def test_model_export_proxied(self): """Model export (proxied) with option enabled""" pvs = ModelPermissionViewSet() @@ -320,7 +320,7 @@ def test_model_export_proxied(self): is_proxied_request=True, ) - @override_settings(LEDGER_CHANNELS={CHANNEL: {"model_export_enabled": False}}) + @override_settings(CHANNELS={CHANNEL: {"model_export_enabled": False}}) def test_model_download_by_organization_proxied_option_disabled(self): """Model export (proxied) with option disabled""" pvs = ModelPermissionViewSet() @@ -333,7 +333,7 @@ def test_model_download_by_organization_proxied_option_disabled(self): is_proxied_request=True, ) - @override_settings(LEDGER_CHANNELS={CHANNEL: {"model_export_enabled": True}}) + @override_settings(CHANNELS={CHANNEL: {"model_export_enabled": True}}) def test_model_download_by_classic_user_enabled(self): """Model export (by end-user, not proxied) with option enabled""" pvs = ModelPermissionViewSet() @@ -353,7 +353,7 @@ def test_model_download_by_classic_user_enabled(self): is_proxied_request=False, ) - @override_settings(LEDGER_CHANNELS={CHANNEL: {"model_export_enabled": False}}) + @override_settings(CHANNELS={CHANNEL: {"model_export_enabled": False}}) def test_model_download_by_classic_user_disabled(self): """Model export (by end-user, not proxied) with option disabled""" pvs = ModelPermissionViewSet() @@ -366,7 +366,7 @@ def test_model_download_by_classic_user_disabled(self): is_proxied_request=False, ) - @override_settings(LEDGER_CHANNELS={CHANNEL: {}}) + @override_settings(CHANNELS={CHANNEL: {}}) def test_model_download_by_classic_user_default(self): pvs = ModelPermissionViewSet() diff --git a/backend/api/tests/views/test_views_newsfeed.py b/backend/api/tests/views/test_views_newsfeed.py index e4ec13d87..e2710f06b 100644 --- a/backend/api/tests/views/test_views_newsfeed.py +++ b/backend/api/tests/views/test_views_newsfeed.py @@ -16,7 +16,7 @@ @override_settings( - MEDIA_ROOT=MEDIA_ROOT, LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} + MEDIA_ROOT=MEDIA_ROOT, CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} ) class NewsFeedViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_performance.py b/backend/api/tests/views/test_views_performance.py index 5756a77b9..c8e9aa560 100644 --- a/backend/api/tests/views/test_views_performance.py +++ b/backend/api/tests/views/test_views_performance.py @@ -22,7 +22,7 @@ @override_settings( - MEDIA_ROOT=MEDIA_ROOT, LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} + MEDIA_ROOT=MEDIA_ROOT, CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} ) class CPPerformanceViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/api/tests/views/test_views_task_profiling.py b/backend/api/tests/views/test_views_task_profiling.py index 335fe511c..5d1c5cf17 100644 --- a/backend/api/tests/views/test_views_task_profiling.py +++ b/backend/api/tests/views/test_views_task_profiling.py @@ -12,8 +12,8 @@ TEST_ORG = "MyTestOrg" ORG_SETTINGS = { - "LEDGER_CHANNELS": {"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, - "LEDGER_MSP_ID": TEST_ORG, + "CHANNELS": {"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + "MSP_ID": TEST_ORG, } EXTRA = {"HTTP_SUBSTRA_CHANNEL_NAME": CHANNEL, "HTTP_ACCEPT": "application/json;version=0.0"} @@ -189,7 +189,7 @@ def test_step_update(authenticated_backend_client, task_profiling): @override_settings(**EXTRA) @override_settings( - LEDGER_MSP_ID="other_org", + MSP_ID="other_org", ) @pytest.mark.django_db() def test_task_profiling_create_fail_other_backend(authenticated_client, create_compute_task): diff --git a/backend/api/views/model.py b/backend/api/views/model.py index c29e78aef..2050d31d3 100644 --- a/backend/api/views/model.py +++ b/backend/api/views/model.py @@ -133,9 +133,9 @@ def check_access(self, channel_name: str, user, asset, is_proxied_request: bool) @staticmethod def _check_export_enabled(channel_name): - channel = settings.LEDGER_CHANNELS[channel_name] + channel = settings.CHANNELS[channel_name] if not channel.get("model_export_enabled", False): - raise AssetPermissionError(f"Disabled: model_export_enabled is disabled on {settings.LEDGER_MSP_ID}") + raise AssetPermissionError(f"Disabled: model_export_enabled is disabled on {settings.MSP_ID}") @if_true(gzip.gzip_page, settings.GZIP_MODELS) @action(detail=True) diff --git a/backend/backend/settings/deps/ledger.py b/backend/backend/settings/deps/ledger.py index 66a852c18..6214ebf2a 100644 --- a/backend/backend/settings/deps/ledger.py +++ b/backend/backend/settings/deps/ledger.py @@ -1,10 +1,10 @@ import json import os -LEDGER_CHANNELS = { +CHANNELS = { channel: settings - for channels in json.loads(os.environ.get("LEDGER_CHANNELS", "[]")) + for channels in json.loads(os.environ.get("CHANNELS", "[]")) for channel, settings in channels.items() } -LEDGER_MSP_ID = os.environ.get("LEDGER_MSP_ID") +MSP_ID = os.environ.get("MSP_ID") diff --git a/backend/backend/settings/localdev.py b/backend/backend/settings/localdev.py index fda523452..2df204763 100644 --- a/backend/backend/settings/localdev.py +++ b/backend/backend/settings/localdev.py @@ -15,6 +15,6 @@ ALLOWED_HOSTS = ALLOWED_HOSTS + ["127.0.0.1", ".org-1.com"] COMMON_HOST_DOMAIN = "org-1.com" -LEDGER_MSP_ID = os.environ.get("LEDGER_MSP_ID", "MyOrg1MSP") +MSP_ID = os.environ.get("MSP_ID", "MyOrg1MSP") -LEDGER_CHANNELS["mychannel"]["model_export_enabled"] = False +CHANNELS["mychannel"]["model_export_enabled"] = False diff --git a/backend/backend/settings/test.py b/backend/backend/settings/test.py index e7a62fe90..26516ff27 100644 --- a/backend/backend/settings/test.py +++ b/backend/backend/settings/test.py @@ -29,5 +29,5 @@ ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS = False ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA = 0 -LEDGER_MSP_ID = "testOrgMSP" -LEDGER_CHANNELS = {"mychannel": {"chaincode": {"name": "mycc"}}} +MSP_ID = "testOrgMSP" +CHANNELS = {"mychannel": {"chaincode": {"name": "mycc"}}} diff --git a/backend/backend/views.py b/backend/backend/views.py index 406564c3d..dec539695 100644 --- a/backend/backend/views.py +++ b/backend/backend/views.py @@ -102,7 +102,7 @@ def get(self, request, *args, **kwargs): if request.user.is_authenticated: channel_name = get_channel_name(request) - channel = settings.LEDGER_CHANNELS[channel_name] + channel = settings.CHANNELS[channel_name] orchestrator_versions = None diff --git a/backend/libs/health_check_middleware.py b/backend/libs/health_check_middleware.py index 0ae41fafe..e6161db7a 100644 --- a/backend/libs/health_check_middleware.py +++ b/backend/libs/health_check_middleware.py @@ -45,14 +45,14 @@ def readiness(self, request): def validate_connections(): if not settings.ISOLATED: # Check orchestrator connection for each channel - for channel_name, _ in settings.LEDGER_CHANNELS.items(): + for channel_name, _ in settings.CHANNELS.items(): with get_orchestrator_client(channel_name) as client: client.query_version() def validate_channels(): # Check channel restrictions - for channel_name, channel_settings in settings.LEDGER_CHANNELS.items(): + for channel_name, channel_settings in settings.CHANNELS.items(): organizations = ChannelOrganizationRep.objects.filter(channel=channel_name).values_list( "organization_id", flat=True ) @@ -65,5 +65,5 @@ def validate_channels(): ) # throw an Exception if the organization is not in the list - if settings.LEDGER_MSP_ID not in organizations: - raise Exception(f'Organization {settings.LEDGER_MSP_ID} is not registered in channel "{channel_name}"') + if settings.MSP_ID not in organizations: + raise Exception(f'Organization {settings.MSP_ID} is not registered in channel "{channel_name}"') diff --git a/backend/orchestrator/client.py b/backend/orchestrator/client.py index 664f04013..4872f450b 100644 --- a/backend/orchestrator/client.py +++ b/backend/orchestrator/client.py @@ -378,7 +378,7 @@ def subscribe_to_events(self, channel_name=None, start_event_id=""): metadata = ( ("mspid", self._mspid), ("channel", channel_name), - ("chaincode", settings.LEDGER_CHANNELS[channel_name]["chaincode"]["name"]), + ("chaincode", settings.CHANNELS[channel_name]["chaincode"]["name"]), ) else: metadata = self._metadata diff --git a/backend/organization/tests/views/test_views_organization.py b/backend/organization/tests/views/test_views_organization.py index 3dc077b83..a8973f01b 100644 --- a/backend/organization/tests/views/test_views_organization.py +++ b/backend/organization/tests/views/test_views_organization.py @@ -13,7 +13,7 @@ @override_settings( - MEDIA_ROOT=MEDIA_ROOT, LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} + MEDIA_ROOT=MEDIA_ROOT, CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} ) class ModelViewTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/organization_register/apps.py b/backend/organization_register/apps.py index 0a063f292..39a5c9b70 100644 --- a/backend/organization_register/apps.py +++ b/backend/organization_register/apps.py @@ -39,5 +39,5 @@ def register_organization(self, channel_name: str) -> None: def ready(self) -> None: if not settings.ISOLATED: - for channel_name in settings.LEDGER_CHANNELS.keys(): + for channel_name in settings.CHANNELS.keys(): self.register_organization(channel_name) diff --git a/backend/substrapp/clients/organization.py b/backend/substrapp/clients/organization.py index 086fc64cc..7a720c228 100644 --- a/backend/substrapp/clients/organization.py +++ b/backend/substrapp/clients/organization.py @@ -27,7 +27,7 @@ class _Method(enum.Enum): PUT = enum.auto() -_LEDGER_MSP_ID: str = settings.LEDGER_MSP_ID +_MSP_ID: str = settings.MSP_ID _HTTP_VERIFY: bool = not settings.DEBUG _HTTP_TIMEOUT: int = settings.HTTP_CLIENT_TIMEOUT_SECONDS _HTTP_STREAM_CHUNK_SIZE: int = 1024 * 1024 # in bytes, equivalent to 1 megabyte @@ -127,7 +127,7 @@ def _http_request( response = _HTTP_METHOD_TO_FUNC[method]( url, headers=_add_mandatory_headers(headers, channel), - auth=HTTPBasicAuth(_LEDGER_MSP_ID, secret), + auth=HTTPBasicAuth(_MSP_ID, secret), verify=_HTTP_VERIFY, timeout=_HTTP_TIMEOUT, **_http_request_kwargs(data, stream), diff --git a/backend/substrapp/compute_tasks/outputs.py b/backend/substrapp/compute_tasks/outputs.py index fb2fd5b17..21dd6a593 100644 --- a/backend/substrapp/compute_tasks/outputs.py +++ b/backend/substrapp/compute_tasks/outputs.py @@ -104,7 +104,7 @@ def _save_model_to_local_storage(self, model: context.OutputResource) -> dict: def _register_models_in_api(self, registered_models: dict): return organization_client.post( self._ctx.channel_name, - settings.LEDGER_MSP_ID, + settings.MSP_ID, settings.DEFAULT_DOMAIN + reverse("api:model-list"), data={"metadata": json.dumps(registered_models)}, ) diff --git a/backend/substrapp/events/handler_compute_engine.py b/backend/substrapp/events/handler_compute_engine.py index ab5558a8c..7055d6ea8 100644 --- a/backend/substrapp/events/handler_compute_engine.py +++ b/backend/substrapp/events/handler_compute_engine.py @@ -7,7 +7,7 @@ from substrapp.tasks.tasks_remove_intermediary_models import queue_remove_intermediary_model_from_db from substrapp.tasks.tasks_remove_intermediary_models import queue_remove_intermediary_models_from_buffer -_MY_ORGANIZATION: str = settings.LEDGER_MSP_ID +_MY_ORGANIZATION: str = settings.MSP_ID def _filter_parent_task_outputs_refs( diff --git a/backend/substrapp/events/reactor.py b/backend/substrapp/events/reactor.py index 5edcbad2e..86010ac40 100644 --- a/backend/substrapp/events/reactor.py +++ b/backend/substrapp/events/reactor.py @@ -23,7 +23,7 @@ from substrapp.tasks.tasks_save_image import save_image_task logger = structlog.get_logger("events") -_MY_ORGANIZATION: str = settings.LEDGER_MSP_ID +_MY_ORGANIZATION: str = settings.MSP_ID def on_computetask_event(payload): @@ -184,7 +184,7 @@ def consume(health_service: health.HealthService): exception_raised, ), ) - for channel_name in settings.LEDGER_CHANNELS.keys() + for channel_name in settings.CHANNELS.keys() ] for consumer in consumers: diff --git a/backend/substrapp/orchestrator.py b/backend/substrapp/orchestrator.py index 194a82408..df6a3e398 100644 --- a/backend/substrapp/orchestrator.py +++ b/backend/substrapp/orchestrator.py @@ -18,10 +18,10 @@ def get_orchestrator_client(channel_name: str = None) -> OrchestratorClient: client_key = settings.ORCHESTRATOR_TLS_CLIENT_KEY_PATH client_cert = settings.ORCHESTRATOR_TLS_CLIENT_CERT_PATH - mspid = settings.LEDGER_MSP_ID + mspid = settings.MSP_ID if channel_name is not None: - chaincode = settings.LEDGER_CHANNELS[channel_name]["chaincode"]["name"] + chaincode = settings.CHANNELS[channel_name]["chaincode"]["name"] opts = ( ("grpc.keepalive_time_ms", settings.ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS), diff --git a/backend/substrapp/tasks/tasks_compute_task.py b/backend/substrapp/tasks/tasks_compute_task.py index 6b7ea555f..ad6191c4a 100644 --- a/backend/substrapp/tasks/tasks_compute_task.py +++ b/backend/substrapp/tasks/tasks_compute_task.py @@ -133,10 +133,10 @@ def compute_task(self: ComputeTask, channel_name: str, serialized_task: str, com def _send_profiling_event(*, channel_name: str, url_create: str, url_update: str, data: dict[str, Any]) -> bytes: try: - return organization_client.post(channel_name, settings.LEDGER_MSP_ID, url_create, data) + return organization_client.post(channel_name, settings.MSP_ID, url_create, data) except OrganizationHttpError as e: if e.status_code == status.HTTP_409_CONFLICT: - return organization_client.put(channel_name, settings.LEDGER_MSP_ID, url_update, data) + return organization_client.put(channel_name, settings.MSP_ID, url_update, data) else: raise e diff --git a/backend/substrapp/tests/compute_tasks/test_asset_buffer.py b/backend/substrapp/tests/compute_tasks/test_asset_buffer.py index 6e71175b3..afa312227 100644 --- a/backend/substrapp/tests/compute_tasks/test_asset_buffer.py +++ b/backend/substrapp/tests/compute_tasks/test_asset_buffer.py @@ -127,7 +127,7 @@ def falsify_content(self, new_content): @override_settings( ASSET_BUFFER_DIR=ASSET_BUFFER_DIR, - LEDGER_CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, + CHANNELS={"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}}, ) class AssetBufferTests(APITestCase): def setUp(self): diff --git a/backend/substrapp/utils/__init__.py b/backend/substrapp/utils/__init__.py index a9795daa6..f56590c94 100644 --- a/backend/substrapp/utils/__init__.py +++ b/backend/substrapp/utils/__init__.py @@ -55,7 +55,7 @@ def get_hash(file, key=None): def get_owner() -> str: - return settings.LEDGER_MSP_ID + return settings.MSP_ID def compute_hash(bytes, key=None): diff --git a/backend/users/tests/test_user.py b/backend/users/tests/test_user.py index 6ad7264b0..ed1a4c7a7 100644 --- a/backend/users/tests/test_user.py +++ b/backend/users/tests/test_user.py @@ -108,7 +108,7 @@ class TestUserEndpoints: @pytest.fixture(autouse=True) def use_dummy_channels(self, settings): - settings.LEDGER_CHANNELS = {"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} + settings.CHANNELS = {"mychannel": {"chaincode": {"name": "mycc"}, "model_export_enabled": True}} @classmethod def setup_class(cls): diff --git a/backend/users/views/user.py b/backend/users/views/user.py index 7fc04a0f9..453fcba78 100644 --- a/backend/users/views/user.py +++ b/backend/users/views/user.py @@ -41,7 +41,7 @@ def _xor_secrets(secret1, secret2): def _validate_channel(name): - if name not in settings.LEDGER_CHANNELS: + if name not in settings.CHANNELS: raise ValidationError({"channel": "Channel does not exist"}) diff --git a/charts/substra-backend/CHANGELOG.md b/charts/substra-backend/CHANGELOG.md index f48692449..0a8abc2e9 100644 --- a/charts/substra-backend/CHANGELOG.md +++ b/charts/substra-backend/CHANGELOG.md @@ -2,6 +2,12 @@ ## [] - Unreleased +## [24.0.1] - 2023-12-15 + +### Changed + +- Rename `LEDGER_CHANNEL` to `CHANNELS` and `LEDGER_MSP_ID` to `MSP_ID` + ## [24.0.0] - 2023-10-16 ### Added diff --git a/charts/substra-backend/Chart.yaml b/charts/substra-backend/Chart.yaml index 4a25510c9..5854a2767 100644 --- a/charts/substra-backend/Chart.yaml +++ b/charts/substra-backend/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: substra-backend home: https://github.com/Substra -version: 24.0.0 +version: 24.0.1 appVersion: 0.42.2 kubeVersion: ">= 1.19.0-0" description: Main package for Substra diff --git a/charts/substra-backend/templates/configmap-orchestrator.yaml b/charts/substra-backend/templates/configmap-orchestrator.yaml index ebdd1e26f..d16c27fdf 100644 --- a/charts/substra-backend/templates/configmap-orchestrator.yaml +++ b/charts/substra-backend/templates/configmap-orchestrator.yaml @@ -15,6 +15,6 @@ data: ORCHESTRATOR_TLS_CLIENT_KEY_PATH: "/var/substra/orchestrator/tls/client/tls.key" # Organization identity - LEDGER_MSP_ID: {{ .Values.orchestrator.mspID | quote }} + MSP_ID: {{ .Values.orchestrator.mspID | quote }} # Orchestrator channels configuration - LEDGER_CHANNELS: {{ .Values.orchestrator.channels | toJson | quote }} + CHANNELS: {{ .Values.orchestrator.channels | toJson | quote }} diff --git a/docs/settings.md b/docs/settings.md index 684253923..ea9ea0fde 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -141,8 +141,8 @@ Accepted true values for `bool` are: `1`, `ON`, `On`, `on`, `T`, `t`, `TRUE`, `T | Type | Setting | Default value | Comment | |------|---------|---------------|---------| -| json | `LEDGER_CHANNELS` | `[]` | | -| string | `LEDGER_MSP_ID` | nil | | +| json | `CHANNELS` | `[]` | | +| string | `MSP_ID` | nil | | ## Worker event app settings