Skip to content

Commit

Permalink
read plus api key from addon options
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Jun 30, 2022
1 parent 5e82eae commit 24d3a9c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion frigate/plus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import json
import logging
import os
import re
import requests
from frigate.const import PLUS_ENV_VAR, PLUS_API_HOST
from requests.models import Response
Expand Down Expand Up @@ -28,10 +30,23 @@ def get_jpg_bytes(image: ndarray, max_dim: int, quality: int) -> bytes:
class PlusApi:
def __init__(self) -> None:
self.host = PLUS_API_HOST
self.key = None
if PLUS_ENV_VAR in os.environ:
self.key = os.environ.get(PLUS_ENV_VAR)
else:
# check for the addon options file
elif os.path.isfile("/data/options.json"):
with open("/data/options.json") as f:
raw_options = f.read()
options = json.loads(raw_options)
self.key = options.get("plus_api_key")

if self.key is not None and not re.match(
r"[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}:[a-z0-9]{40}",
self.key,
):
logger.error("Plus API Key is not formatted correctly.")
self.key = None

self._is_active: bool = self.key is not None
self._token_data: dict = {}

Expand Down

0 comments on commit 24d3a9c

Please sign in to comment.