Skip to content

Commit cc8044a

Browse files
author
Bastian Schmidt
committed
Fixes #38241 - Extend userdata API by MAC address endpoint
Make the Smart Proxy Userdata API endpoint consistent with the Foreman API which was extended in #34887 (46ca3e70).
1 parent 6624f2c commit cc8044a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

modules/templates/templates_userdata_api.rb

+6
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ class Proxy::TemplatesUserdataApi < Sinatra::Base
88
Proxy::Templates::UserdataProxyRequest.new.get(kind, request.env, params)
99
end
1010
end
11+
12+
get "/:mac/:kind" do |kind|
13+
log_halt(500, "Failed to retrieve #{kind} userdata template for #{params.inspect}: ") do
14+
Proxy::Templates::UserdataProxyRequest.new.get([mac, kind], request.env, params)
15+
end
16+
end
1117
end

test/templates/templates_userdata_api_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,11 @@ def test_api_can_ask_for_a_cloud_init_template
2525
assert last_response.ok?, "Last response was ok"
2626
assert_match("A user-data template", last_response.body)
2727
end
28+
29+
def test_api_can_ask_for_a_cloud_init_template_by_mac
30+
stub_request(:get, "#{@foreman_url}/userdata/00:a1:b2:c3:d4:f5/user-data").with(query: {"url" => @template_url}).to_return(:body => 'A user-data template')
31+
get "/00:a1:b2:c3:d4:f5/user-data", {}
32+
assert last_response.ok?, "Last response was ok"
33+
assert_match("A user-data template", last_response.body)
34+
end
2835
end

0 commit comments

Comments
 (0)