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

DataBiosphere / azul / 19543508912

20 Nov 2025 04:13PM UTC coverage: 85.407% (-0.002%) from 85.409%
19543508912

push

github

hannes-ucsc
[u a] Configure mirroring per source (#7066, PR #7304)

19670 of 23031 relevant lines covered (85.41%)

0.85 hits per line

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

68.18
src/azul/service/source_controller.py
1
import logging
1✔
2

3
from chalice import (
1✔
4
    TooManyRequestsError,
5
    UnauthorizedError,
6
)
7

8
from azul import (
1✔
9
    CatalogName,
10
    cached_property,
11
)
12
from azul.auth import (
1✔
13
    Authentication,
14
)
15
from azul.chalice import (
1✔
16
    AppController,
17
    BadGatewayError,
18
    ServiceUnavailableError,
19
)
20
from azul.http import (
1✔
21
    LimitedTimeoutException,
22
    TooManyRequestsException,
23
)
24
from azul.service import (
1✔
25
    Filters,
26
)
27
from azul.service.source_service import (
1✔
28
    SourceService,
29
)
30
from azul.types import (
1✔
31
    JSONs,
32
)
33

34
log = logging.getLogger(__name__)
1✔
35

36

37
class SourceController(AppController):
1✔
38

39
    @cached_property
1✔
40
    def _source_service(self) -> SourceService:
1✔
41
        return SourceService()
1✔
42

43
    def list_sources(self,
1✔
44
                     catalog: CatalogName,
45
                     authentication: Authentication | None
46
                     ) -> JSONs:
47
        try:
1✔
48
            sources = self._source_service.list_sources(catalog, authentication)
1✔
49
        except PermissionError:
×
50
            raise UnauthorizedError
×
51
        except LimitedTimeoutException as e:
×
52
            raise ServiceUnavailableError(*e.args)
×
53
        except TooManyRequestsException as e:
×
54
            raise TooManyRequestsError(*e.args)
×
55
        else:
56
            authoritative_source_ids = {source.id for source in sources}
1✔
57
            cached_source_ids = self._list_source_ids(catalog, authentication)
1✔
58
            # For optimized performance, the cache may include source IDs that
59
            # are accessible but are not configured for indexing. Therefore, we
60
            # expect the set of actual sources to be a subset of the cached
61
            # sources.
62
            diff = authoritative_source_ids - cached_source_ids
1✔
63
            if diff:
1✔
64
                log.debug(diff)
×
65
                raise BadGatewayError('Inconsistent response from repository')
×
66
            return [
1✔
67
                {'sourceId': source.id, 'sourceSpec': str(source.spec)}
68
                for source in sources
69
            ]
70

71
    def _list_source_ids(self,
1✔
72
                         catalog: CatalogName,
73
                         authentication: Authentication | None
74
                         ) -> set[str]:
75
        try:
1✔
76
            source_ids = self._source_service.list_source_ids(catalog, authentication)
1✔
77
        except PermissionError:
×
78
            raise UnauthorizedError
×
79
        except LimitedTimeoutException as e:
×
80
            raise ServiceUnavailableError(*e.args)
×
81
        except TooManyRequestsException as e:
×
82
            raise TooManyRequestsError(*e.args)
×
83
        else:
84
            return source_ids
1✔
85

86
    def _list_public_source_ids(self, catalog: CatalogName) -> set[str]:
1✔
87
        return self._list_source_ids(catalog, authentication=None)
1✔
88

89
    def get_filters(self,
1✔
90
                    catalog: CatalogName,
91
                    authentication: Authentication | None,
92
                    filters: str | None = None
93
                    ) -> Filters:
94
        return Filters(explicit=self._parse_filters(filters),
1✔
95
                       source_ids=self._list_source_ids(catalog, authentication))
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

© 2026 Coveralls, Inc