Skip to content

Commit

Permalink
Add support for manage roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Linke committed Oct 23, 2023
1 parent b8cdd65 commit ff4e06d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/puppet/provider/nexus_role/nexus_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ def initialize
def keys_to_snake_case(hash)
hash.transform_keys do |key|
key.gsub(%r{([A-Z]+)([A-Z][a-z])}, '\1_\2')
.gsub(%r{([a-z\d])([A-Z])}, '\1_\2')
.downcase
.to_sym
.gsub(%r{([a-z\d])([A-Z])}, '\1_\2')
.downcase
.to_sym
end
end

# convert keys of the given hash to camelCase
def keys_to_camelcase(hash)
hash.transform_keys do |key|
key.to_s
.gsub(%r{(?:_+)([a-z])}) { Regexp.last_match(1).upcase }
.gsub(%r{(\A|\s)([A-Z])}) { Regexp.last_match(1) + Regexp.last_match(2).downcase }
.to_sym
.gsub(%r{(?:_+)([a-z])}) { Regexp.last_match(1).upcase }
.gsub(%r{(\A|\s)([A-Z])}) { Regexp.last_match(1) + Regexp.last_match(2).downcase }
.to_sym
end
end

# Return all existing roles as resources
def get(context)
res = context.transport.get_request(context, 'security/roles')
context.err(res.body) unless res.success?
Puppet::Util::Json.load(res.body).map { |role|
keys_to_snake_case(role.merge({'ensure' => 'present'}))
}
Puppet::Util::Json.load(res.body).map do |role|
keys_to_snake_case(role.merge({ 'ensure' => 'present' }))
end
end

# Creates new role if they not exist yet
Expand Down

0 comments on commit ff4e06d

Please sign in to comment.