From d5e17cb1ee87f51d0fd1b3c40e50791ae40e08a0 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Thu, 24 May 2018 07:51:40 -0400 Subject: Adding env datasource Signed-off-by: Dave Henderson --- docs/content/datasources.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'docs') diff --git a/docs/content/datasources.md b/docs/content/datasources.md index e80744ee..f31128ae 100644 --- a/docs/content/datasources.md +++ b/docs/content/datasources.md @@ -42,6 +42,7 @@ Gomplate supports a number of datasources, each specified with a particular URL | [AWS Systems Manager Parameter Store](#using-aws-smp-datasources) | `aws+smp` | [AWS Systems Manager Parameter Store][AWS SMP] is a hierarchically-organized key/value store which allows storage of text, lists, or encrypted secrets for retrieval by AWS resources | | [BoltDB](#using-boltdb-datasources) | `boltdb` | [BoltDB][] is a simple local key/value store used by many Go tools | | [Consul](#using-consul-datasources) | `consul`, `consul+http`, `consul+https` | [HashiCorp Consul][] provides (among many other features) a key/value store | +| [Environment](#using-env-datasources) | `env` | Environment variables can be used as datasources - useful for testing | | [File](#using-file-datasources) | `file` | Files can be read in any of the [supported formats](#supported-formats), including by piping through standard input (`Stdin`) | | [HTTP](#using-http-datasources) | `http`, `https` | Data can be sourced from HTTP/HTTPS sites in many different formats. Arbitrary HTTP headers can be set with the [`--datasource-header`/`-H`][] flag | | [Stdin](#using-stdin-datasources) | `stdin` | A special case of the `file` datasource; allows piping through standard input (`Stdin`) | @@ -226,6 +227,35 @@ $ gomplate -d consul=consul:///foo -i '{{(datasource "consul" "bar/baz")}}' value for foo/bar/baz key ``` +## Using `env` datasources + +The `env` datasource type provides access to environment variables. This can be useful for rendering templates that would normally use a different sort of datasource, in test and development scenarios. + +No hierarchy or directory semantics are currently supported. + +**Note:** Variable names are _case-sensitive!_ + +### URL Considerations + +The _scheme_ and either the _path_ or the _opaque_ part are used, and the _query_ component can be used to [override the MIME type](#overriding-mime-types). + +- the _scheme_ must be `env` +- one of the _path_ or _opaque_ component is required, and is interpreted as the environment variable's name. Leading `/` characters are stripped from the _path_. + +### Examples + +```console +$ gomplate -d user=env:USER -i 'Hello {{ include "user" }}!' +Hello hairyhenderson! + +$ gomplate -d homedir=env:///HOME -i '{{ files.IsDir (ds "homedir") }}' +true + +$ export foo='{"one":1, "two":2}' +$ gomplate -d foo=env:/foo?type=application/json -i '{{ (ds "foo").two }}' +2 +``` + ## Using `file` datasources The `file` datasource type provides access to files in any of the [supported formats](#mime-types). [Directory datasource](#directory-datasources) semantics are supported. -- cgit v1.2.3