Skip to content

Commit ee36417

Browse files
committed
feat(CONFIG): support multiple integrations
1 parent 6336308 commit ee36417

24 files changed

+488
-269
lines changed

README.md

+37-23
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,46 @@ Create a configuration json file that contains the following:
9191

9292
```json
9393
{
94-
"AWS_ACCESS_KEY_ID": "... AWS key with write access to buckets ...",
95-
"AWS_SECRET_ACCESS_KEY": "... AWS secret key with write access buckets ...",
96-
"AWS_S3_BUCKETS": {
94+
"ARCHIVAL": {
95+
"AWS": {
96+
"AWS_ACCESS_KEY_ID": "... AWS key with write access to buckets ...",
97+
"AWS_SECRET_ACCESS_KEY": "... AWS secret key with write access buckets ...",
98+
"AWS_S3_BUCKETS": {
9799
"LOGS": "... s3 logs bucket name ...",
98100
"VIDEOS": "... s3 video bucket name ..."
99-
},
100-
"CONTACT_SWITCHES": [
101-
{
102-
"NAME": "... name and pin-out of a GPIO switch...",
103-
"GPIO": 12
104-
}
105-
],
106-
"LOGZ_IO_CODE": "... logz io's logger code ...",
107-
"SLACK_APP_SIGNING_SECRET": "... secret value from slack to validate bot messages ...",
108-
"SLACK_APP_TOKEN": "... token from slack to allow app to use websockets ...",
109-
"SLACK_BOT_TOKEN": "... token from slack...",
110-
"SLACK_CHANNEL": "... proper name of slack channel ...",
111-
"SLACK_CHANNEL_ID": ".. slack's ID for the channel ...",
112-
"TEMPERATURE_SENSORS": {
113-
"DHT11": [
114-
{
115-
"NAME": "... name and pin-out of a GPIO with a DHT11 connected ...",
116-
"GPIO": 4
117-
}
118-
]
101+
}
102+
}
103+
},
104+
"CHAT": {
105+
"SLACK": {
106+
"SLACK_APP_SIGNING_SECRET": "... secret value from slack to validate bot messages ...",
107+
"SLACK_APP_TOKEN": "... token from slack to allow app to use websockets ...",
108+
"SLACK_BOT_TOKEN": "... token from slack...",
109+
"SLACK_CHANNEL": "... proper name of slack channel ...",
110+
"SLACK_CHANNEL_ID": ".. slack's ID for the channel ..."
119111
}
112+
},
113+
"LOGS": {
114+
"LOGZ_IO": {
115+
"LOGZ_IO_TOKEN": "... logz io's logger token ..."
116+
}
117+
},
118+
"SWITCHES": {
119+
"CONTACT_SWITCHES": [
120+
{
121+
"NAME": "... name and pin-out of a GPIO switch...",
122+
"GPIO": 12
123+
}
124+
]
125+
},
126+
"TEMPERATURE_SENSORS": {
127+
"DHT11": [
128+
{
129+
"NAME": "... name and pin-out of a GPIO with a DHT11 connected ...",
130+
"GPIO": 4
131+
}
132+
]
133+
}
120134
}
121135
```
122136

config.json

