Compare commits
2 Commits
5b173917be
...
0bf20c32c4
Author | SHA1 | Date |
---|---|---|
neri | 0bf20c32c4 | |
neri | f2b95e3eb0 |
|
@ -37,7 +37,6 @@ api:
|
||||||
key: $api_enckey
|
key: $api_enckey
|
||||||
|
|
||||||
ota:
|
ota:
|
||||||
- platform: esphome
|
|
||||||
password: $ota_password
|
password: $ota_password
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
|
@ -66,7 +65,6 @@ http_request:
|
||||||
useragent: esphome
|
useragent: esphome
|
||||||
timeout: 2s
|
timeout: 2s
|
||||||
id: http_request_data
|
id: http_request_data
|
||||||
verify_ssl: false
|
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
- id: my_token
|
- id: my_token
|
||||||
|
@ -91,9 +89,13 @@ rc522_spi:
|
||||||
# store the tag id into global variable
|
# store the tag id into global variable
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
id(my_tag) = x;
|
id(my_tag) = x;
|
||||||
|
- text.set:
|
||||||
|
id: ${name_of_board}_letzter_token
|
||||||
|
value: !lambda return id(my_tag);
|
||||||
# login to vault with role_id to fetch short lived token
|
# login to vault with role_id to fetch short lived token
|
||||||
- http_request.post:
|
- http_request.post:
|
||||||
url: https://vault.ctdo.de/v1/auth/approle/login
|
url: https://vault.ctdo.de/v1/auth/approle/login
|
||||||
|
verify_ssl: false
|
||||||
headers:
|
headers:
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
json:
|
json:
|
||||||
|
@ -103,26 +105,25 @@ rc522_spi:
|
||||||
# fetch token from response, store into my_token
|
# fetch token from response, store into my_token
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
json::parse_json(body, [](JsonObject root) -> bool {
|
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
|
||||||
id(my_token) = (const char*) root["auth"]["client_token"];
|
id(my_token) = (const char*) root["auth"]["client_token"];
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
# use the token to get json of scanned tag from vault
|
# use the token to get json of scanned tag from vault
|
||||||
- http_request.get:
|
- http_request.get:
|
||||||
url: !lambda |-
|
url: !lambda |-
|
||||||
return ((std::string) "https://vault.ctdo.de/v1/maschinenlock/" + id(my_tag));
|
return ((std::string) "https://vault.ctdo.de/v1/maschinenlock/" + id(my_tag));
|
||||||
|
verify_ssl: false
|
||||||
headers:
|
headers:
|
||||||
X-Vault-Token: !lambda return id(my_token).c_str();
|
X-Vault-Token: !lambda return id(my_token).c_str();
|
||||||
on_response:
|
on_response:
|
||||||
then:
|
then:
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
lambda: 'return response->status_code == 200;'
|
lambda: 'return status_code == 200;'
|
||||||
then: # when found, check if machine is allowed, turn on output or blink LED red
|
then: # when found, check if machine is allowed, turn on output or blink LED red
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
json::parse_json(body, [](JsonObject root) -> bool {
|
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
|
||||||
id(may_switch_output) = root["data"]["mlock-$name_of_board"];
|
id(may_switch_output) = root["data"]["mlock-$name_of_board"];
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
|
@ -225,3 +226,8 @@ text:
|
||||||
id: ${name_of_board}_letzte_entsperrung
|
id: ${name_of_board}_letzte_entsperrung
|
||||||
optimistic: true
|
optimistic: true
|
||||||
mode: text
|
mode: text
|
||||||
|
- platform: template
|
||||||
|
name: "$name_of_board Zuletzt Gelesener Token"
|
||||||
|
id: ${name_of_board}_letzter_token
|
||||||
|
optimistic: true
|
||||||
|
mode: text
|
||||||
|
|
Loading…
Reference in New Issue