---
lib/aeolus_image/oauth_client.rb | 45 ++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
create mode 100644 lib/aeolus_image/oauth_client.rb
diff --git a/lib/aeolus_image/oauth_client.rb b/lib/aeolus_image/oauth_client.rb
new file mode 100644
index 0000000..54836f2
--- /dev/null
+++ b/lib/aeolus_image/oauth_client.rb
@@ -0,0 +1,45 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'oauth'
+
+# Monkey-patch ActiveResource to allow us to merge our OAuth headers in.
+module OAuthClient
+ ActiveResource::Connection.class_eval do
+
+ def request_with_oauth(method, path, *arguments)
+ result =
ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
+ payload[:method] = method
+ payload[:request_uri] =
"#{site.scheme}://#{site.host}:#{site.port}#{path}"
+
+ # FIXME: Obviously, these values should not be hardcoded
+ oauth_consumer = OAuth::Consumer.new('mock-key', 'mock-secret',
:site => 'http://127.0.0.1:8075/imagefactory')
+ token = OAuth::AccessToken.new(oauth_consumer)
+
+ base_request = oauth_consumer.create_signed_request(method, path, token, {},
*arguments)
+ payload[:result] = http.request(base_request)
+ end
+ # FIXME: Add the error-handling stuff that OAuth does:
+ #
https://github.com/oauth/oauth-ruby/blob/master/lib/oauth/consumer.rb#L165
+ handle_response(result)
+ rescue Timeout::Error => e
+ raise TimeoutError.new(e.message)
+ rescue OpenSSL::SSL::SSLError => e
+ raise SSLError.new(e.message)
+ end
+ #
+ alias_method_chain :request, :oauth
+
+ end
+end
--
1.7.6.4