1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Add User-Agent header to the marketplace client

This commit is contained in:
Daniel Molina 2012-06-22 12:13:50 +02:00
parent 22a8915b1a
commit d0c4564343
3 changed files with 22 additions and 9 deletions

View File

@ -37,6 +37,8 @@ require 'cli/cli_helper'
require 'rubygems'
require 'json'
USER_AGENT = "CLI"
#
# Options
#
@ -113,7 +115,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
client = Market::ApplianceClient.new(
options[:username],
options[:password],
options[:server])
options[:server],
USER_AGENT)
response = client.list
@ -142,7 +145,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
client = Market::ApplianceClient.new(
options[:username],
options[:password],
options[:server])
options[:server],
USER_AGENT)
response = client.create(File.read(args[0]))
@ -165,7 +169,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
client = Market::ApplianceClient.new(
options[:username],
options[:password],
options[:server])
options[:server],
USER_AGENT)
response = client.show(args[0])

View File

@ -19,12 +19,14 @@ require 'cloud/CloudClient'
module Market
class Client
def initialize(username, password, url)
def initialize(username, password, url, user_agent="Ruby")
@username = username
@password = password
url ||= 'http://localhost:9292/'
url ||= 'http://localhost:9292/'
@uri = URI.parse(url)
@user_agent = "OpenNebula 3.5.80 (#{user_agent})"
end
def get(path)
@ -47,6 +49,8 @@ module Market
req.basic_auth @username, @password
end
req['User-Agent'] = @user_agent
res = CloudClient::http_start(@uri, @timeout) do |http|
http.request(req)
end
@ -57,8 +61,8 @@ module Market
class ApplianceClient < Client
def initialize(user, password, url)
super(user, password, url)
def initialize(user, password, url, agent)
super(user, password, url, agent)
end
def list

View File

@ -17,11 +17,14 @@
require 'marketplace/marketplace_client'
module SunstoneMarketplace
USER_AGENT = "Sunstone"
def get_appliance_pool
client = Market::ApplianceClient.new(
@config[:marketplace_username],
@config[:marketplace_password],
@config[:marketplace_url])
@config[:marketplace_url],
USER_AGENT)
response = client.list
@ -37,7 +40,8 @@ module SunstoneMarketplace
client = Market::ApplianceClient.new(
@config[:marketplace_username],
@config[:marketplace_password],
@config[:marketplace_url])
@config[:marketplace_url],
USER_AGENT)
response = client.show(app_id)