default config

This commit is contained in:
Q
2023-01-22 17:02:25 +02:00
parent cd37185d2a
commit ebf8e00c86
2 changed files with 23 additions and 6 deletions

View File

@@ -1,2 +1,2 @@
__version__ = "0.1" __version__ = "0.2"
from spiller.spiller import retrieve, store, list_storage from spiller.spiller import retrieve, store, list_storage

View File

@@ -9,9 +9,18 @@ import random
import stat import stat
import string import string
JSON = os.getenv(
"SPILLER_STORAGE", os.path.expanduser("~/.config/spiller/storage.json") def get_config():
) default_config = {
'SPILLER_STORAGE': os.path.expanduser("~/.config/spiller/storage.json")
}
try:
with open(os.path.expanduser("~/.config/spiller/config.json"), 'rt') as fp:
default_config.update(json.load(fp))
except Exception:
pass
return default_config
def get_opts(): def get_opts():
@@ -19,8 +28,11 @@ def get_opts():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog="spill", prog="spill",
description="""Key/value storage that uses JSON and GPG as backend. description="""Key/value storage that uses JSON and GPG as backend.
Values are encrypted symmetrically with the key provided, or a random string is generated. Storage file can be changed with Values are encrypted symmetrically with the key provided, or a random string is generated.
SPILLER_STORAGE env variable. Encryption key can be passed from a variable SPILLER_KEY instead of a switch.""", Encryption key can be passed from a variable SPILLER_KEY instead of a switch.
Storage file can be changed with SPILLER_STORAGE env variable, in a
"SPILLER_STORAGE": key in a JSON file read at ~/.config/spill/config.json
""",
) )
subparsers = parser.add_subparsers(dest="command", help="Command") subparsers = parser.add_subparsers(dest="command", help="Command")
set_parser = subparsers.add_parser("set") set_parser = subparsers.add_parser("set")
@@ -204,6 +216,11 @@ def get_random_key():
) )
CONFIG = get_config()
JSON = os.getenv(
"SPILLER_STORAGE", CONFIG['SPILLER_STORAGE']
)
def main(): def main():
opts = get_opts() opts = get_opts()
if opts.command == "set": if opts.command == "set":