Giter VIP home page Giter VIP logo

keyring_configparser's Introduction

keyring_configparser

GitHub Workflow Status PyPI PyPI - Downloads PyPI - License

A ConfigParser subclass that can read values stored with the keyring pypi package.

Installation

pip install keyring_configparser

Usage

It is recommended to be familiar with the ConfigParser module and the 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
[section_name]
non_secret = hello world
secret_name = $.
import keyring

keyring.set_password("section_name", "secret_name", "secret_value")
from keyring_configparser import KeyringConfigParser

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

Additional Examples

Configured Keyring Instances

A configured keyring instance can be supplied to the KeyringConfigParser constructor. This allows using non-default backends or any other non-default keyring settings when looking up values in keyring.

For example, to use the keyrings.cryptfile backend:

#/tmp/app.config
[section_name]
non_secret = hello world
secret_name = $.
from keyrings.cryptfile.cryptfile import CryptFileKeyring

kr = CryptFileKeyring()
kr.keyring_key = "CRYPTFILE_PASSWORD"
kr.set_password("section_name", "secret_name", "secret_value")
from keyring_configparser import KeyringConfigParser
from keyrings.cryptfile.cryptfile import CryptFileKeyring

kr = CryptFileKeyring()
kr.keyring_key = "CRYPTFILE_PASSWORD"

config = KeyringConfigParser(keyring=kr)
config.read("/tmp/app.config")
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.

#/tmp/app.config
[section_name]
non_secret = hello world
secret_name = !~!
default_token = $.
import keyring

keyring.set_password("section_name", "secret_name", "secret_value")
from keyring_configparser import KeyringConfigParser

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

Questions / Issues

Please raise any questions in the Discussions page of the repository.

Please document any issues encountered in the Issues page of the repository.

keyring_configparser's People

Contributors

liammahoney avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

keyring_configparser's Issues

Action to Automatically Create Release

Need to create a GitHub action that will automatically create a release when a new version is released.

Should either be triggered on PR being merged or a push into the default branch.

Release details:

  • should use the description / body of the PR as the release description
  • create tag - probably using this wrong, I need to look into it more
  • use python version as release + tag name
  • upload distribution archive files

Thought this would be easier than it appears to be. Might need to become familiar with javascript actions so I can use the GitHub API within the action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.