From 12a4ab7ae78213839b09ef5a49ab349541ff19cc Mon Sep 17 00:00:00 2001 From: Kristian Krsnik Date: Tue, 1 Aug 2023 21:58:56 +0200 Subject: [PATCH] added support for keys in external files --- dyn_gandi/main.py | 14 ++++++++++++-- flake.nix | 2 ++ nix/hm-module.nix | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 nix/hm-module.nix diff --git a/dyn_gandi/main.py b/dyn_gandi/main.py index f3392eb..24ef006 100644 --- a/dyn_gandi/main.py +++ b/dyn_gandi/main.py @@ -1,11 +1,21 @@ -import requests, json, re +import requests, json, re, os from datetime import datetime def loadSettings() -> dict: # TODO: check integrity try: with open('config.json', 'r') as file: - return json.load(file) + # Read if the API keys are path to files + config = json.load(file) + keys = config['api'].keys() + mask = dict() + for key in keys: + api_key = key + if os.path.exists(key): + with open(key, 'r') as file: + api_key = file.readline().strip() + mask[key] = api_key + config['api'] = { mask[key]: value for key, value in config['api'].items() } except FileNotFoundError: sample_config = { 'api': {}, diff --git a/flake.nix b/flake.nix index d652f79..26c7640 100644 --- a/flake.nix +++ b/flake.nix @@ -40,5 +40,7 @@ type = "app"; }; }); + + homeManagerModules.default = import ./nix/hm-module.nix self; }; } diff --git a/nix/hm-module.nix b/nix/hm-module.nix new file mode 100644 index 0000000..b5611d2 --- /dev/null +++ b/nix/hm-module.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.dyn-gandi; +in { + + options.dyn-gandi = { + enable = lib.mkEnableOption null // { + description = lib.mdDoc ''''; + }; + }; + + config = lib.mkIf cfg.enable { + +}; +} \ No newline at end of file