7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2023-06-14 - Release 0.8.0

### Summary

- Updated for Ruby 3.x
- Removal of deprecations

## 2021-03-21 - Release 0.7.5

### Summary
Expand Down
43 changes: 19 additions & 24 deletions lib/puppet/face/node_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
options = args.last

if options[:import]
fail('Choose import or export') if options[:export]
raise('Choose import or export') if options[:export]

'Success' if classifier.import_hierarchy(read_import(options[:import]))
else
groups = classifier.get_groups
groups = classifier.get_groups

if args.length == 2
output << groups.select { |g| g['name'] == args.first }
elsif args.length == 1
output << groups
else
fail("wrong number of arguments (#{args.length-1} for 1)")
raise("wrong number of arguments (#{args.length - 1} for 1)")
end
if options[:export]
output.flatten.to_json
Expand All @@ -54,7 +54,7 @@
case output
when Hash
if output.length == 0
fail('No groups found')
raise('No groups found')
elsif output.length == 1
JSON.pretty_generate output.values[0]
else
Expand Down Expand Up @@ -132,7 +132,7 @@
output.flatten
end

when_rendering :console do |output, nodename, options|
when_rendering :console do |output, _nodename, options|
if options[:explain] == true
JSON.pretty_generate output.first['match_explanations']
else
Expand All @@ -156,7 +156,6 @@

if options[:node_group]
'Success' if classifier.pin_node(nodename, options[:node_group])
else
end
end

Expand Down Expand Up @@ -196,12 +195,12 @@
else
PuppetX::Node_manager::Common.hashify_group_array(output.flatten.first['nodes'])
end
else
'Success' if classifier.unpin_node(nodename, options[:node_group])
elsif classifier.unpin_node(nodename, options[:node_group])
'Success'
end
end

when_rendering :console do |output, nodename, options|
when_rendering :console do |output, _nodename, _options|
if output.is_a?(String)
output
else
Expand All @@ -223,20 +222,18 @@
elsif args.length == 1
output << environments
else
fail("wrong number of arguments (#{args.length-1} for 1)")
raise("wrong number of arguments (#{args.length - 1} for 1)")
end
output.flatten
end

when_rendering :console do |output|
if output.length > 1
output
elsif output.first.class == Hash && output.first.has_key?('sync_succeeded')
output.first['sync_succeeded'].to_s
else
if output.first.class == Hash && output.first.has_key?('sync_succeeded')
output.first['sync_succeeded'].to_s
else
fail('Environment doesn\'t exist.')
end
raise('Environment doesn\'t exist.')
end
end
end
Expand All @@ -245,9 +242,9 @@ def check_facts(file, options)
if file && options[:explain]
begin
contents = YAML.load_file(file)
contents ||= JSON.parse(File.read file)
contents ||= JSON.parse(File.read(file))
rescue
fail "Could not file file '#{file}'"
raise "Could not file file '#{file}'"
else
contents
end
Expand All @@ -257,13 +254,11 @@ def check_facts(file, options)
end

def read_import(file)
begin
contents = JSON.parse(File.read file)
rescue
fail "Could not read file '#{file}'"
else
contents
end
contents = JSON.parse(File.read(file))
rescue
raise "Could not read file '#{file}'"
else
contents
end

def cap_class_name(k)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/feature/puppetclassify.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require 'puppet/util/feature'

Puppet.features.add(:puppetclassify, :libs => ['puppetclassify'])
Puppet.features.add(:puppetclassify, libs: ['puppetclassify'])
77 changes: 37 additions & 40 deletions lib/puppet/provider/node_group/https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
require 'puppet_x/node_manager/common'

Puppet::Type.type(:node_group).provide(:https) do
defaultfor :feature => :posix
defaultfor feature: :posix

def initialize(value={})
def initialize(value = {})
super(value)
@property_flush = {
'state' => {},
'attrs' => {},
}
end


def self.classifier
@classifier ||= initialize_client
end
Expand All @@ -25,24 +24,24 @@ def self.initialize_client
# Decided to use override_environment instead
def self.friendly_name
{
:classes => 'classes',
:environment => 'environment',
:environment_trumps => 'override_environment',
:id => 'id',
:name => 'name',
:parent => 'parent',
:rule => 'rule',
:variables => 'variables',
:description => 'description',
:config_data => 'data',
classes: 'classes',
environment: 'environment',
environment_trumps: 'override_environment',
id: 'id',
name: 'name',
parent: 'parent',
rule: 'rule',
variables: 'variables',
description: 'description',
config_data: 'data',
}
end

