Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaludy committed Jan 27, 2021
1 parent e48f1db commit 620109e
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 26 deletions.
14 changes: 7 additions & 7 deletions lib/puppet/provider/ipa_group_membership/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

# In this case we need to be pretty different about how we handle group memberships
# because they are special, so we aren't using a cache here
def read_instance(use_cache: true)
# TODO read from a "groups cache"
def read_instance(*)
# TODO: read from a "groups cache"
body = {
'id' => 0,
'method' => 'group_find/1',
Expand Down Expand Up @@ -45,10 +45,10 @@ def read_instance(use_cache: true)

# if we are trying to delete the instance and all of the memberships are gone, then tell
# Puppet that its gone
if (resource[:ensure] == :absent &&
(instance[:groups].nil? || instance[:groups] == :absent) &&
(instance[:users].nil? || instance[:users] == :absent) &&
(instance[:services].nil? || instance[:services] == :absent))
if resource[:ensure] == :absent &&
(instance[:groups].nil? || instance[:groups] == :absent) &&
(instance[:users].nil? || instance[:users] == :absent) &&
(instance[:services].nil? || instance[:services] == :absent)
instance = nil
end
end
Expand All @@ -57,7 +57,6 @@ def read_instance(use_cache: true)
instance
end


# this method should check resource[:ensure]
# if it is :present this method should create/update the instance using the values
# in resource[:xxx] (these are the desired state values)
Expand All @@ -74,6 +73,7 @@ def flush_instance
else
'group_add_member/1'
end

body = {
'id' => 0,
'method' => method,
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/ipa_user/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def read_instance(use_cache: true)
# special handling for custom ldap attributes
if resource[:ldap_attributes]
# only keep the LDAP attributes in the instance that are specified on the resource
instance[:ldap_attributes].select! do |attr_key, attr_value|
instance[:ldap_attributes].select! do |attr_key, _attr_value|
resource[:ldap_attributes].key?(attr_key)
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/ipa_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
validate do |value|
PuppetX::Encore::Ipa::TypeUtils.validate_type(name, value, Integer)
unless @resource[:group_type] == :posix
raise ArgumentError, "gid is only allowed to be specified when creating POSIX groups."
raise ArgumentError, 'gid is only allowed to be specified when creating POSIX groups.'
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/type/ipa_group_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
autorequire(:ipa_group) do
grp = [@parameters[:group].should]
grp += @parameters[:groups].should if @parameters[:groups] && @parameters[:groups].should
grp
end

autorequire(:ipa_user) do
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet_x/encore/ipa.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'puppet_x'

module PuppetX
module Encore
module Ipa
end
end
# module for encore
module PuppetX::Encore
end
# module for ipa
module PuppetX::Encore::Ipa
end
1 change: 0 additions & 1 deletion lib/puppet_x/encore/ipa/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'puppet_x/encore/ipa'
require 'puppet'


module PuppetX::Encore::Ipa
# Client class for HTTP calls
class HTTPClient
Expand Down
24 changes: 18 additions & 6 deletions lib/puppet_x/encore/ipa/list_property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,37 @@
require 'puppet_x/encore/ipa'

module PuppetX::Encore::Ipa
# This class implements an array/list property and handles things like sorting
# for you so we can properly compute the difference between the requested list in
# PuppetDSL and the "actual" list read in from the provider.
#
# This class also helps by implementing the "membership" concept meaning
# whether specified members should be considered the **complete list**.
# :inclusive = the list given in PuppetDSL should be the complete list
# :minimum = the list given in PuppetDSL should be contained in the list, but is allowed to have extras
#
# To determine what type of "membership" we read from another type's property
# defined by the membership() method, default is :membership. If you want to use
# a different property name for your membership determination just override this
# method in your newproperty() definition block.
class ListProperty < Puppet::Property

def membership
:membership
end

def inclusive?
@resource[membership] == :inclusive
end

# sort the array so we can compute the difference correct and order doesn't matter

def sort_array(a)
(a.nil?) ? [] : make_array(a).sort
# sort the array so we can compute the difference correct and order doesn't matter
a.nil? ? [] : make_array(a).sort
end

def make_array(a)
a.is_a?(Array) ? a : [a]
end

def should
members = make_array(super)

Expand Down
6 changes: 2 additions & 4 deletions lib/puppet_x/encore/ipa/type_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
# Encore module
module PuppetX::Encore::Ipa::TypeUtils
def validate_type(attr, value, type)
unless value.is_a?(type)
raise ArgumentError, "#{attr} is expected to be an #{type.name}, given: #{value.class.name}"
end
raise ArgumentError, "#{attr} is expected to be an #{type.name}, given: #{value.class.name}" unless value.is_a?(type)
end
module_function :validate_type

def validate_string(attr, value)
validate_type(attr, value, String)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/puppet/provider/ipa_kinit/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
provider: described_class.name,
name: name,
realm: 'EXPECTED.DOMAIN.TLD',
password: 'AdminPassword123',
}
end

Expand Down Expand Up @@ -98,6 +99,7 @@
provider: described_class.name,
name: name,
ensure: :absent,
password: 'AdminPassword123',
}
end

Expand Down
3 changes: 2 additions & 1 deletion spec/unit/puppet/type/ipa_kinit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
expect(type_instance[:ensure]).to eq(:present)
end
it 'default to :present' do
expect(Puppet::Type.type(:ipa_kinit).new(name: name)[:ensure]).to eq(:present)
type = Puppet::Type.type(:ipa_kinit).new(name: name, password: 'Password123')
expect(type[:ensure]).to eq(:present)
end
end
end

0 comments on commit 620109e

Please sign in to comment.