Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions gateway/scripts/generate-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ set -Eeuo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
GATEWAY_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd)
SDS_ROOT=$(cd "${GATEWAY_ROOT}/.." && pwd)
FEDERATION_ROOT=$(cd "${SDS_ROOT}/federation" && pwd)
FEDERATION_ROOT=""
if [[ -d "${SDS_ROOT}/federation" ]]; then
FEDERATION_ROOT=$(cd "${SDS_ROOT}/federation" && pwd)
fi
SFS_ROOT=$(cd "${SDS_ROOT}/seaweedfs" && pwd)
EXAMPLE_DIR="${GATEWAY_ROOT}/.envs/example"
FEDERATION_SHARED_TEMPLATE="${SDS_ROOT}/federation-shared.example.env"
Expand Down Expand Up @@ -271,8 +274,10 @@ function set_permissions() {
env_dirs=(
"${GATEWAY_ROOT}/.envs"
"${SFS_ROOT}/.envs"
"${FEDERATION_ROOT}/.envs"
)
if [[ -n "${FEDERATION_ROOT}" ]]; then
env_dirs+=("${FEDERATION_ROOT}/.envs")
fi
for dir in "${env_dirs[@]}"; do
if [ -d "${dir}" ]; then
find "${dir}" -type f -name "*.env" -exec chmod --changes 600 {} \;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def federation_site_name() -> str:

def capture_in_published_dataset(capture: Capture) -> bool:
exportable_datasets = get_capture_datasets(
capture,
include_deleted=False
capture, include_deleted=False
).federation_exportable()
return exportable_datasets.exists()

Expand All @@ -48,8 +47,7 @@ def capture_in_other_published_datasets(
exclude_dataset_id: UUID,
) -> bool:
exportable_datasets = get_capture_datasets(
capture,
include_deleted=False
capture, include_deleted=False
).federation_exportable()
return exportable_datasets.exclude(uuid=exclude_dataset_id).exists()

Expand Down Expand Up @@ -100,7 +98,8 @@ def get_federated_export_doc_by_uuid(
return None
except os_exceptions.OpenSearchException as exc:
log.warning(
f"Federation fed doc lookup failed for {asset_type.value} {asset_uuid}: {exc}",
f"Federation fed doc lookup failed for {asset_type.value} "
f"{asset_uuid}: {exc}",
)
return None
source = response.get("_source")
Expand Down
2 changes: 1 addition & 1 deletion gateway/sds_gateway/api_methods/federation/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from sds_gateway.api_methods.models import Capture
from sds_gateway.api_methods.models import Dataset
from sds_gateway.api_methods.models import ItemType
from sds_gateway.api_methods.utils.relationship_utils import get_dataset_captures
from sds_gateway.api_methods.utils.opensearch_client import get_opensearch_client
from sds_gateway.api_methods.utils.relationship_utils import get_dataset_captures

if TYPE_CHECKING:
from collections.abc import Iterable
Expand Down
11 changes: 5 additions & 6 deletions gateway/sds_gateway/api_methods/utils/asset_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from django.db.models import Q
from pydantic import UUID4

from sds_gateway.api_methods.federation.reindex import (
reindex_captures_after_dataset_unlink,
)
from sds_gateway.api_methods.models import Capture
from sds_gateway.api_methods.models import Dataset
from sds_gateway.api_methods.models import File
Expand All @@ -13,10 +16,6 @@
from sds_gateway.api_methods.models import user_has_access_to_item
from sds_gateway.api_methods.utils import relationship_utils

from sds_gateway.api_methods.federation.reindex import (
reindex_captures_after_dataset_unlink,
)

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -402,8 +401,8 @@ def disconnect_captures_from_dataset(dataset: Dataset) -> None:
Capture.datasets.through.objects.filter(dataset_id=dataset.pk).delete()
# TODO: remove FK after contraction
Capture.objects.filter(dataset=dataset).update(dataset=None)
reindex_captures_after_dataset_unlink(capture_pks)

reindex_captures_after_dataset_unlink(capture_pks)


def disconnect_assets(item: Dataset | Capture, item_type: ItemType) -> None:
Expand Down
10 changes: 7 additions & 3 deletions gateway/sds_gateway/users/api/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from collections.abc import Callable
from enum import StrEnum
from typing import cast

from django.conf import settings
from django.db.models import QuerySet
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from drf_spectacular.utils import extend_schema
from loguru import logger as log
from rest_framework import status
from rest_framework.authentication import TokenAuthentication
from rest_framework.decorators import action
Expand All @@ -25,6 +25,7 @@

from .serializers import UserSerializer


class ServiceUserSetting(StrEnum):
SVI_SERVER_EMAIL = "SVI_SERVER_EMAIL"
FEDERATION_SYNC_USER_EMAIL = "FEDERATION_SYNC_USER_EMAIL"
Expand Down Expand Up @@ -65,7 +66,7 @@ class BackendServiceMintAPIKeyView(APIView):

def get(self, request: Request) -> Response:
allowed_email = getattr(settings, self.service_user_email_setting)

if not request.user.is_authenticated:
return Response(
{"error": "The requesting user could not be identified."},
Expand All @@ -80,7 +81,10 @@ def get(self, request: Request) -> Response:
)

email_to_mint = ""
if self.service_user_email_setting == ServiceUserSetting.FEDERATION_SYNC_USER_EMAIL:
if (
self.service_user_email_setting
== ServiceUserSetting.FEDERATION_SYNC_USER_EMAIL
):
email_to_mint = request_email
elif self.service_user_email_setting == ServiceUserSetting.SVI_SERVER_EMAIL:
email_to_mint = request.query_params.get("email")
Expand Down