Skip to main content

CndScaffold >=3.0.0

Why use CndScaffold

CndScaffold is a python lib, designed to help management of GitOps process. Now base on jinja2, it allow you to merge a dict of data into a list of file.

Connected with the right provider, you can directly push your result to a git server (gitlab / github /Azure DevOps)

How it's works ? (with example)

  • define in jinja format a list of template file (the file can be text, yaml or anything else)
  • create a file of definition
  • apply data on it

What we want as result

Data source

For example we got this data

name: Denis
customers:
  - name: my_first_customer
    email: my_first_customer@sample-mail.com
    id: c6a240ac-587a-11ee-8c99-0242ac120002
    token: ABC
  - name: my_second
    email: my_second_customer@sample-mail.com
    id: d174a3e4-587a-11ee-8c99-0242ac120002
    token: DEF
  - name: my_last
    email: my_last_customer@sample-mail.com
    id: ebe22792-587a-11ee-8c99-0242ac120002
    token: GHI

Files result

And we want to generate multiple file for a gitops process, who look like this result:

config.yml

name: Denis
type: my_type_sample

customers.yml

customers:
- name: my_first_customer
  email: my_first_customer@sample-mail.com
  id: c6a240ac-587a-11ee-8c99-0242ac120002
- name: my_second
  email: my_second_customer@sample-mail.com
  id: d174a3e4-587a-11ee-8c99-0242ac120002
- name: my_last
  email: my_last_customer@sample-mail.com
  id: ebe22792-587a-11ee-8c99-0242ac120002

customers/c6a240ac-587a-11ee-8c99-0242ac120002.yml

token: ABC

customers/d174a3e4-587a-11ee-8c99-0242ac120002.yml

token: DEF

customers/ebe22792-587a-11ee-8c99-0242ac120002.yml

token: GHI

How we do it

Definition of a list of file in jinja

A single simple file :

definition/customers/file1.yml

name: {{ name }}
type: my_type_sample

Now a file with a loop :

definition/customers/loop.yml

{% if customers |length > 1 %}
customers: 
{%- for customer in customers %}
  name: {{ customer.name -}}
  email: {{ customer.email -}}
  id: {{ customer.id -}}
{% endfor %}
{% endif %}

And finally to create multiple file with a loop (like one per customer):

definition/customers/multiple.yml

token: {{ token }}

Definition file

definition/customers.yml

source_folder: customers
files:
- name: file1.yml
  step: ['init']
  target: config.yml
- name: loop.yml
  step: ['init', 'build', 'runtime']
- name: multiple.yml
  step: ['init', 'build', 'runtime']
  repeat: customers 
  target: customers/{{ id }}.yml 

Build the code (localfile)

The first sample will generate the file into a results folder

run.py (generate data in a local folder)

import cnd_scaffold
import cndprint


data = my_data # .... load your data as you need
cnd_scaffold = cnd_scaffold.Scaffold(_print)
model = cnd_scaffold.load_model('definition', customers.yml')
final_files = cnd_scaffold.apply('init', model, data)
final_files = cnd_scaffold.push_files(final_files, 'results')

Build the code (provider gitlab)

This second example will push the result into git_lab_project_id

run.py (generate data in a local folder)

import cnd_scaffold
import cndprint
import cnd_provider


data = my_data # .... load your data as you need
provider = cnd_provider.CndProviderGitlab({"private_token": 'replace-me', "host": "https://mygitlab"}
cnd_scaffold = cnd_scaffold.Scaffold(_print)
model = cnd_scaffold.load_model('definition', customers.yml')
final_files = cnd_scaffold.apply('init', model, data)
final_files = cnd_scaffold.push_files(final_files, "git_lab_project_id", provider=provider)

That's all !

With this definition, each time you use cnd_scaffold you will generate this file structure/content from your own data.

Tips

Step

step, will allow you using different case, you can use it as you prefer, but I suggest you this:

  • init: First time only, it's mean this file will never been update by the script
  • build: Each time the process start, it will be update
  • runtime: Perfect for Terraform secret for example, you can set this to never write result on git, but only on the current pipeline session

Metadata

Release files for cnd-scaffold 3.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cnd-scaffold 3.2.1
File Size Uploaded Provenance Actions
cnd_scaffold-3.2.1.tar.gz 12.5 kB Without provenance Details for cnd_scaffold-3.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cnd-scaffold 3.2.1
File Interpreter ABI Platform Actions
cnd_scaffold-3.2.1-py3-none-any.whl Python 3 none any Details for cnd_scaffold-3.2.1-py3-none-any.whl

Total release size: 19.9 kB

Release files / cnd_scaffold-3.2.1.tar.gz

Download URL cnd_scaffold-3.2.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8f1ea6d3c18c405611dc37f03c798322a63c305e064de6d9827c89fb2d984b20
BLAKE2b-256 checksum
How to use checksums
dceb74584bac23e2413431961c49d38fc74e06c185ce7e9db9f1153264684edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / cnd_scaffold-3.2.1-py3-none-any.whl

Download URL cnd_scaffold-3.2.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87d460df531b54c069f614baf85bee0b2b52d435b24784aae744e049c0df53b1
BLAKE2b-256 checksum
How to use checksums
010034b97cda3918b780ebb8660b20b321fa9c861286b463c7704569ae40ee4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for cnd-scaffold 3.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page