def self.instances
$ngs = classifier.get_groups
$ngs.collect do |group|
ngs_hash = {}
friendly_name.each do |property,friendly|
friendly_name.each do |property, friendly|
# Replace parent ID with string name
if friendly == 'parent'
gindex = get_name_index_from_id(group[property.to_s])
Expand All @@ -61,7 +60,7 @@ def self.instances
def self.prefetch(resources)
ngs = instances
resources.keys.each do |group|
if provider = ngs.find{ |g| g.name == group }
if provider = ngs.find { |g| g.name == group }
resources[group].provider = provider
end
end
Expand All @@ -76,7 +75,7 @@ def exists?
def create
@noflush = true
# Only passing parameters that are given
send_data = Hash.new
send_data = {}
@resource.properties.each do |property|
next if [:ensure].include? property.name
key = property.to_s
Expand All @@ -92,8 +91,8 @@ def create
# Ensure environment_trumps is a boolean
send_data['environment_trumps'] = Puppet::Coercion.boolean(send_data['environment_trumps']) if send_data['environment_trumps']

send_data['parent'] = '00000000-0000-4000-8000-000000000000' if !send_data['parent']
unless send_data['parent'] =~ /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/
send_data['parent'] = '00000000-0000-4000-8000-000000000000' unless send_data['parent']
unless %r{^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$}.match?(send_data['parent'])
gindex = get_id_index_from_name(send_data['parent'])
if gindex
send_data['parent'] = $ngs[gindex]['id']
Expand All @@ -109,10 +108,9 @@ def create
end
end
# Add placeholder for $ngs lookups
$ngs << { "name" => send_data['name'], "id" => resp }
$ngs << { 'name' => send_data['name'], 'id' => resp }

exists? ? (return true) : (return false)

end

def destroy
Expand All @@ -125,7 +123,7 @@ def destroy

# If ID is given, translate to string name
def parent
if @resource[:parent] =~ /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/
if %r{^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$}.match?(@resource[:parent])
gindex = self.class.get_name_index_from_id(@resource[:parent])
$ngs[gindex]['name']
else
Expand All @@ -147,10 +145,10 @@ def rule
@property_hash[:rule].nil? ? [''] : @property_hash[:rule]
end

friendly_name.each do |property,friendly|
friendly_name.each do |property, friendly|
define_method "#{friendly}=" do |value|
if property == :parent
if value =~ /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/
if %r{^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$}.match?(value)
@property_flush['attrs'][property.to_s] = value
else
gindex = $ngs.index { |i| i['name'] == value }
Expand All @@ -160,18 +158,18 @@ def rule
elsif [:variables, :classes, :config_data].include?(property)
@property_flush['attrs'][property.to_s] = add_nulls(@property_hash[friendly.to_sym], value)
# For logging return to original intended value
@resource[friendly.to_sym] = value.select { |k,v| v != nil }
@resource[friendly.to_sym] = value.select { |_k, v| !v.nil? }
else
# The to_json function needs to recognize
# booleans true/false, not symbols :true/false
case value
when :true
@property_flush['attrs'][property.to_s] = true
when :false
@property_flush['attrs'][property.to_s] = false
else
@property_flush['attrs'][property.to_s] = value
end
@property_flush['attrs'][property.to_s] = case value
when :true
true
when :false
false
else
value
end
end
@property_hash[friendly.to_sym] = value
end
Expand All @@ -197,24 +195,23 @@ def get_id_index_from_name(name)
end

def add_nulls(current, new)
if current.is_a?(Hash)
allkeys = (current.keys + new.keys).uniq
else
allkeys = new.keys
end
newhash = Hash.new
allkeys = if current.is_a?(Hash)
(current.keys + new.keys).uniq
else
new.keys
end
newhash = {}

allkeys.each do |k|
if new[k].is_a?(Hash)
# Push forward an empty hash if nothing is there
_current = current.is_a?(Hash) ? current[k] : {}
newhash[k] = add_nulls(_current, new[k])
else
newhash[k] = new[k]
newhash[k] = new[k]
end
end

newhash
end

end
Loading