Skip to content

Commit

Permalink
rubocop: autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed May 12, 2023
1 parent ee02529 commit a9db891
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 169 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

Expand Down
83 changes: 38 additions & 45 deletions lib/puppet/provider/puppet_auth/augeas.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# coding: utf-8
# frozen_string_literal: true

# Alternative Augeas-based providers for Puppet
#
# Copyright (c) 2012 Raphaël Pinson
# Licensed under the Apache License, Version 2.0

raise("Missing augeasproviders_core dependency") if Puppet::Type.type(:augeasprovider).nil?
Puppet::Type.type(:puppet_auth).provide(:augeas, :parent => Puppet::Type.type(:augeasprovider).provider(:default)) do
raise('Missing augeasproviders_core dependency') if Puppet::Type.type(:augeasprovider).nil?

Puppet::Type.type(:puppet_auth).provide(:augeas, parent: Puppet::Type.type(:augeasprovider).provider(:default)) do
desc "Uses Augeas API to update a rule in Puppet's auth.conf."

INS_ALIASES = {
"first allow" => "path[allow][1]",
"last allow" => "path[allow][last()]",
"first deny" => "path[count(allow)=0][1]",
"last deny" => "path[count(allow)=0][last()]",
}
'first allow' => 'path[allow][1]',
'last allow' => 'path[allow][last()]',
'first deny' => 'path[count(allow)=0][1]',
'last deny' => 'path[count(allow)=0][last()]',
}.freeze

default_file { File.join(Puppet[:confdir], 'auth.conf') }

lens { 'Puppet_Auth.lns' }

confine :feature => :augeas
confine feature: :augeas

resource_path do |resource|
path = resource[:path]
Expand All @@ -29,7 +31,7 @@
def self.instances
resources = []
augopen do |aug|
settings = aug.match("$target/path")
settings = aug.match('$target/path')

settings.each do |node|
# Set $resource for getters
Expand All @@ -42,12 +44,12 @@ def self.instances
allow = attr_aug_reader_allow(aug)
allow_ip = attr_aug_reader_allow_ip(aug)
authenticated = attr_aug_reader_authenticated(aug)
name = (path_regex == :false) ? "Auth rule for #{path}" : "Auth rule matching #{path}"
entry = {:ensure => :present, :name => name,
:path => path, :path_regex => path_regex,
:environments => environments, :methods => methods,
:allow => allow, :allow_ip => allow_ip,
:authenticated => authenticated}
name = path_regex == :false ? "Auth rule for #{path}" : "Auth rule matching #{path}"
entry = { ensure: :present, name: name,
path: path, path_regex: path_regex,
environments: environments, methods: methods,
allow: allow, allow_ip: allow_ip,
authenticated: authenticated }
resources << new(entry) if entry[:path]
end
end
Expand All @@ -65,21 +67,17 @@ def create
allow_ip = resource[:allow_ip]
authenticated = resource[:authenticated]
augopen! do |aug|
if before or after
if before || after
expr = before || after
if INS_ALIASES.has_key?(expr)
expr = INS_ALIASES[expr]
end
aug.insert("$target/#{expr}", "path", before ? true : false)
expr = INS_ALIASES[expr] if INS_ALIASES.key?(expr)
aug.insert("$target/#{expr}", 'path', before ? true : false)
aug.set("$target/path[.='']", apath)
end

aug.set(resource_path, apath)
# Refresh $resource
setvars(aug)
if apath_regex == :true
aug.set('$resource/operator', "~")
end
aug.set('$resource/operator', '~') if apath_regex == :true
attr_aug_writer_environments(aug, environments)
attr_aug_writer_methods(aug, methods)
attr_aug_writer_allow(aug, allow)
Expand All @@ -89,33 +87,28 @@ def create
end

attr_aug_accessor(:environments,
:label => 'environment',
:type => :array,
:sublabel => :seq,
:purge_ident => true
)
label: 'environment',
type: :array,
sublabel: :seq,
purge_ident: true)

attr_aug_accessor(:methods,
:label => 'method',
:type => :array,
:sublabel => :seq,
:purge_ident => true
)
label: 'method',
type: :array,
sublabel: :seq,
purge_ident: true)

attr_aug_accessor(:allow,
:type => :array,
:sublabel => :seq,
:purge_ident => true
)
type: :array,
sublabel: :seq,
purge_ident: true)

attr_aug_accessor(:allow_ip,
:type => :array,
:sublabel => :seq,
:purge_ident => true
)
type: :array,
sublabel: :seq,
purge_ident: true)

attr_aug_accessor(:authenticated,
:label => 'auth',
:purge_ident => true
)
label: 'auth',
purge_ident: true)
end
28 changes: 15 additions & 13 deletions lib/puppet/type/puppet_auth.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Manages settings in Puppet's auth.conf file
#
# Copyright (c) 2012 Raphaël Pinson
Expand All @@ -10,26 +12,26 @@

def munge_boolean(value)
case value
when true, "true", :true
when true, 'true', :true
:true
when false, "false", :false
when false, 'false', :false
:false
else
fail("munge_boolean only takes booleans")
raise('munge_boolean only takes booleans')
end
end

newparam(:name) do
desc "The name of the resource."
desc 'The name of the resource.'
isnamevar
end

newparam(:path) do
desc "The path for the auth rule."
desc 'The path for the auth rule.'
end

newparam(:path_regex, :boolean => true) do
desc "Whether the path is specified as a regex."
newparam(:path_regex, boolean: true) do
desc 'Whether the path is specified as a regex.'

newvalues(:true, :false)

Expand Down Expand Up @@ -60,11 +62,11 @@ def munge_boolean(value)
- `last deny`, mapping to path[count(allow)=0][last()]`"
end

newproperty(:environments, :array_matching => :all) do
desc "The list of environments the rule applies to."
newproperty(:environments, array_matching: :all) do
desc 'The list of environments the rule applies to.'
end

newproperty(:methods, :array_matching => :all) do
newproperty(:methods, array_matching: :all) do
desc "The list of methods the rule applies to. Possible values are:
- find;
Expand All @@ -73,17 +75,17 @@ def munge_boolean(value)
- destroy."
end

newproperty(:allow, :array_matching => :all) do
newproperty(:allow, array_matching: :all) do
desc "The list of hosts allowed for this rule,
specified by hostname or cername. Regexes are allowed,
as well as the special value `*`."

validate do |val|
raise ArgumentError, "The allow parameter cannot be undef" if val == :undef
raise ArgumentError, 'The allow parameter cannot be undef' if val == :undef
end
end

newproperty(:allow_ip, :array_matching => :all) do
newproperty(:allow_ip, array_matching: :all) do
desc "The list of IPs allowed for this rule.
Requires Puppet 3.0.0 or greater."
end
Expand Down
Loading

0 comments on commit a9db891

Please sign in to comment.