Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dig feature. #66

Merged
merged 5 commits into from
Oct 20, 2017
Merged

Add dig feature. #66

merged 5 commits into from
Oct 20, 2017

Conversation

crayfishx
Copy link
Owner

Related to #65

#65 was a great suggestion and I felt we could do more with this idea......

From the readme;

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;

{
  "apache::port": 80
}

Returned value would be 80

This behaviour can be overriden by using the options dig and dig_key.

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 can also be used in the dig_key option. Consider the following example output from our HTTP endpoint;

{
  "document": {
    "settings": {
      "apache::port": 80
    }
  }
}

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 dig into the hash with the following option;

  options:
    dig_key: document.settings.__KEY__

A more complicated example;

{
  "document": {
    "settings": {
      "apache": {
        "port": 80
      }
    }
  }
}

Can be looked up with;

  options:
    dig_key: document.settings.__MODULE__.__KEY__

The dig option can be used to disable digging altogether and the entire data hash will be returned with no attempt to resolve a key

@crayfishx
Copy link
Owner Author

This PR also adds a distinction between an undefined value and a deliberatly set nil value.

@crayfishx
Copy link
Owner Author

Closes #65

@crayfishx crayfishx merged commit 8be9894 into master Oct 20, 2017
@FlorinAsavoaie
Copy link

I think this broke some stuff. I didn't get the time to look into this but http_get returns nil for some cases and then when you test if it's a string, it's not... And it tries to hash_dig it, and it can't call has_key? on nil.

@crayfishx
Copy link
Owner Author

@FlorinAsavoaie This should be fixed in 3.3.2 just released.

cegeka-jenkins pushed a commit to cegeka/puppet-hierahttp that referenced this pull request Jan 19, 2023
* added dig features

* added docs

* typo

* updated README with more about digging

* [skip ci] fixed example error in README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants