Class: UcloudApi::StorageReseller

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ucloud_api/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(reseller_admin_user = nil, reseller_admin_pass = nil, reseller_user = nil) ⇒ StorageReseller

debug_output $stderr



52
53
54
55
56
# File 'lib/ucloud_api/storage.rb', line 52

def initialize(reseller_admin_user=nil, reseller_admin_pass=nil, reseller_user = nil)
  @reseller_admin = reseller_admin_user || ENV["UCLOUD_STORAGE_RESELLER_ADMIN"]
  @reseller_admin_pass = reseller_admin_pass || ENV["UCLOUD_STORAGE_RESELLER_ADMIN_PASS"]
  @reseller_user = reseller_user || ENV["UCLOUD_STORAGE_RESELLER_USER"]
end

Instance Method Details

#add_user(user, pass) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/ucloud_api/storage.rb', line 70

def add_user user, pass
  auth_url = File.join "https://ssproxy.ucloudbiz.olleh.com", "/auth/v2/#@reseller_user/#{user}"
  #auth_url = "https://api.ucloudbiz.olleh.com/v2/#@reseller_user/#{user}"
  headers = {
    "X-Auth-Admin-User" => @reseller_admin,
    "X-Auth-Admin-Key" => @reseller_admin_pass,
    "X-Auth-User-Key" => pass }      
  self.class.put auth_url, :headers => headers
end

#authObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ucloud_api/storage.rb', line 58

def auth
  auth_url = 'https://api.ucloudbiz.olleh.com/storage/v1/auth'
  headers = {
    "X-Storage-User" => "#@reseller_user:#@reseller_admin",
    "X-Storage-Pass"=> @reseller_admin_pass }
  response = self.class.get auth_url , :headers => headers
  headers = response.headers
  @storage_url = headers["X-Storage-Url"]
  @auth_token = headers["X-Auth-Token"]
  response
end