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

uw-it-aca / canvas-sis-provisioner / 6698520699

30 Oct 2023 08:45PM UTC coverage: 56.318% (+0.02%) from 56.295%
6698520699

Pull #911

github-actions

web-flow
Merge branch 'main' into develop
Pull Request #911: Develop

25 of 25 new or added lines in 5 files covered. (100.0%)

4573 of 8120 relevant lines covered (56.32%)

0.56 hits per line

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

36.96
/sis_provisioner/cache.py
1
# Copyright 2023 UW-IT, University of Washington
2
# SPDX-License-Identifier: Apache-2.0
3

4

5
from django.conf import settings
1✔
6
from memcached_clients import RestclientPymemcacheClient
1✔
7
from uw_kws import ENCRYPTION_KEY_URL, ENCRYPTION_CURRENT_KEY_URL
1✔
8
import re
1✔
9

10
ONE_MINUTE = 60
1✔
11
ONE_HOUR = 60 * 60
1✔
12
ONE_DAY = 60 * 60 * 24
1✔
13
ONE_WEEK = 60 * 60 * 24 * 7
1✔
14
ONE_MONTH = 60 * 60 * 24 * 30
1✔
15

16
ALLOWED_CANVAS_LOGIN_USERS = getattr(
1✔
17
    settings, 'ALLOWED_CANVAS_LOGIN_USERS', 'none')
18
ALLOWED_CANVAS_STUDENT_USERS = getattr(
1✔
19
    settings, 'ALLOWED_CANVAS_STUDENT_USERS', 'none')
20
ALLOWED_CANVAS_AFFILIATE_USERS = getattr(
1✔
21
    settings, 'ALLOWED_CANVAS_AFFILIATE_USERS', 'none')
22
ALLOWED_CANVAS_SPONSORED_USERS = getattr(
1✔
23
    settings, 'ALLOWED_CANVAS_SPONSORED_USERS', 'none')
24
NONPERSONAL_NETID_EXCEPTION_GROUP = getattr(
1✔
25
    settings, 'NONPERSONAL_NETID_EXCEPTION_GROUP', 'none')
26

27

28
class RestClientsCache(RestclientPymemcacheClient):
1✔
29
    def get_cache_expiration_time(self, service, url, status=200):
1✔
30
        if 'sws' == service:
×
31
            if re.match(r'^/student/v\d/course/', url):
×
32
                return ONE_MINUTE * 5
×
33
            if re.match(r'^/student/v\d/term/', url):
×
34
                return ONE_HOUR * 4
×
35
            if re.match(
×
36
                r'^/student/v\d/(?:campus|college|department|curriculum)',
37
                    url):
38
                return ONE_HOUR * 4
×
39

40
        if 'pws' == service:
×
41
            return ONE_HOUR
×
42

43
        if 'kws' == service:
×
44
            if re.search(r'{}'.format(
×
45
                    ENCRYPTION_KEY_URL.format(r'[\-\da-fA-F]{36}')), url):
46
                return ONE_MONTH
×
47
            if re.search(r'{}'.format(
×
48
                    ENCRYPTION_CURRENT_KEY_URL.format(r'[\-\da-zA-Z]+')), url):
49
                return ONE_WEEK
×
50

51
        if 'gws' == service:
×
52
            if re.match(r'^/group_sws/v\d/group/u_somalt_', url):
×
53
                return ONE_HOUR
×
54
            if re.match(r'^/group_sws/v\d/group/{}/effective_member/'.format(
×
55
                    ALLOWED_CANVAS_LOGIN_USERS), url):
56
                return ONE_HOUR
×
57
            if re.match(r'^/group_sws/v\d/group/(?:{}|{}|{})/member/'.format(
×
58
                    ALLOWED_CANVAS_STUDENT_USERS,
59
                    ALLOWED_CANVAS_AFFILIATE_USERS,
60
                    ALLOWED_CANVAS_SPONSORED_USERS), url):
61
                return ONE_HOUR * 2
×
62
            if re.match(r'^/group_sws/v\d/group/{}/member/'.format(
×
63
                    NONPERSONAL_NETID_EXCEPTION_GROUP), url):
64
                return ONE_HOUR * 8
×
65

66
        if 'canvas' == service:
×
67
            if re.match(r'^/api/v\d/accounts/sis_account_id:', url):
×
68
                return ONE_HOUR * 10
×
69
            if re.match(r'^/api/v\d/accounts/\d+/roles', url):
×
70
                return ONE_MONTH
×
71

72
    def delete_cached_kws_current_key(self, resource_type):
1✔
73
        self.deleteCache('kws', ENCRYPTION_CURRENT_KEY_URL.format(
×
74
            resource_type))
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