Skip to main content

filemap - processing Kubernetes-style config maps and secrets

What's this

filemap is a Python module for comfortable processing of Kubernetes-style config maps and secrets, mounted as the volumes.

Usage

When connected as volumes, Kubernetes config maps and secrets are single-level directory, where files are keys and file contents are values.

Basic usage

When loaded, inside FileMap object, keys are transformed into fields and namespaces, field trees are formed with the dots in file names, as:

  • somefile => obj.data.somefile
  • some.key => obj.data.some.key
  • some.another.key => obj.data.some.another.key

Example:

from filemap import FileMap

config = FileMap('/etc/config')

print(config.data.somefile)
print(config.data.some.key)
print(config.data.some.another.key)

Note: when text data is loaded, it's automatically right-stripped.

Getting single key by name

print(config.get('some.key'))
print(config.get('some.another.key'))

Serialization to dict

When serialized, FileMap object is transformed into dict:

data = config.serialize()
print(data['somefile'])
print(data['some']['file'])
print(data['some']['another']['file'])

Combining multiple volumes

FileMap object can be updated multiple times with content from the different data folders:

config = FileMap()

config.update('/etc/config')
config.update('/etc/config2')
config.update('/etc/secrets')

If the same keys exist in different volumes, newer keys override the older ones.

Loading binary data

When argument raw=True is used either in constructor or in update function, the data is loaded in binary format.

config = FileMap('/etc/binary-keys', raw=True)
config.update('/etc/binary-keys2', raw=True)

Installation

pip3 install filemap

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filemap-0.0.2.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file filemap-0.0.2.tar.gz.

File metadata

  • Download URL: filemap-0.0.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for filemap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7e4ca9907cffbfd13532b4bcdccb50af74a723e96ab52fd7bda44474b3524283
MD5 1536c9eeb4e9cfe35ae76c7e8c15090b
BLAKE2b-256 c2817709d32865584999dc90ee7754deec2303f3e7b07eff777ad1afd5dcdd67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page