Skip to content

Commit

Permalink
Merge branch 'main' into pitch/connect-renkulab-and-openbis-datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius authored Sep 17, 2024
2 parents 75c794f + 4c89c4b commit 0bb92b6
Show file tree
Hide file tree
Showing 25 changed files with 776 additions and 620 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
extra-values: ${{ steps.deploy-comment.outputs.extra-values}}
steps:
- id: deploy-comment
uses: SwissDataScienceCenter/renku-actions/check-pr-description@v1.12.2
uses: SwissDataScienceCenter/renku-actions/check-pr-description@v1.12.3
with:
string: /deploy
pr_ref: ${{ github.event.number }}
Expand All @@ -46,22 +46,22 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Find deplyoment url
uses: peter-evans/find-comment@v1
uses: peter-evans/find-comment@v3
id: deploymentUrlMessage
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "RenkuBot"
body-includes: "You can access the deployment of this PR at"
- name: Create comment deployment url
if: steps.deploymentUrlMessage.outputs.comment-id == 0
uses: peter-evans/create-or-update-comment@v1
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.RENKUBOT_GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
You can access the deployment of this PR at https://renku-ci-ds-${{ github.event.number }}.dev.renku.ch
- name: Build and deploy
uses: SwissDataScienceCenter/renku-actions/deploy-renku@v1.12.2
uses: SwissDataScienceCenter/renku-actions/deploy-renku@v1.12.3
env:
RANCHER_PROJECT_ID: ${{ secrets.CI_RANCHER_PROJECT }}
DOCKER_PASSWORD: ${{ secrets.RENKU_DOCKER_PASSWORD }}
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
if: github.event.action != 'closed' && needs.check-deploy.outputs.pr-contains-string == 'true' && needs.check-deploy.outputs.test-enabled == 'true'
runs-on: ubuntu-22.04
steps:
- uses: SwissDataScienceCenter/renku-actions/test-renku@v1.12.2
- uses: SwissDataScienceCenter/renku-actions/test-renku@v1.12.3
with:
kubeconfig: ${{ secrets.RENKUBOT_DEV_KUBECONFIG }}
renku-release: renku-ci-ds-${{ github.event.number }}
Expand All @@ -118,7 +118,7 @@ jobs:
steps:
- name: Extract Renku repository reference
run: echo "RENKU_REFERENCE=`echo '${{ needs.check-deploy.outputs.renku }}' | cut -d'@' -f2`" >> $GITHUB_ENV
- uses: SwissDataScienceCenter/renku-actions/test-renku-cypress@v1.12.2
- uses: SwissDataScienceCenter/renku-actions/test-renku-cypress@v1.12.3
with:
e2e-target: ${{ matrix.tests }}
renku-reference: ${{ env.RENKU_REFERENCE }}
Expand All @@ -131,22 +131,22 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Find deplyoment url
uses: peter-evans/find-comment@v1
uses: peter-evans/find-comment@v3
id: deploymentUrlMessage
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "RenkuBot"
body-includes: "Tearing down the temporary RenkuLab deplyoment"
- name: Create comment deployment url
if: steps.deploymentUrlMessage.outputs.comment-id == 0
uses: peter-evans/create-or-update-comment@v1
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.RENKUBOT_GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Tearing down the temporary RenkuLab deplyoment for this PR.
- name: renku teardown
uses: SwissDataScienceCenter/renku-actions/cleanup-renku-ci-deployments@v1.12.2
uses: SwissDataScienceCenter/renku-actions/cleanup-renku-ci-deployments@v1.12.3
env:
HELM_RELEASE_REGEX: "^renku-ci-ds-${{ github.event.number }}$"
GITLAB_TOKEN: ${{ secrets.DEV_GITLAB_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:
uses: actions/checkout@v4
- name: Docker meta data services
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
Expand Down Expand Up @@ -240,7 +240,7 @@ jobs:
cache-to: type=registry,ref=renku/renku-data-service:buildcache,mode=max
- name: Docker meta background jobs
id: meta-background-jobs
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
Expand All @@ -265,7 +265,7 @@ jobs:
cache-to: type=registry,ref=renku/data-service-background-jobs:buildcache,mode=max
- name: Docker meta secrets
id: meta-secrets-storage
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
Expand Down
6 changes: 3 additions & 3 deletions components/renku_data_services/app_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from renku_data_services.users.db import UserRepo as KcUserRepo
from renku_data_services.users.dummy_kc_api import DummyKeycloakAPI
from renku_data_services.users.kc_api import IKeycloakAPI, KeycloakAPI
from renku_data_services.users.models import UserInfo
from renku_data_services.users.models import UnsavedUserInfo
from renku_data_services.utils.core import merge_api_specs, oidc_discovery

default_resource_pool = models.ResourcePool(
Expand Down Expand Up @@ -436,8 +436,8 @@ def from_env(cls, prefix: str = "") -> "Config":
user_store = DummyUserStore(user_always_exists=user_always_exists)
gitlab_client = DummyGitlabAPI()
dummy_users = [
UserInfo("user1", "user1", "doe", "user1@doe.com"),
UserInfo("user2", "user2", "doe", "user2@doe.com"),
UnsavedUserInfo(id="user1", first_name="user1", last_name="doe", email="user1@doe.com"),
UnsavedUserInfo(id="user2", first_name="user2", last_name="doe", email="user2@doe.com"),
]
kc_api = DummyKeycloakAPI(users=[i._to_keycloak_dict() for i in dummy_users])
redis = RedisConfig.fake()
Expand Down
10 changes: 5 additions & 5 deletions components/renku_data_services/authz/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from renku_data_services.errors import errors
from renku_data_services.namespace.models import Group, GroupUpdate, Namespace, NamespaceKind, NamespaceUpdate
from renku_data_services.project.models import Project, ProjectUpdate
from renku_data_services.users.models import UserWithNamespace, UserWithNamespaceUpdate
from renku_data_services.users.models import UserInfo, UserInfoUpdate

_P = ParamSpec("_P")

Expand All @@ -51,7 +51,7 @@ def authz(self) -> "Authz":

_AuthzChangeFuncResult = TypeVar(
"_AuthzChangeFuncResult",
bound=Project | ProjectUpdate | Group | UserWithNamespaceUpdate | list[UserWithNamespace] | None,
bound=Project | ProjectUpdate | Group | UserInfoUpdate | list[UserInfo] | None,
)
_T = TypeVar("_T")
_WithAuthz = TypeVar("_WithAuthz", bound=WithAuthz)
Expand Down Expand Up @@ -493,14 +493,14 @@ async def _get_authz_change(
case AuthzOperation.delete, ResourceType.group if result is None:
# NOTE: This means that the group does not exist in the first place so nothing was deleted
pass
case AuthzOperation.update_or_insert, ResourceType.user if isinstance(result, UserWithNamespaceUpdate):
case AuthzOperation.update_or_insert, ResourceType.user if isinstance(result, UserInfoUpdate):
if result.old is None:
authz_change = db_repo.authz._add_user_namespace(result.new.namespace)
case AuthzOperation.insert_many, ResourceType.user_namespace if isinstance(result, list):
for res in result:
if not isinstance(res, UserWithNamespace):
if not isinstance(res, UserInfo):
raise errors.ProgrammingError(
message="Expected list of UserWithNamespace when generating authorization "
message="Expected list of UserInfo when generating authorization "
f"database updates for inserting namespaces but found {type(res)}"
)
authz_change.extend(db_repo.authz._add_user_namespace(res.namespace))
Expand Down
22 changes: 20 additions & 2 deletions components/renku_data_services/base_models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unicodedata
from dataclasses import dataclass, field
from enum import Enum, StrEnum
from typing import ClassVar, Optional, Protocol
from typing import ClassVar, Optional, Protocol, Self

from sanic import Request

Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(self, value: str) -> None:
object.__setattr__(self, "value", value.lower())

@classmethod
def from_name(cls, name: str) -> "Slug":
def from_name(cls, name: str) -> Self:
"""Takes a name with any amount of invalid characters and transforms it in a valid slug."""
lower_case = name.lower()
no_space = re.sub(r"\s+", "-", lower_case)
Expand All @@ -139,6 +139,24 @@ def from_name(cls, name: str) -> "Slug":
)
return cls(no_dot_git_or_dot_atom_at_end)

@classmethod
def from_user(cls, email: str | None, first_name: str | None, last_name: str | None, keycloak_id: str) -> Self:
"""Create a slug from a user."""
if email:
slug = email.split("@")[0]
elif first_name and last_name:
slug = first_name + "-" + last_name
elif last_name:
slug = last_name
elif first_name:
slug = first_name
else:
slug = "user_" + keycloak_id
# The length limit is 99 but leave some space for modifications that may be added down the line
# to filter out invalid characters or to generate a unique name
slug = slug[:80]
return cls.from_name(slug)

def __true_div__(self, other: "Slug") -> str:
"""Joins two slugs into a path fraction without dashes at the beginning or end."""
if type(self) is not type(other):
Expand Down
6 changes: 3 additions & 3 deletions components/renku_data_services/crc/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from renku_data_services.crc.db import ResourcePoolRepository, UserRepository
from renku_data_services.k8s.quota import QuotaRepository
from renku_data_services.users.db import UserRepo as KcUserRepo
from renku_data_services.users.models import UserWithNamespace
from renku_data_services.users.models import UserInfo


@dataclass(kw_only=True)
Expand Down Expand Up @@ -183,10 +183,10 @@ async def _put_post(
self, api_user: base_models.APIUser, resource_pool_id: int, body: apispec.PoolUsersWithId, post: bool = True
) -> HTTPResponse:
user_ids_to_add = set([user.id for user in body.root])
users_checks: list[UserWithNamespace | None] = await asyncio.gather(
users_checks: list[UserInfo | None] = await asyncio.gather(
*[self.kc_user_repo.get_user(id=id) for id in user_ids_to_add]
)
existing_user_ids = set([user.user.id for user in users_checks if user is not None])
existing_user_ids = set([user.id for user in users_checks if user is not None])
if existing_user_ids != user_ids_to_add:
missing_ids = user_ids_to_add.difference(existing_user_ids)
raise errors.MissingResourceError(message=f"The users with IDs {missing_ids} cannot be found")
Expand Down
42 changes: 21 additions & 21 deletions components/renku_data_services/message_queue/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,38 @@ def to_events(
class _UserEventConverter:
@staticmethod
def to_events(
user: user_models.UserInfo | user_models.UserWithNamespace | user_models.UserWithNamespaceUpdate,
user: user_models.UserInfo | user_models.UserInfoUpdate | str,
event_type: type[AvroModel] | type[events.AmbiguousEvent],
) -> list[Event]:
match event_type:
case v2.UserAdded | events.InsertUserNamespace:
user = cast(user_models.UserWithNamespace, user)
user = cast(user_models.UserInfo, user)
return [
_make_event(
"user.added",
v2.UserAdded(
id=user.user.id,
firstName=user.user.first_name,
lastName=user.user.last_name,
email=user.user.email,
id=user.id,
firstName=user.first_name,
lastName=user.last_name,
email=user.email,
namespace=user.namespace.slug,
),
)
]
case v2.UserRemoved:
user = cast(user_models.UserInfo, user)
return [_make_event("user.removed", v2.UserRemoved(id=user.id))]
user_id = cast(str, user)
return [_make_event("user.removed", v2.UserRemoved(id=user_id))]
case events.UpdateOrInsertUser:
user = cast(user_models.UserWithNamespaceUpdate, user)
user = cast(user_models.UserInfoUpdate, user)
if user.old is None:
return [
_make_event(
"user.added",
v2.UserAdded(
id=user.new.user.id,
firstName=user.new.user.first_name,
lastName=user.new.user.last_name,
email=user.new.user.email,
id=user.new.id,
firstName=user.new.first_name,
lastName=user.new.last_name,
email=user.new.email,
namespace=user.new.namespace.slug,
),
)
Expand All @@ -135,10 +135,10 @@ def to_events(
_make_event(
"user.updated",
v2.UserUpdated(
id=user.new.user.id,
firstName=user.new.user.first_name,
lastName=user.new.user.last_name,
email=user.new.user.email,
id=user.new.id,
firstName=user.new.first_name,
lastName=user.new.last_name,
email=user.new.email,
namespace=user.new.namespace.slug,
),
)
Expand Down Expand Up @@ -328,16 +328,16 @@ def to_events(input: _T, event_type: type[AvroModel] | type[events.AmbiguousEven
group_authz = cast(list[authz_models.MembershipChange], input)
return _GroupAuthzEventConverter.to_events(group_authz)
case v2.UserAdded:
user_with_namespace = cast(user_models.UserWithNamespace, input)
user_with_namespace = cast(user_models.UserInfo, input)
return _UserEventConverter.to_events(user_with_namespace, event_type)
case v2.UserRemoved:
user_info = cast(user_models.UserInfo, input)
user_info = cast(str, input)
return _UserEventConverter.to_events(user_info, event_type)
case events.UpdateOrInsertUser:
user_with_namespace_update = cast(user_models.UserWithNamespaceUpdate, input)
user_with_namespace_update = cast(user_models.UserInfoUpdate, input)
return _UserEventConverter.to_events(user_with_namespace_update, event_type)
case events.InsertUserNamespace:
user_namespaces = cast(list[user_models.UserWithNamespace], input)
user_namespaces = cast(list[user_models.UserInfo], input)
output: list[Event] = []
for namespace in user_namespaces:
output.extend(_UserEventConverter.to_events(namespace, event_type))
Expand Down
Loading

0 comments on commit 0bb92b6

Please sign in to comment.