-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathoutcall.py
More file actions
38 lines (26 loc) · 1.01 KB
/
outcall.py
File metadata and controls
38 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright 2016-2023 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later
import random
import string
from . import confd
from ..config import CONTEXT
def generate_outcall(**parameters):
parameters.setdefault('label', generate_label())
parameters.setdefault('context', CONTEXT)
return add_outcall(**parameters)
def add_outcall(wazo_tenant=None, **parameters):
response = confd.outcalls.post(parameters, wazo_tenant=wazo_tenant)
return response.item
def delete_outcall(outcall_id, check=False, **params):
response = confd.outcalls(outcall_id).delete()
if check:
response.assert_ok()
def generate_label():
response = confd.outcalls.get()
labels = set(d['label'] for d in response.items)
return _random_label(labels)
def _random_label(labels):
label = ''.join(random.choice(string.ascii_lowercase) for i in range(10))
while label in labels:
label = ''.join(random.choice(string.ascii_lowercase) for i in range(10))
return label