• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SwissDataScienceCenter / renku-data-services / 19035163548

03 Nov 2025 12:46PM UTC coverage: 86.797% (-0.02%) from 86.812%
19035163548

Pull #1094

github

web-flow
Merge 1a36ce7e6 into d7d3167bd
Pull Request #1094: feat: add user alerts

22739 of 26198 relevant lines covered (86.8%)

1.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.38
/components/renku_data_services/connected_services/core.py
1
"""Business logic for connected services."""
2

3
from urllib.parse import urlparse
2✔
4

5
from renku_data_services.connected_services import apispec, models
2✔
6
from renku_data_services.errors import errors
2✔
7

8

9
def validate_oauth2_client_patch(patch: apispec.ProviderPatch) -> models.OAuth2ClientPatch:
2✔
10
    """Validate the update to a OAuth2 Client."""
11
    if patch.image_registry_url:
2✔
12
        validate_image_registry_url(patch.image_registry_url)
2✔
13
    kind = models.ProviderKind(patch.kind.value) if patch.kind else None
2✔
14
    if kind == models.ProviderKind.generic_oidc:
2✔
15
        if not patch.oidc_issuer_url:
1✔
16
            raise errors.ValidationError(
×
17
                message=f"The field 'oidc_issuer_url' is required when kind is set to {models.ProviderKind.generic_oidc.value}.",  # noqa E501
18
                quiet=True,
19
            )
20
        validate_oidc_issuer_url(patch.oidc_issuer_url)
1✔
21
    return models.OAuth2ClientPatch(
2✔
22
        kind=kind,
23
        app_slug=patch.app_slug,
24
        client_id=patch.client_id,
25
        client_secret=patch.client_secret,
26
        display_name=patch.display_name,
27
        scope=patch.scope,
28
        url=patch.url,
29
        use_pkce=patch.use_pkce,
30
        image_registry_url=patch.image_registry_url,
31
        oidc_issuer_url=patch.oidc_issuer_url,
32
    )
33

34

35
def validate_unsaved_oauth2_client(clnt: apispec.ProviderPost) -> models.UnsavedOAuth2Client:
2✔
36
    """Validate the the creation of a new OAuth2 Client."""
37
    if clnt.image_registry_url is not None:
2✔
38
        validate_image_registry_url(clnt.image_registry_url)
2✔
39
    kind = models.ProviderKind(clnt.kind.value)
2✔
40
    if clnt.oidc_issuer_url and kind != models.ProviderKind.generic_oidc:
2✔
41
        raise errors.ValidationError(
1✔
42
            message=f"The field 'oidc_issuer_url' can only be set when kind is set to {models.ProviderKind.generic_oidc.value}.",  # noqa E501
43
            quiet=True,
44
        )
45
    if kind == models.ProviderKind.generic_oidc:
2✔
46
        if not clnt.oidc_issuer_url:
×
47
            raise errors.ValidationError(
×
48
                message=f"The field 'oidc_issuer_url' is required when kind is set to {models.ProviderKind.generic_oidc.value}.",  # noqa E501
49
                quiet=True,
50
            )
51
        validate_oidc_issuer_url(clnt.oidc_issuer_url)
×
52
    return models.UnsavedOAuth2Client(
2✔
53
        id=clnt.id,
54
        kind=kind,
55
        app_slug=clnt.app_slug or "",
56
        client_id=clnt.client_id,
57
        client_secret=clnt.client_secret,
58
        display_name=clnt.display_name,
59
        scope=clnt.scope,
60
        url=clnt.url,
61
        use_pkce=clnt.use_pkce or False,
62
        image_registry_url=clnt.image_registry_url,
63
        oidc_issuer_url=clnt.oidc_issuer_url,
64
    )
65

66

67
def validate_image_registry_url(url: str) -> None:
2✔
68
    """Validate an image registry url."""
69
    parsed = urlparse(url)
2✔
70
    if not parsed.netloc:
2✔
71
        raise errors.ValidationError(
×
72
            message=f"The image registry url {url} is not valid, expected a valid url starting with the scheme.",
73
            quiet=True,
74
        )
75
    accepted_schemes = ["https"]
2✔
76
    if parsed.scheme not in accepted_schemes:
2✔
77
        raise errors.ValidationError(
×
78
            message=f"The scheme for the image registry url {url} is not valid, expected one of {accepted_schemes}",
79
            quiet=True,
80
        )
81

82

83
def validate_oidc_issuer_url(url: str) -> None:
2✔
84
    """Validate an OpenID Connect Issuer URL."""
85
    parsed = urlparse(url)
1✔
86
    if not parsed.netloc:
1✔
87
        raise errors.ValidationError(
×
88
            message=f"The host for the 'oidc_issuer_url' {url} is not valid, expected a non-empty value.",
89
            quiet=True,
90
        )
91
    accepted_schemes = ["https"]
1✔
92
    if parsed.scheme not in accepted_schemes:
1✔
93
        raise errors.ValidationError(
×
94
            message=f"The scheme for the 'oidc_issuer_url' {url} is not valid, expected one of {accepted_schemes}",
95
            quiet=True,
96
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc