Skip to content

Commit

Permalink
chore: remove LEDGER in naming (#794)
Browse files Browse the repository at this point in the history
Signed-off-by: ThibaultFy <[email protected]>
  • Loading branch information
ThibaultFy authored Dec 18, 2023
1 parent 593b32e commit fdfd1f7
Show file tree
Hide file tree
Showing 41 changed files with 82 additions and 75 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion backend/api/events/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion backend/api/serializers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_compute_plan_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_computeplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down
4 changes: 2 additions & 2 deletions backend/api/tests/views/test_views_computetask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions backend/api/tests/views/test_views_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_datasample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 12 additions & 12 deletions backend/api/tests/views/test_views_failed_asset_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)


Expand All @@ -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
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"

Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions backend/api/tests/views/test_views_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_newsfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/api/tests/views/test_views_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions backend/api/tests/views/test_views_task_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions backend/api/views/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions backend/backend/settings/deps/ledger.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 2 additions & 2 deletions backend/backend/settings/localdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions backend/backend/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}
2 changes: 1 addition & 1 deletion backend/backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions backend/libs/health_check_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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}"')
2 changes: 1 addition & 1 deletion backend/orchestrator/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fdfd1f7

Please sign in to comment.