Skip to content

Commit

Permalink
Merge pull request #74 from m0dular/SUP-3397-admin_membership
Browse files Browse the repository at this point in the history
(SUP-3397) Do not add/remove the admin user
  • Loading branch information
m0dular authored Mar 21, 2023
2 parents ab85768 + 0bdd435 commit 38f7591
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/puppet/provider/influxdb_org/influxdb_org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def update(context, name, should)
to_add = should_members - cur_members.map { |member| member['name'] }

to_remove.each do |user|
next if user == 'admin'
if user == 'admin'
context.warning('Unable to remove the admin user. Please remove it from your members[] entry.')
next
end

user_id = id_from_name(@user_map, user)
if user_id
Expand All @@ -89,6 +92,12 @@ def update(context, name, should)
end

to_add.each do |user|
# Admin is already an owner of all orgs
if user == 'admin'
context.warning('Unable to add the admin user. Please remove it from your members[] entry.')
next
end

user_id = id_from_name(@user_map, user)
if user_id
body = { name: user, id: user_id }
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
unless $host == $facts['networking']['fqdn'] or $host == $facts['networking']['hostname'] or $host == 'localhost' {
fail(
@("MSG")
Unable to manage InfluxDB installation on host: ${host}.
Unable to manage InfluxDB installation on host: ${host}.
Management of repos, packages and services etc is only possible on the local host (${facts['networking']['fqdn']}).
| MSG
)
Expand Down
21 changes: 21 additions & 0 deletions spec/unit/puppet/provider/influxdb_org/influxdb_org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@
end
end

context 'with the admin user' do
let(:should_hash) do
{
name: 'puppetlabs',
members: ['admin']
}
end

it 'does not add the admin user' do
provider.instance_variable_set('@org_hash', [{ 'name' => 'puppetlabs', 'id' => 123 }])
patch_args = ['/api/v2/orgs/123', JSON.dump({ description: nil })]

expect(context).to receive(:debug).with("Updating '#{should_hash[:name]}' with #{should_hash.inspect}")
expect(context).to receive(:warning).with('Unable to add the admin user. Please remove it from your members[] entry.')
expect(provider).to receive(:influx_patch).with(*patch_args)
expect(provider).not_to receive(:influx_post)

provider.update(context, should_hash[:name], should_hash)
end
end

describe '#delete' do
it 'deletes resources' do
provider.instance_variable_set('@org_hash', [{ 'name' => 'puppetlabs', 'id' => 123 }])
Expand Down

0 comments on commit 38f7591

Please sign in to comment.