You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+88-15Lines changed: 88 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -64,39 +64,47 @@ The following mandatory Hiera 5 options must be set for each level of the hierar
64
64
65
65
The following are optional configuration parameters supported in the `options` hash of the Hiera 5 config
66
66
67
-
`:output: ` : Specify what handler to use for the output of the request. Currently supported outputs are plain, which will just return the whole document, or YAML and JSON which parse the data and try to look up the key
67
+
#### Lookup options
68
68
69
-
`:http_connect_timeout: ` : Timeout in seconds for the HTTP connect (default 10)
69
+
`output:` : Specify what handler to use for the output of the request. Currently supported outputs are plain, which will just return the whole document, or YAML and JSON which parse the data and try to look up the key
70
70
71
-
`:http_read_timeout:` : Timeout in seconds for waiting for a HTTP response (default 10)
71
+
`http_connect_timeout: ` : Timeout in seconds for the HTTP connect (default 10)
72
72
73
-
`:confine_to_keys: ` : Only use this backend if the key matches one of the regexes in the array
73
+
`http_read_timeout: ` : Timeout in seconds for waiting for a HTTP response (default 10)
74
+
75
+
`confine_to_keys: ` : Only use this backend if the key matches one of the regexes in the array
74
76
75
77
confine_to_keys:
76
78
- "application.*"
77
79
- "apache::.*"
78
80
79
-
`:failure: ` : When set to `graceful` will stop hiera-http from throwing an exception in the event of a connection error, timeout or invalid HTTP response and move on. Without this option set hiera-http will throw an exception in such circumstances
81
+
`failure: ` : When set to `graceful` will stop hiera-http from throwing an exception in the event of a connection error, timeout or invalid HTTP response and move on. Without this option set hiera-http will throw an exception in such circumstances
82
+
83
+
`ignore_404: ` : If `failure` is _not_ set to `graceful` then any error code received from the HTTP response will throw an exception. This option makes 404 responses exempt from exceptions. This is useful if you expect to get 404's for data items not in a certain part of the hierarchy and need to fall back to the next level in the hierarchy, but you still want to bomb out on other errors.
84
+
85
+
`dig:` : (true or false) When the output is parsed YAML or JSON, whether or not to dig into the hash and return the value defined by the `dig_key` option below. This option defaults to `true`
86
+
87
+
`dig_key` : When the `dig` option is true (default), this option specifies what key is looked up from the results hash returned by the HTTP endpoint. See [Digging values](#digging-values) below for more information
80
88
81
-
`:ignore_404: ` : If `failure` is _not_ set to `graceful` then any error code received from the HTTP response will throw an exception. This option makes 404 responses exempt from exceptions. This is useful if you expect to get 404's for data items not in a certain part of the hierarchy and need to fall back to the next level in the hierarchy, but you still want to bomb out on other errors.
89
+
#### HTTP options
82
90
83
-
`:use_ssl:`: When set to true, enable SSL (default: false)
91
+
`use_ssl:`: When set to true, enable SSL (default: false)
84
92
85
-
`:ssl_ca_cert`: Specify a CA cert for use with SSL
93
+
`ssl_ca_cert`: Specify a CA cert for use with SSL
86
94
87
-
`:ssl_cert`: Specify location of SSL certificate
95
+
`ssl_cert`: Specify location of SSL certificate
88
96
89
-
`:ssl_key`: Specify location of SSL key
97
+
`ssl_key`: Specify location of SSL key
90
98
91
-
`:ssl_verify`: Specify whether to verify SSL certificates (default: true)
99
+
`ssl_verify`: Specify whether to verify SSL certificates (default: true)
92
100
93
-
`:use_auth:`: When set to true, enable basic auth (default: false)
101
+
`use_auth:`: When set to true, enable basic auth (default: false)
94
102
95
-
`:auth_user:`: The user for basic auth
103
+
`auth_user:`: The user for basic auth
96
104
97
-
`:auth_pass:`: The password for basic auth
105
+
`auth_pass:`: The password for basic auth
98
106
99
-
`:headers:`: Hash of headers to send in the request
107
+
`headers:`: Hash of headers to send in the request
100
108
101
109
### Interpolating special tags
102
110
@@ -130,6 +138,71 @@ hierarchy:
130
138
failure: graceful
131
139
```
132
140
141
+
### Digging values
142
+
143
+
Hiera-HTTP supports options to automatically dig into the returned data structure to find a corresponding key. Puppet lookup itself supports similar dig functionality but being able to specify it at the backend means that where an API wraps the required data up in a different way, we can always lookup the desired value before passing it to Puppet to ensure that class parameter lookups work without having to hard code the `lookup` function and dig down into the data for each request. The dig functionality in Puppet is intended to enable you to parse your data more effectivly, the dig functionality in hiera-http is intended to make the API of the endpoint you are talking to compatible.
144
+
145
+
By default, when a hash is returned by the HTTP endpoint (eg: JSON) then hiera-http will attempt to lookup the key corresponding with the lookup key. For example, when looking up a key `apache::port` we would expect the HTTP endpoint to return something like;
146
+
147
+
```json
148
+
{
149
+
"apache::port": 80
150
+
}
151
+
```
152
+
153
+
Returned value would be `80`
154
+
155
+
Depending on what HTTP endpoint we are hitting, the returned output may contain other data with the key that we want to look up nested below it. This behaviour can be overriden by using the options `dig` and `dig_key`.
156
+
157
+
The `dig_key` option can be used to change the key that is looked up, it also supports a dot-notation for digging values in nested hashes. [Special tags](#interpolating-special-tags) can also be used in the `dig_key` option. Consider the following example output from our HTTP endpoint;
158
+
159
+
```json
160
+
{
161
+
"document": {
162
+
"settings": {
163
+
"apache::port": 80
164
+
}
165
+
}
166
+
}
167
+
```
168
+
169
+
170
+
In this scenario we wouldn't be able to use class parameter lookups out-of-the-box, even if we just returned the whole structure, because we always need to drill down into `document.settings` to get the correct value, so In order to map the lookup to find the correct value, we can interpolate the __KEY__ tag into `lookup_key` and tell hiera-http to always dig into the hash with the following option;
0 commit comments