Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/puppet/indirector/file_bucket_file/rest.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'uri'
require_relative '../../../puppet/indirector/rest'
require_relative '../../../puppet/file_bucket/file'

Expand All @@ -9,7 +10,8 @@ class Rest < Puppet::Indirector::REST

def head(request)
session = Puppet.lookup(:http_session)
api = session.route_to(:puppet)
url = URI::HTTPS.build(host: request.server, port: request.port) if request.server
api = session.route_to(:puppet, url: url)
api.head_filebucket_file(
request.key,
environment: request.environment.to_s,
Expand All @@ -23,7 +25,8 @@ def head(request)

def find(request)
session = Puppet.lookup(:http_session)
api = session.route_to(:puppet)
url = URI::HTTPS.build(host: request.server, port: request.port) if request.server
api = session.route_to(:puppet, url: url)
_, filebucket_file = api.get_filebucket_file(
request.key,
environment: request.environment.to_s,
Expand All @@ -40,7 +43,8 @@ def find(request)

def save(request)
session = Puppet.lookup(:http_session)
api = session.route_to(:puppet)
url = URI::HTTPS.build(host: request.server, port: request.port) if request.server
api = session.route_to(:puppet, url: url)
api.put_filebucket_file(
request.key,
body: request.instance.render,
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/indirector/file_bucket_file/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,32 @@
expect{described_class.indirection.save(file_bucket_file, dest_path)}.to raise_error(Net::HTTPError, "Error 503 on SERVER: server unavailable")
end
end

context 'when the request URI contains an explicit server' do
let(:server_uri) { %r{https://xanadu:8141/puppet/v3/file_bucket_file} }

describe '#head' do
it 'routes the request to the server in the filebucket URI' do
stub_request(:head, server_uri)

described_class.indirection.head(file_bucket_path, :bucket_path => file_bucket_file.bucket_path)
end
end

describe '#find' do
it 'routes the request to the server in the filebucket URI' do
stub_request(:get, server_uri).to_return(status: 200, headers: {'Content-Type' => 'application/octet-stream'})

described_class.indirection.find(source_path, :bucket_path => nil)
end
end

describe '#save' do
it 'routes the request to the server in the filebucket URI' do
stub_request(:put, server_uri)

described_class.indirection.save(file_bucket_file, dest_path)
end
end
end
end