GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#341)
by
unknown
44s
created

CoturnHMAC   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B fetch_token() 0 26 3
A __init__() 0 3 1
1
"""
2
Coturn static auth api
3
4
Creates ice_server record with temporary credentials computed from coturn static-auth-secret
5
6
http://stackoverflow.com/a/35767224
7
"""
8
9
import time
10
import hmac
11
import base64
12
from hashlib import sha1
13
from server.config import COTURN_HOSTS, COTURN_KEYS, TWILIO_TTL
14
15
class CoturnHMAC:
16
    def __init__(self, coturn_hosts=None, coturn_keys=None):
17
        self.coturn_hosts = coturn_hosts or COTURN_HOSTS
18
        self.coturn_keys = coturn_keys or COTURN_KEYS
19
20
    def fetch_token(self, username='faf-user', ttl=None):
21
        servers = []
22
23
        ttl = ttl or TWILIO_TTL
24
        if ttl is not None:
25
            ttl = int(ttl)
26
        else:
27
            ttl = 3600*24
28
29
        # See https://github.com/coturn/coturn/wiki/turnserver#turn-rest-api
30
        # create hmac of coturn_key + timestamp:username
31
        timestamp = int(time.time()) + ttl
32
        token_name = "{}:{}".format(timestamp, username)
33
34
        for coturn_host, coturn_key in zip(self.coturn_hosts, self.coturn_keys):
35
            secret = hmac.new(coturn_key.encode(), str(token_name).encode(), sha1)
36
            auth_token = base64.b64encode(secret.digest()).decode()
37
38
            servers.append(dict(urls=["turn:{}?transport=tcp".format(coturn_host),
39
                                      "turn:{}?transport=udp".format(coturn_host),
40
                                      "stun:{}".format(coturn_host)],
41
                                username=token_name,
42
                                credential=auth_token,
43
                                credentialType="token"))
44
45
        return servers
46