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

Support dot-notation when retrieving facts in facter_impl #46

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

alexjfisher
Copy link

In Puppet 8, core providers are being confined using facts fetched using 'dot-notation'. We need to support this style of lookup in our stub implementation.

For example in lib/puppet/provider/service/init.rb

confine :true => begin
  os = Puppet.runtime[:facter].value(:operatingsystem).downcase
  # ...

was updated to

confine :true => begin
  os = Puppet.runtime[:facter].value('os.name').downcase
  # ...

See
puppetlabs/puppet@82cef23 for Puppet 8 change.

Relates to #38

@alexjfisher alexjfisher requested a review from a team as a code owner March 15, 2023 12:28
In Puppet 8, core providers are being confined using facts fetched using
'dot-notation'. We need to support this style of lookup in our stub
implementation.

For example in `lib/puppet/provider/service/init.rb`

```ruby
confine :true => begin
  os = Puppet.runtime[:facter].value(:operatingsystem).downcase
  # ...
```

was updated to

```ruby
confine :true => begin
  os = Puppet.runtime[:facter].value('os.name').downcase
  # ...
```

See
puppetlabs/puppet@82cef23 for Puppet 8 change.

Relates to puppetlabs#38
@@ -8,7 +8,11 @@ def initialize
end

def value(fact_name)
@facts[fact_name.to_s]
begin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so used to Ruby 2.5+ where you can write:

def
  @facts.dig(*fact_name.to_s.split('.'))
rescue TypeError
  nil
end

But this gem doesn't declare to be Ruby 2.5+ so I think your current code is fine.

Copy link

@jhoblitt jhoblitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm excited to be able to use this.

@chelnak chelnak merged commit d8a362b into puppetlabs:main Mar 15, 2023
@alexjfisher alexjfisher deleted the facter_impl_dot_notation branch March 15, 2023 17:51
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.

5 participants