mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
fetch the correct hiera information based on the node env (#12944)
For https://github.com/fleetdm/fleet/issues/12897
This commit is contained in:
parent
02f70eb528
commit
833c851706
1
changes/12897-puppet-envs
Normal file
1
changes/12897-puppet-envs
Normal file
@ -0,0 +1 @@
|
||||
* Allow the puppet module to read different Fleet URL/token combinations for different environments
|
@ -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
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user