Skip to content

Commit

Permalink
Allow mapped_group_attributes to be removed by defaulting to absent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock authored May 3, 2024
1 parent 7d22db2 commit e179a6b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
12 changes: 10 additions & 2 deletions lib/puppet/provider/keycloak_ldap_mapper/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def self.instances
else
property.to_s.tr('_', '.')
end
next unless d['config'].key?(key)
unless d['config'].key?(key)
component[property.to_sym] = :absent
next
end

value = d['config'][key][0]
if !!value == value # rubocop:disable Style/DoubleNegation
Expand Down Expand Up @@ -130,6 +133,7 @@ def create
data[:config] = {}
type_properties.each do |property|
next unless resource[property.to_sym]
next if resource[property.to_sym].to_s == 'absent'

key = if property == :ldap_attribute && resource[:type] == 'full-name-ldap-mapper'
'ldap.full.name.attribute'
Expand Down Expand Up @@ -194,7 +198,11 @@ def flush
end
next unless type_supported_properties(resource[:type]).include?(property.to_sym)

data[:config][key] = [resource[property.to_sym]]
value = [resource[property.to_sym]]
if @property_flush[property.to_sym].to_s == 'absent'
value = ['']
end
data[:config][key] = value
end

t = Tempfile.new('keycloak_component')
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/type/keycloak_ldap_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@

newproperty(:mapped_group_attributes) do
desc 'mapped.group.attributes, only for `type` of `group-ldap-mapper`'
defaultto(:absent)
end

newproperty(:groups_ldap_filter) do
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@
],
"pdk-version": "2.7.1",
"template-url": "https://github.com/treydock/pdk-templates.git#master",
"template-ref": "heads/master-0-g5a59870"
"template-ref": "heads/master-0-g15e3149"
}
9 changes: 6 additions & 3 deletions spec/acceptance/3_ldap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class { 'keycloak': }
roles_ldap_filter => '(!(cn=P*))',
}
keycloak_ldap_mapper { 'group for LDAP on test':
type => 'group-ldap-mapper',
groups_dn => 'ou=Groups,dc=example,dc=com',
groups_ldap_filter => '(cn=P*)',
type => 'group-ldap-mapper',
groups_dn => 'ou=Groups,dc=example,dc=com',
groups_ldap_filter => '(cn=P*)',
mapped_group_attributes => 'ou',
}
PUPPET_PP

Expand Down Expand Up @@ -92,6 +93,7 @@ class { 'keycloak': }
expect(d['providerId']).to eq('group-ldap-mapper')
expect(d['config']['groups.dn']).to eq(['ou=Groups,dc=example,dc=com'])
expect(d['config']['groups.ldap.filter']).to eq(['(cn=P*)'])
expect(d['config']['mapped.group.attributes']).to eq(['ou'])
end
end
end
Expand Down Expand Up @@ -174,6 +176,7 @@ class { 'keycloak': }
expect(d['providerId']).to eq('group-ldap-mapper')
expect(d['config']['groups.dn']).to eq(['ou=Groups,dc=example,dc=com'])
expect(d['config']['groups.ldap.filter']).to eq(['(cn=P0*)'])
expect(d['config']['mapped.group.attributes']).to be_nil
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/nodesets/el8.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
HOSTS:
rocky-8:
el8:
roles:
- agent
platform: el-8-x86_64
hypervisor: docker
image: almalinux:8
image: rockylinux:8
docker_preserve_image: true
docker_cmd:
- '/usr/sbin/init'
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/nodesets/el9.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
HOSTS:
almalinux-9:
el9:
roles:
- agent
platform: el-9-x86_64
hypervisor: docker
image: almalinux:9
image: rockylinux:9
docker_preserve_image: true
docker_cmd:
- '/usr/sbin/init'
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/puppet/type/keycloak_ldap_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@
end

defaults = {
read_only: :true
read_only: :true,
mapped_group_attributes: :absent
}

describe 'basic properties' do
Expand Down

0 comments on commit e179a6b

Please sign in to comment.