ConfigFormatter helps you to follow the naming patterns of Google Cloud resources in your Python application.
Project description
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 environmentconfig.solution.json
- specification of the solution (e.g. name of the solution, name of the solution owner, etc.) - independent on the environmentconfig.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
Release history Release notifications | RSS feed
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
File details
Details for the file surquest_utils_config_formatter-0.0.2.tar.gz
.
File metadata
- Download URL: surquest_utils_config_formatter-0.0.2.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7139da58ccf45311d15191e977395d2314f1c483dc628d242c3e2cce75d41bea |
|
MD5 | cf87da45dd45f7196406177c88596ca8 |
|
BLAKE2b-256 | 422ef0faaae2aa2f771ee8de12eb8d6c6ea0cd9b0b1f6ff464a1e76adf2f4cf4 |
File details
Details for the file surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd70b9b5edaf8ec372b0a41ebb578ecf92e987adc43f7d9c48b9f0242995f4e6 |
|
MD5 | 3c06aa0c051f7963c6ecc05511f056b0 |
|
BLAKE2b-256 | 0e88d368a7005175c92e0073088eccbf32b1c80338e4404a4d4db965d520731a |