Skip to main content

ConfigFormatter helps you to follow the naming patterns of Google Cloud resources in your Python application.

Project description

GitHub GitHub Workflow Status (with branch) Coverage PyPI - Downloads PyPI

Introduction

The Formatter helps you to follow the naming patterns of resources defined for your Python application as well as for the IaC (Infrastructure as Code) scripts in Terraform.

Getting started

Following example illustrates how to use the Formatter can help you get names of resources defined with the help of the naming patterns.

# Project configuration
config = {
    "env": "PROD",
    "project": {
        "code": "analytics-datamart",
        "slug": "adm",
        "solution": {
            "code": "exchange-rates",
            "slug": "fx"
        }
    }
}
# Project naming patterns
naming_patterns = {
    "storage": {
        "buckets": {
            "ingress": "${project.slug}--${project.solution.code}--ingress--${lower(env)}",
            "asset": "${project.slug}--${project.solution.code}--assets--${lower(env)}",
        }
    },
    "bigquery": {
        "datasets": {
            "raw": "${project.slug}_${replace(project.solution.code,'-','_')}_raw",
            "reporting": "${project.slug}_${replace(project.solution.code,'-','_')}_reporting",
        }
    }
}

from surquest.utils.config.formatter import Formatter
formatter = Formatter(
    config=config,
    naming_patterns=naming_patterns,
)

# Get the name of the bucket for the ingress data
formatter.get("storage.buckets.ingress") # adm--exchange-rates--ingress--prod
formatter.get("bigquery.datasets.raw") # adm_exchange_rates_raw

Advanced usage

Let's assume we have all the configuration specified in 4 different JSON files as follows:

  • config.cloud.google.env.PROD.json - configuration for the production environment (GCP project details)
  • config.cloud.google.services.json - specification of the GCP services used in the project (e.g. BigQuery, Cloud Storage, Cloud SQL, etc.) - independent on the environment
  • config.solution.json - specification of the solution (e.g. name of the solution, name of the solution owner, etc.) - independent on the environment
  • config.tenants.json - specification of the tenants (e.g. name of the tenant, country of the tenant, etc.) - independent on the environment

If you want to see more details about the configuration files, please check the config directory

from surquest.utils.config.formatter import Formatter

formatter = Formatter(
  config=Formatter.import_config(
    configs={
      "GCP": "path/to/config/config.cloud.google.env.PROD.json",
      "services": "path/to/config/config.cloud.google.services.json",
      "solution": "path/to/config/config.solution.json",
    }
  ),
  naming_patterns=Formatter.load_json(
    path="path/to/config/naming.patterns.json"
  )
)

formatter.get("storage.buckets.ingress") # adm--exchange-rates--ingress--prod

Local development

You are more than welcome to contribute to this project. To make your start easier we have prepared a docker image with all the necessary tools to run it as interpreter for Pycharm or to run tests.

Build docker image

docker build `
--tag python/utils/config/formatter     `
--file package.base.dockerfile `
--target test .

Run tests

docker run --rm -it `
-v "${pwd}:/opt/project" `
-w "/opt/project/test" `
python/utils/config/formatter pytest

Project details


Download files

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

Source Distribution

Built Distribution

surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl (5.9 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for surquest_utils_config_formatter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7139da58ccf45311d15191e977395d2314f1c483dc628d242c3e2cce75d41bea
MD5 cf87da45dd45f7196406177c88596ca8
BLAKE2b-256 422ef0faaae2aa2f771ee8de12eb8d6c6ea0cd9b0b1f6ff464a1e76adf2f4cf4

See more details on using hashes here.

File details

Details for the file surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dd70b9b5edaf8ec372b0a41ebb578ecf92e987adc43f7d9c48b9f0242995f4e6
MD5 3c06aa0c051f7963c6ecc05511f056b0
BLAKE2b-256 0e88d368a7005175c92e0073088eccbf32b1c80338e4404a4d4db965d520731a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page