fetch the correct hiera information based on the node env (#12944)

For https://github.com/fleetdm/fleet/issues/12897
This commit is contained in:
Roberto Dip 2023-07-26 12:04:11 -03:00 committed by GitHub
parent 02f70eb528
commit 833c851706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -0,0 +1 @@
* Allow the puppet module to read different Fleet URL/token combinations for different environments

View File

@ -25,13 +25,6 @@ module Puppet::Util
end
def initialize
node_name = Puppet[:node_name_value]
node = Puppet::Node.new(node_name)
compiler = Puppet::Parser::Compiler.new(node)
scope = Puppet::Parser::Scope.new(compiler)
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {}, nil)
@host = Puppet::Pops::Lookup.lookup('fleetdm::host', nil, '', false, nil, lookup_invocation)
@token = Puppet::Pops::Lookup.lookup('fleetdm::token', nil, '', false, nil, lookup_invocation)
@cache = {}
@cache_mutex = Mutex.new
end
@ -114,6 +107,15 @@ module Puppet::Util
private
def req(method: :get, path: '', body: nil, headers: {}, cached: false)
node_name = Puppet[:node_name_value]
node = Puppet::Node.new(node_name)
node.environment = Puppet.lookup(:current_environment).name.to_s
compiler = Puppet::Parser::Compiler.new(node)
scope = Puppet::Parser::Scope.new(compiler)
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {}, nil)
host = Puppet::Pops::Lookup.lookup('fleetdm::host', nil, '', false, nil, lookup_invocation)
token = Puppet::Pops::Lookup.lookup('fleetdm::token', nil, '', false, nil, lookup_invocation)
if cached
@cache_mutex.synchronize do
unless @cache[path].nil?
@ -123,7 +125,7 @@ module Puppet::Util
end
out = { 'error' => '' }
uri = URI.parse("#{@host}#{path}")
uri = URI.parse("#{host}#{path}")
uri.path.squeeze! '/'
uri.path.chomp! '/'
@ -139,7 +141,7 @@ module Puppet::Util
throw "HTTP method #{method} not implemented"
end
headers['Authorization'] = "Bearer #{@token}"
headers['Authorization'] = "Bearer #{token}"
headers.each { |key, value| request[key] = value }
request.body = body.to_json if body

View File

@ -1,6 +1,6 @@
{
"name": "fleetdm-fleetdm",
"version": "0.2.1",
"version": "0.2.2",
"author": "Fleet Device Management Inc",
"summary": "MDM management and profile assignment using FleetDM",
"license": "proprietary",