forked from codedust/fitconnect-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_config.py
65 lines (57 loc) · 2.51 KB
/
read_config.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from fitconnect import Environment
from os import path
from strictyaml import load, Map, Str, Int, Seq, YAMLError, Optional
from strictyaml import Enum as YAMLEnum
import json
'''Read data for a sender client from the specified configuration file,
see the sender.yaml.example for required details.'''
def read_config_sender(config_file):
config_schema = Map({
"destination_id": Str(),
"leika_key": Str(),
"sdk": Map({
"environment": YAMLEnum([e.name for e in Environment]), # change to native Enum when strictyaml supports it: https://github.com/crdoconnor/strictyaml/issues/73
"client_id": Str(),
"client_secret": Str(),
}),
})
# parse yaml config
with open(config_file) as file:
config = load(file.read(), config_schema, label=config_file).data
return config
'''Read data for a subscriber client from the specified configuration file
and its private key, see the subscriber.yaml.example for required details.'''
def read_config_subscriber(config_file):
config_schema = Map({
"destination_id": Str(),
"private_key_decryption_file": Str(),
"sdk": Map({
"environment": YAMLEnum([e.name for e in Environment]), # change to native Enum when strictyaml supports it: https://github.com/crdoconnor/strictyaml/issues/73
"client_id": Str(),
"client_secret": Str(),
}),
})
# parse yaml config
with open(config_file) as file:
config = load(file.read(), config_schema, label=config_file).data
# load private key for decryption
with open(path.join(path.dirname(config_file), config['private_key_decryption_file'])) as private_key_file:
config['private_key_decryption'] = json.load(private_key_file)
return config
'''Read data for sender clients to verify if a destination exists. At least one sender
client configuration is required. For specific deteils see the destination.yaml.example'''
def read_config_multi_environment(config_file):
config_schema = Map({
"environments": Seq(
Map({
# change to native Enum when strictyaml supports it: https://github.com/crdoconnor/strictyaml/issues/73
"environment": YAMLEnum([e.name for e in Environment]),
"client_id": Str(),
"client_secret": Str(),
}),
),
})
# parse yaml config
with open(config_file) as file:
config = load(file.read(), config_schema, label=config_file).data
return config