+38-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
{
2-
"AWS_ACCESS_KEY_ID": "... AWS key with write access to buckets ...",
3-
"AWS_SECRET_ACCESS_KEY": "... AWS secret key with write access buckets ...",
4-
"AWS_S3_BUCKETS": {
2+
"ARCHIVAL": {
3+
"AWS": {
4+
"AWS_ACCESS_KEY_ID": "... AWS key with write access to buckets ...",
5+
"AWS_SECRET_ACCESS_KEY": "... AWS secret key with write access buckets ...",
6+
"AWS_S3_BUCKETS": {
57
"LOGS": "... s3 logs bucket name ...",
68
"VIDEOS": "... s3 video bucket name ..."
7-
},
8-
"CONTACT_SWITCHES": [
9-
{
10-
"NAME": "... name and pin-out of a GPIO switch...",
11-
"GPIO": 12
12-
}
13-
],
14-
"LOGZ_IO_CODE": "... logz io's logger code ...",
15-
"SLACK_APP_SIGNING_SECRET": "... secret value from slack to validate bot messages ...",
16-
"SLACK_APP_TOKEN": "... token from slack to allow app to use websockets ...",
17-
"SLACK_BOT_TOKEN": "... token from slack...",
18-
"SLACK_CHANNEL": "... proper name of slack channel ...",
19-
"SLACK_CHANNEL_ID": ".. slack's ID for the channel ...",
20-
"TEMPERATURE_SENSORS": {
21-
"DHT11": [
22-
{
23-
"NAME": "... name and pin-out of a GPIO with a DHT11 connected ...",
24-
"GPIO": 4
25-
}
26-
]
9+
}
10+
}
11+
},
12+
"CHAT": {
13+
"SLACK": {
14+
"SLACK_APP_SIGNING_SECRET": "... secret value from slack to validate bot messages ...",
15+
"SLACK_APP_TOKEN": "... token from slack to allow app to use websockets ...",
16+
"SLACK_BOT_TOKEN": "... token from slack...",
17+
"SLACK_CHANNEL": "... proper name of slack channel ...",
18+
"SLACK_CHANNEL_ID": ".. slack's ID for the channel ..."
2719
}
28-
}
20+
},
21+
"LOGS": {
22+
"LOGZ_IO": {
23+
"LOGZ_IO_TOKEN": "... logz io's logger token ..."
24+
}
25+
},
26+
"SWITCHES": {
27+
"CONTACT_SWITCHES": [
28+
{
29+
"NAME": "... name and pin-out of a GPIO switch...",
30+
"GPIO": 12
31+
}
32+
]
33+
},
34+
"TEMPERATURE_SENSORS": {
35+
"DHT11": [
36+
{
37+
"NAME": "... name and pin-out of a GPIO with a DHT11 connected ...",
38+
"GPIO": 4
39+
}
40+
]
41+
}
42+
}

