https://github.com/cloudtruth/importer
An importer utility for adding parameters to cloudtruth
https://github.com/cloudtruth/importer
Last synced: about 2 months ago
JSON representation
An importer utility for adding parameters to cloudtruth
- Host: GitHub
- URL: https://github.com/cloudtruth/importer
- Owner: cloudtruth
- License: other
- Created: 2021-06-10T20:51:43.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-26T15:32:22.000Z (almost 3 years ago)
- Last Synced: 2023-04-26T17:22:40.014Z (almost 3 years ago)
- Language: Ruby
- Size: 53.7 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/cloudtruth/importer/actions)
[](https://codecov.io/gh/cloudtruth/importer)
[](https://cloudtruth.com)
# Cloudtruth Importer
An importer utility for adding parameters to cloudtruth.
## Installation
```shell
docker pull cloudtruth/importer
```
## Uninstall
```shell
docker rmi --force cloudtruth/importer
```
## Usage
To get the cli usage for the importer:
```shell
docker run cloudtruth/importer --help
```
and then run it for real like:
```shell
docker run -v $(pwd):/data -e CLOUDTRUTH_API_KEY=xyz cloudtruth/importer --dry-run /data/some/file.yaml
```
It scans the given directories and files (or stdin), parsing those that are a
form of structured data (json/yaml/dotenv/properties). The structured data is
then passed into a transformation template in order to generate parameter
definitions that are used to drive the cloudtruth cli to create the actual
parameters.
The transformation template is processed using the [Liquid template
language](https://shopify.github.io/liquid/). The context supplied to each
rendering of the template will contain the variables:
| Variable | Description | Type |
|----------|-------------|------|
| environment | The environment supplied from the `--environment` cli flag or by using a named capture from `--path-selector` (i.e. to extract the environment from filenames) | string |
| project | The project supplied from the `--project` cli flag or by using a named capture from `--path-selector` (i.e. to extract the environment from filenames) | string |
| filename | The filename for the data the template is currently being rendered for | string |
| data | The structured data parsed from the file that the template is currently being rendered for | map or array depending on file contents |
| | Any named captures from applying the `--path-selector` regular expression to the filename | string
The default transformation template treats the `data` passed in as a simple HashMap,
using its keys/value to be the parameter keys and values. It looks like:
```liquid
{% for entry in data %}
- environment: "{{ environment }}"
project: "{{ project }}"
key: "{{ entry[0] }}"
value: "{{ entry[1] }}"
{% endfor %}
```
To handle other data structures, your template should produce a yaml document
that is a list of parameter definitions of the form:
```yaml
- environment: someEnvironment, # The environment to set the value for
environment_parent: someParentEnv, # The environment's parent if using --create-environments
project: someProject, # The project to create the parameter in
project_parent: someParentProj, # The project's parent if using --create-projects
key: aKey, # The key name of the parameter
value: aValue, # The value for the parameter. Don't set this if using FQN+JMES
secret: false, # (optional) Indicate that the parameter should be created as a secret
fqn: myFQN, # (optional) Set the parameter value to come from the given FQN (with optional JMES)
jmes: myJmesPath # (optional) Set the parameter value to come from the given FQN+JMES
```
### Examples
#### Read from stdin
```shell
cat somefile.yaml | docker run -i -e CLOUDTRUTH_API_KEY=xyz cloudtruth/importer --dry-run --stdin yaml
```
## Development
After checking out the repo, run `docker build -t cloudtruth/importer .` to build the image.
Run `docker run -it --entrypoint "" cloudtruth/importer bundle exec rspec` to run the tests.
Run `docker run -it --entrypoint "" cloudtruth/importer bundle exec bin/console` to get an interactive console.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/cloudtruth/importer.