Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
* clarified names to better explain secrets

* removed whitespace to trigger actions

* 1.0.0
  • Loading branch information
LiamMahoney authored Mar 4, 2023
1 parent 875becc commit a17db08
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ A ConfigParser subclass that can read values stored with the [keyring pypi packa

## Usage

It is recommended to be familiar with the [ConfigParser](https://docs.python.org/3/library/configparser.html) module and the [keyring](https://pypi.org/project/keyring/) pypi package.
It is recommended to be familiar with the [ConfigParser](https://docs.python.org/3/library/configparser.html) module and the [keyring](https://pypi.org/project/keyring/) pypi package before use.

`KeryingConfigParser` is identical to `ConfigParser` except when it reads a specific token as a configuration value (`"$."` by default) it uses the keyring package to resolve the value. This enables using secret values in configuration files without storing the value as plain-text within the file.

### Basic Example

```
#/tmp/app.config
[EXAMPLE_SECTION]
[section_name]
non_secret = hello world
some_secret = $.
secret_name = $.
```

```python
import keyring

keyring.set_password("EXAMPLE_SECTION", "some_secret", "very_secret_value")
keyring.set_password("section_name", "secret_name", "secret_value")
```

```python
from keyring_configparser import KeyringConfigParser

config = KeyringConfigParser()
config.read("/tmp/app.config")
config.get('EXAMPLE_SECTION', 'non_secret')
config.get('section_name', 'non_secret')
> "hello world"
sec = config.get('EXAMPLE_SECTION', 'some_secret')
> "very_secret_value"
sec = config.get('section_name', 'secret_name')
> "secret_value"
```

### Additional Examples
Expand All @@ -48,12 +48,19 @@ A configured keyring instance can be supplied to the `KeyringConfigParser` const

For example, to use the [`keyrings.cryptfile`](https://pypi.org/project/keyrings.cryptfile/) backend:

```
#/tmp/app.config
[section_name]
non_secret = hello world
secret_name = $.
```

```python
from keyrings.cryptfile.cryptfile import CryptFileKeyring

kr = CryptFileKeyring()
kr.keyring_key = "CRYPTFILE_PASSWORD"
kr.set_password("EXAMPLE_SECTION", "some_secret", "very_secret_value")
kr.set_password("section_name", "secret_name", "secret_value")
```

```python
Expand All @@ -65,32 +72,36 @@ kr.keyring_key = "CRYPTFILE_PASSWORD"

config = KeyringConfigParser(keyring=kr)
config.read("/tmp/app.config")
config.get('EXAMPLE_SECTION', 'some_secret')
> "very_secret_value"
config.get('section_name', 'secret_name')
> "secret_value"
```

#### Custom Config Token

A token can be supplied to the `KeyringConfigParser` constructor to override the default token `"$."`. When the custom token is encountered in the configuration file the value will be resolved with keyring.

Given the following configuration file:

```
#/tmp/app.config
[EXAMPLE_SECTION]
[section_name]
non_secret = hello world
some_secret = !~!
secret_name = !~!
default_token = $.
```

```python
import keyring

keyring.set_password("section_name", "secret_name", "secret_value")
```

```python
from keyring_configparser import KeyringConfigParser

config = KeyringConfigParser(token="!~!")
config.read("/tmp/app.config")
config.get('EXAMPLE_SECTION', 'some_secret')
> "very_secret_value"
config.get('EXAMPLE_SECTION', 'default_token')
config.get('section_name', 'secret_name')
> "secret_value"
config.get('section_name', 'default_token')
> "$."
```

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "keyring_configparser"
version = "0.1.2"
version = "1.0.0"
authors = [
{ name="Liam Mahoney", email="liammahoney96@gmail.com" },
]
Expand Down
6 changes: 1 addition & 5 deletions src/keyring_configparser/keyring_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,4 @@ def before_get(self, parser, section, option, value, defaults):
return parsed_value

# token not specified, return value stored in config file
return value




return value

0 comments on commit a17db08

Please sign in to comment.