pi_portal/installation/templates/config_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create_context(self) -> Dict[str, Any]:
3939
"""
4040

4141
context = {
42-
"LOGZ_IO_CODE": self.state.user_config["LOGZ_IO_CODE"],
42+
"USER_CONFIG": self.state.user_config,
4343
}
4444

4545
for setting in dir(config):

pi_portal/installation/templates/logzio/filebeat.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ filebeat.inputs:
77
- "{{ LOG_FILE_CRON_SCHEDULER }}*"
88
fields:
99
logzio_codec: json
10-
token: {{ LOGZ_IO_CODE }}
10+
token: "{{ USER_CONFIG['LOGS']['LOGZ_IO']['LOGZ_IO_TOKEN'] }}"
1111
type: pi_portal_cron_json
1212
fields_under_root: true
1313
encoding: utf-8
@@ -18,7 +18,7 @@ filebeat.inputs:
1818
- "{{ LOG_FILE_DOOR_MONITOR }}*"
1919
fields:
2020
logzio_codec: json
21-
token: {{ LOGZ_IO_CODE }}
21+
token: "{{ USER_CONFIG['LOGS']['LOGZ_IO']['LOGZ_IO_TOKEN'] }}"
2222
type: pi_portal_door_json
2323
fields_under_root: true
2424
encoding: utf-8
@@ -30,7 +30,7 @@ filebeat.inputs:
3030
- "{{ LOG_FILE_SLACK_CLIENT }}*"
3131
fields:
3232
logzio_codec: json
33-
token: {{ LOGZ_IO_CODE }}
33+
token: "{{ USER_CONFIG['LOGS']['LOGZ_IO']['LOGZ_IO_TOKEN'] }}"
3434
type: pi_portal_slack_json
3535
fields_under_root: true
3636
encoding: utf-8
@@ -41,7 +41,7 @@ filebeat.inputs:
4141
- "{{ LOG_FILE_TEMPERATURE_MONITOR }}*"
4242
fields:
4343
logzio_codec: json
44-
token: {{ LOGZ_IO_CODE }}
44+
token: "{{ USER_CONFIG['LOGS']['LOGZ_IO']['LOGZ_IO_TOKEN'] }}"
4545
type: pi_portal_temperature_json
4646
fields_under_root: true
4747
encoding: utf-8

pi_portal/installation/templates/tests/test_config_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test__create_context__returns_dict(
3030
config_file_template: config_file.ConfileFileTemplate,
3131
) -> None:
3232
expected_values = {
33-
"LOGZ_IO_CODE": mocked_state.user_config["LOGZ_IO_CODE"],
33+
"USER_CONFIG": mocked_state.user_config,
3434
}
3535
for setting in dir(config):
3636
if not setting.startswith("__"):

pi_portal/modules/configuration/tests/fixtures/mock_state.py

+38-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'LOGS': 'MOCK_S3_BUCKET_NAME_1',
1414
'VIDEOS': 'MOCK_S3_BUCKET_NAME_2',
1515
}
16-
MOCK_LOGZ_IO_CODE = "secretCode"
16+
MOCK_LOGZ_IO_TOKEN = "secretCode"
1717
MOCK_SLACK_CHANNEL = "mockChannel"
1818
MOCK_SLACK_CHANNEL_ID = "CHHH111"
1919
MOCK_SLACK_APP_SIGNING_SECRET = "MOCK_SLACK_APP_SIGNING_SECRET"
@@ -41,25 +41,48 @@ def mock_state_creator() -> Generator[mock.Mock, None, None]:
4141
try:
4242
mock_state_instance = mock_state.return_value
4343
mock_state_instance.user_config = {
44-
"AWS_ACCESS_KEY_ID": MOCK_AWS_ACCESS_KEY_ID,
45-
"AWS_SECRET_ACCESS_KEY": MOCK_AWS_SECRET_ACCESS_KEY,
46-
"AWS_S3_BUCKETS": MOCK_AWS_S3_BUCKETS,
47-
"LOGZ_IO_CODE": MOCK_LOGZ_IO_CODE,
48-
"SLACK_APP_SIGNING_SECRET": MOCK_SLACK_APP_SIGNING_SECRET,
49-
"SLACK_APP_TOKEN": MOCK_SLACK_APP_TOKEN,
50-
"SLACK_BOT_TOKEN": MOCK_SLACK_BOT_TOKEN,
51-
"SLACK_CHANNEL": MOCK_SLACK_CHANNEL,
52-
"SLACK_CHANNEL_ID": MOCK_SLACK_CHANNEL_ID,
53-
"CONTACT_SWITCHES": [{
54-
"NAME": "Front",
55-
"GPIO": 5,
56-
}],
44+
"ARCHIVAL":
45+
{
46+
"AWS":
47+
{
48+
"AWS_ACCESS_KEY_ID": MOCK_AWS_ACCESS_KEY_ID,
49+
"AWS_SECRET_ACCESS_KEY": MOCK_AWS_SECRET_ACCESS_KEY,
50+
"AWS_S3_BUCKETS": MOCK_AWS_S3_BUCKETS,
51+
}
52+
},
53+
"CHAT":
54+
{
55+
"SLACK":
56+
{
57+
"SLACK_APP_SIGNING_SECRET":
58+
MOCK_SLACK_APP_SIGNING_SECRET,
59+
"SLACK_APP_TOKEN":
60+
MOCK_SLACK_APP_TOKEN,
61+
"SLACK_BOT_TOKEN":
62+
MOCK_SLACK_BOT_TOKEN,
63+
"SLACK_CHANNEL":
64+
MOCK_SLACK_CHANNEL,
65+
"SLACK_CHANNEL_ID":
66+
MOCK_SLACK_CHANNEL_ID,
67+
}
68+
},
69+
"LOGS": {
70+
"LOGZ_IO": {
71+
"LOGZ_IO_TOKEN": MOCK_LOGZ_IO_TOKEN,
72+
}
73+
},
74+
"SWITCHES": {
75+
"CONTACT_SWITCHES": [{
76+
"NAME": "Front",
77+
"GPIO": 5,
78+
}],
79+
},
5780
"TEMPERATURE_SENSORS": {
5881
"DHT11": [{
5982
"NAME": "Kitchen",
6083
"GPIO": 4,
6184
}]
62-
}
85+
},
6386
}
6487
mock_state_instance.log_uuid = MOCK_LOG_UUID
6588
mock_state_instance.log_level = MOCK_LOG_LEVEL

pi_portal/modules/configuration/tests/test_user_config.py

+50-39
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,54 @@
1111
from pi_portal.modules.mixins import read_json_file
1212

1313
MOCK_INVALID_JSON = cast(user_config.TypeUserConfig, {"mock_setting": "0123"})
14-
MOCK_VALID_JSON = cast(
15-
user_config.TypeUserConfig,
16-
{
17-
"AWS_ACCESS_KEY_ID":
18-
"... AWS key with write access to buckets ...",
19-
"AWS_SECRET_ACCESS_KEY":
20-
"... AWS secret key with write access buckets ...",
21-
"AWS_S3_BUCKETS":
14+
MOCK_VALID_JSON = user_config.TypeUserConfig(
15+
**{
16+
"ARCHIVAL":
2217
{
23-
"LOGS": "... s3 logs bucket name ...",
24-
"VIDEOS": "... s3 video bucket name ..."
18+
"AWS":
19+
{
20+
"AWS_ACCESS_KEY_ID":
21+
"... AWS key with write access ...",
22+
"AWS_SECRET_ACCESS_KEY":
23+
"... AWS secret key with write access ...",
24+
"AWS_S3_BUCKETS":
25+
{
26+
"LOGS": "... s3 logs bucket name ...",
27+
"VIDEOS": "... s3 video bucket name ..."
28+
},
29+
}
30+
},
31+
"CHAT":
32+
{
33+
"SLACK":
34+
{
35+
"SLACK_APP_SIGNING_SECRET":
36+
"... secret value from slack ...",
37+
"SLACK_APP_TOKEN":
38+
"... token from slack ...",
39+
"SLACK_BOT_TOKEN":
40+
"... token from slack ...",
41+
"SLACK_CHANNEL":
42+
"... proper name of slack channel ...",
43+
"SLACK_CHANNEL_ID":
44+
".. slack's ID for the channel ...",
45+
},
46+
},
47+
"LOGS": {
48+
"LOGZ_IO": {
49+
"LOGZ_IO_TOKEN": "... logz io's logger token ..."
50+
}
51+
},
52+
"SWITCHES":
53+
{
54+
"CONTACT_SWITCHES":
55+
[
56+
{
57+
"NAME": "... name and pin-out of a GPIO switch...",
58+
"GPIO": 12,
59+
},
60+
],
2561
},
26-
"CONTACT_SWITCHES":
27-
[
28-
{
29-
"NAME": "... name and pin-out of a GPIO switch...",
30-
"GPIO": 12,
31-
},
32-
],
33-
"LOGZ_IO_CODE":
34-
"... logz io's logger code ...",
35-
"SLACK_APP_SIGNING_SECRET":
36-
"... secret value from slack to validate bot messages ...",
37-
"SLACK_APP_TOKEN":
38-
"... token from slack to allow app to use websockets ...",
39-
"SLACK_BOT_TOKEN":
40-
"... token from slack ...",
41-
"SLACK_CHANNEL":
42-
"... proper name of slack channel ...",
43-
"SLACK_CHANNEL_ID":
44-
".. slack's ID for the channel ...",
4562
"TEMPERATURE_SENSORS":
4663
{
4764
"DHT11":
@@ -114,15 +131,9 @@ def test_validate__invalid_configuration(
114131
user_configuration_instance.validate()
115132

116133
assert json.loads(str(exc.value)) == [
117-
"'AWS_ACCESS_KEY_ID' is a required property",
118-
"'AWS_SECRET_ACCESS_KEY' is a required property",
119-
"'AWS_S3_BUCKETS' is a required property",
120-
"'CONTACT_SWITCHES' is a required property",
121-
"'LOGZ_IO_CODE' is a required property",
122-
"'SLACK_APP_SIGNING_SECRET' is a required property",
123-
"'SLACK_APP_TOKEN' is a required property",
124-
"'SLACK_BOT_TOKEN' is a required property",
125-
"'SLACK_CHANNEL' is a required property",
126-
"'SLACK_CHANNEL_ID' is a required property",
134+
"'ARCHIVAL' is a required property",
135+
"'CHAT' is a required property",
136+
"'LOGS' is a required property",
137+
"'SWITCHES' is a required property",
127138
"'TEMPERATURE_SENSORS' is a required property",
128139
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Type definitions for the user configuration."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Archival configuration types."""
2+
3+
from typing_extensions import TypedDict
4+
5+
6+
class TypeUserConfigArchival(TypedDict):
7+
"""Typed representation of the archival configuration."""
8+
9+
AWS: "TypeUserConfigArchivalAWS"
10+
11+
12+
class TypeUserConfigArchivalAWS(TypedDict):
13+
"""Typed representation of the AWS archival configuration."""
14+
15+
AWS_ACCESS_KEY_ID: str
16+
AWS_SECRET_ACCESS_KEY: str
17+
AWS_S3_BUCKETS: "TypeUserConfigArchivalAWSBuckets"
18+
19+
20+
class TypeUserConfigArchivalAWSBuckets(TypedDict):
21+
"""Typed representation of the required S3 bucket names."""
22+
23+
LOGS: str
24+
VIDEOS: str

0 commit comments

Comments
 (0)