Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

puppet-lint-top_scope_facts-check

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

puppet-lint-top_scope_facts-check

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status Gem Total Downloads Latest Downloads

A puppet-lint plugin to check you are not using top scope fact variables like $::operatingsystem. You should use the $facts hash like $facts['operatingsystem'] instead.

This linter will not covert from the legacy facts like $facts['operatingsystem'] to $facts['os']['name']. The legacy facts linter can be used to accomplish that.

Overview

In puppet 2.x facts were top scope variables and accessed as $operatingsystem or $::operatingsystem, the latter being far more common especially because the linter enforces that convention.

Puppet 3.5 added a $facts hash to access facts like $facts['operatingsystem']. This works if you set trusted_node_data = true but it was not enabled by default. Puppet 4 has it enabled by default.

This puppet-lint plugin will help find facts referenced as top scope variables and replace them with the $facts hash to improve readability of code. Its only useful if you're running puppet 3.5 to 3.8 with trusted_node_data enabled, or if you're running puppet 4.

Limitations

  • It only finds facts using the top-scope: ie it will find $::operatingsystem but not $operatingsystem.
  • It assumes all top scope variables are facts. If you have top scope variables that aren't facts you should configure the linter to ignore them.

Installing

From the command line

$ gem install puppet-lint-top_scope_facts-check

In a Gemfile

gem 'puppet-lint-top_scope_facts-check', :require => false

Checks

What you have done
$service_name = $::operatingsystem {
  'CentOS' => 'httpd',
  'Debian' => 'apache2',
}
What you should have done
$service_name = $facts['operatingsystem'] {
  'CentOS' => 'httpd',
  'Debian' => 'apache2',
}
Configuring the check

You can whitelist top scope variables to ignore via the Rake task. You should insert the following line to your Rakefile.

PuppetLint.configuration.top_scope_variables = ['location', 'role']
Disabling the check

To disable this check, you can add --no-top_scope_facts to your puppet-lint command line.

$ puppet-lint --no-top_scope_facts path/to/file.pp

Alternatively, if you’re calling puppet-lint via the Rake task, you should insert the following line to your Rakefile.

PuppetLint.configuration.send('disable_top_scope_facts')

License

Copyright 2016 Mark McKinstry

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

FAQs

Package last updated on 27 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc