From 6409a6ee04215d96b541a6cf75d9592ef519cd52 Mon Sep 17 00:00:00 2001 From: Korijn van Golen Date: Sun, 23 Jul 2023 07:36:40 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6a0c462..b0c3a89 100644 --- a/README.md +++ b/README.md @@ -40,17 +40,17 @@ The first is the most preferred method, since your secrets will only be exposed ## Configuration > **Note** -> if you are having trouble configuring keycmd, refer to the section [debugging configuration](#debugging-configuration). +> if you are having trouble configuring keycmd, refer to section [debugging configuration](#debugging-configuration). ### Locations Configuration can be stored in three places (where `~` is the user home folder and `.` is the current working directory when calling `keycmd`): - `~/.keycmd` -- `./.keycmd` - first `pyproject.toml` found while walking file system up from `.` +- `./.keycmd` -Configuration is merged where more local configuration values have precendence. +Configuration files are loaded and merged in this order as well. ### Options @@ -64,7 +64,7 @@ The options are a nested dictionary, defined as follows: You can define as many keys as you like. For each key, you are required to define: -* the `key_name`, which is the name of the environment variable under which the credential will be exposed. +* the `key_name`, which is the name of the environment variable under which the credential will be exposed * the `credential`, which is the name of the credential in your OS keyring * the `username`, which is the name of the user owning the credential in the OS keyring @@ -72,7 +72,7 @@ Optionally, you can also set `b64` to `true` to apply base64 encoding to the cre ## Example configuration for Poetry, npm and docker-compose -In this example, I've stored the following configuration in `~/.keyring`: +In this example, I've stored the following configuration in `~/.keycmd`: ```toml [keys] @@ -98,7 +98,10 @@ always-auth=true //pkgs.dev.azure.com/my_organization/_packaging/main/npm/:email=email ``` -Now, I can set up my `node_modules` just by calling `keycmd npm install`. +Now, I can set up my `node_modules` just by calling `keycmd npm install`! 🚀 + +> **Note** +> npm will complain if you make any calls such as `npm run [...]` without the environment variable set. 🙄 You can set them to the empty string to make npm shut up. I use `export ARTIFACTS_TOKEN_B64=` (or `setx ARTIFACTS_TOKEN_B64=` on Windows). Additionally, I also have a docker-compose file in this project which is configured as follows: @@ -110,7 +113,7 @@ secrets: environment: ARTIFACTS_TOKEN_B64 ``` -When I call `keycmd docker compose build` these two variables are exposed by keycmd and subsequently they are available as [docker compose build secrets](https://docs.docker.com/compose/use-secrets/). +When I call `keycmd docker compose build` these two variables are exposed by keycmd and subsequently they are available as [docker compose build secrets](https://docs.docker.com/compose/use-secrets/). 👌 ## Debugging configuration @@ -122,13 +125,13 @@ to debug your configuration. keycmd: loading config file C:\Users\kvang\.keycmd keycmd: loading config file C:\Users\kvang\dev\keycmd\pyproject.toml keycmd: merged config: -{'keys': {'ARTIFACTS_TOKEN': {'credential': 'azure@poetry-repository-main', - 'username': 'azure'}, +{'keys': {'ARTIFACTS_TOKEN': {'credential': 'korijn@poetry-repository-main', + 'username': 'korijn'}, 'ARTIFACTS_TOKEN_B64': {'b64': True, - 'credential': 'azure@poetry-repository-main', - 'username': 'azure'}}} -keycmd: exposing credential azure@poetry-repository-main belonging to user azure as environment variable ARTIFACTS_TOKEN (b64: False) -keycmd: exposing credential azure@poetry-repository-main belonging to user azure as environment variable ARTIFACTS_TOKEN_B64 (b64: True) + 'credential': 'korijn@poetry-repository-main', + 'username': 'korijn'}}} +keycmd: exposing credential korijn@poetry-repository-main belonging to user korijn as environment variable ARTIFACTS_TOKEN (b64: False) +keycmd: exposing credential korijn@poetry-repository-main belonging to user korijn as environment variable ARTIFACTS_TOKEN_B64 (b64: True) keycmd: detected shell: C:\Windows\System32\cmd.exe keycmd: running command: ['C:\\Windows\\System32\\cmd.exe', '/C', 'echo', '%ARTIFACTS_TOKEN_B64%'] aSdtIG5vdCB0aGF0IHN0dXBpZCA6KQ== From 8c9aebe04e07b4af786755223bc196a974555bf0 Mon Sep 17 00:00:00 2001 From: Korijn van Golen Date: Sun, 23 Jul 2023 07:39:04 +0100 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b0c3a89..92b9bda 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Configuration can be stored in three places (where `~` is the user home folder a - first `pyproject.toml` found while walking file system up from `.` - `./.keycmd` -Configuration files are loaded and merged in this order as well. +Configuration files are loaded and merged in the listed order. ### Options From b019a01cf1f73741dc7fc706dd92deba18cd2d20 Mon Sep 17 00:00:00 2001 From: Korijn van Golen Date: Sun, 23 Jul 2023 07:43:43 +0100 Subject: [PATCH 3/5] Correct loading order --- keycmd/conf.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/keycmd/conf.py b/keycmd/conf.py index cb787a5..9fb42b5 100644 --- a/keycmd/conf.py +++ b/keycmd/conf.py @@ -46,20 +46,19 @@ def load_conf(): Load merged configuration from the following files: - defaults() - ~/.keycmd - - ./.keycmd - first pyproject.toml found while walking file system up from . + - ./.keycmd """ conf = defaults() cwd = Path.cwd() - # fixed conf locations, in order - for path in [Path.home(), cwd]: - fpath = path / ".keycmd" - if fpath.is_file(): - vlog(f"loading config file {fpath}") - conf = merge_conf(conf, load_toml(fpath)) + # ~/.keycmd + fpath = Path.home() / ".keycmd" + if fpath.is_file(): + vlog(f"loading config file {fpath}") + conf = merge_conf(conf, load_toml(fpath)) - # dynamic conf locations, walk up from current directory + # pyproject.toml cur = cwd while cur != cur.anchor: pyproj = cur / "pyproject.toml" @@ -72,6 +71,12 @@ def load_conf(): break cur = cur.parent + # ./.keycmd + fpath = cwd / ".keycmd" + if fpath.is_file(): + vlog(f"loading config file {fpath}") + conf = merge_conf(conf, load_toml(fpath)) + vlog(f"merged config:\n{pformat(conf)}") return conf From 997ef48de5b80d44790916578093a695629da1f7 Mon Sep 17 00:00:00 2001 From: Korijn van Golen Date: Sun, 23 Jul 2023 07:45:53 +0100 Subject: [PATCH 4/5] Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8ca40e8..239ef4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "keycmd" -version = "0.1.0" +version = "0.2.0" description = "" authors = ["Korijn van Golen "] license = "MIT" From e3f7fe8e938e7d7d9d71f9007405d21907ca69ae Mon Sep 17 00:00:00 2001 From: Korijn van Golen Date: Sun, 23 Jul 2023 07:46:17 +0100 Subject: [PATCH 5/5] Bump version --- keycmd/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keycmd/__init__.py b/keycmd/__init__.py index 3dc1f76..d3ec452 100644 --- a/keycmd/__init__.py +++ b/keycmd/__init__.py @@ -1 +1 @@ -__version__ = "0.1.0" +__version__ = "0.2.0"