Class: Fog::Cloudian::Admin::Real
- Inherits:
-
Object
- Object
- Fog::Cloudian::Admin::Real
- Defined in:
- lib/fog/cloudian/admin.rb,
lib/fog/cloudian/requests/admin/get_user.rb,
lib/fog/cloudian/requests/admin/get_group.rb,
lib/fog/cloudian/requests/admin/create_user.rb,
lib/fog/cloudian/requests/admin/delete_user.rb,
lib/fog/cloudian/requests/admin/update_user.rb,
lib/fog/cloudian/requests/admin/create_group.rb,
lib/fog/cloudian/requests/admin/delete_group.rb,
lib/fog/cloudian/requests/admin/set_password.rb,
lib/fog/cloudian/requests/admin/set_qos_limits.rb,
lib/fog/cloudian/requests/admin/create_credentials.rb
Constant Summary collapse
- QOS_LIMITS_DEFAULTS =
{ userId: '*', # TODO: maybe use 'ALL' instead # groupId: '...', # required storageQuotaKBytes: -1, storageQuotaCount: -1, wlRequestRate: -1, hlRequestRate: -1, wlDataKBytesIn: -1, hlDataKBytesIn: -1, wlDataKBytesOut: -1, hlDataKBytesOut: -1 }
Instance Method Summary collapse
- #create_credentials(user_name, group_name) ⇒ Object
- #create_group(group_name) ⇒ Object
- #create_user(user_name, group_name, user_type = 'User') ⇒ Object
- #delete_group(group_name) ⇒ Object
- #delete_user(user_name, group_name) ⇒ Object
- #get_group(group_name) ⇒ Object
- #get_user(user_name, group_name) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #request(method, path, payload, query = nil) ⇒ Object
- #set_password(user_name, group_name, password) ⇒ Object
- #set_qos_limits(qos_details) ⇒ Object
- #update_user(user_details) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/cloudian/admin.rb', line 37 def initialize(={}) @user = [:user] @password = [:password] @host = [:host] @port = [:port] @path = [:path] || '/' @persistent = [:persistent] || false @ssl_verify_peer = true if [:ssl_verify_peer] != false url = "https://#{@host}:#{@port}#{@path}" params = { user: @user, password: @password, # NOTE: cloudians error messages always seem to be HTML headers: {"Accept" => "application/json"}, ssl_verify_peer: @ssl_verify_peer } @connection = Fog::Core::Connection.new(url, @persistent, params) end |
Instance Method Details
#create_credentials(user_name, group_name) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/cloudian/requests/admin/create_credentials.rb', line 5 def create_credentials(user_name, group_name) request(:put, 'user/credentials', nil, { userId: user_name, groupId: group_name }) # this returns "credentials object" in JSON end |
#create_group(group_name) ⇒ Object
5 6 7 8 |
# File 'lib/fog/cloudian/requests/admin/create_group.rb', line 5 def create_group(group_name) request(:put, 'group', { groupId: group_name }) # NOTE: the response is a 200 and has an empty body *sigh* end |
#create_user(user_name, group_name, user_type = 'User') ⇒ Object
5 6 7 8 9 10 |
# File 'lib/fog/cloudian/requests/admin/create_user.rb', line 5 def create_user(user_name, group_name, user_type='User') request(:put, 'user', { userId: user_name, groupId: group_name, userType: user_type }) # this returns a "user object" as JSON end |
#delete_group(group_name) ⇒ Object
5 6 7 8 |
# File 'lib/fog/cloudian/requests/admin/delete_group.rb', line 5 def delete_group(group_name) request(:delete, 'group', nil, { groupId: group_name }) # the response is a 200 and has an empty body end |
#delete_user(user_name, group_name) ⇒ Object
5 6 7 8 |
# File 'lib/fog/cloudian/requests/admin/delete_user.rb', line 5 def delete_user(user_name, group_name) request(:delete, 'user', nil, { userId: user_name, groupId: group_name }) # the response is 200 with an empty body end |
#get_group(group_name) ⇒ Object
5 6 7 8 |
# File 'lib/fog/cloudian/requests/admin/get_group.rb', line 5 def get_group(group_name) request(:get, 'group', nil, { groupId: group_name }) # this returns a "group object" in JSON end |
#get_user(user_name, group_name) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/cloudian/requests/admin/get_user.rb', line 5 def get_user(user_name, group_name) request(:get, 'user', nil, { userId: user_name, groupId: group_name }) # this returns an "user object" in JSON end |
#request(method, path, payload, query = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fog/cloudian/admin.rb', line 56 def request(method, path, payload, query=nil) # NOTE: on success cloudian always returns a 200, they don't # know any other status codes, nor redirects params = { method: method, path: path, expects: [200] } params[:body] = Fog::JSON.encode(payload) if payload params[:query] = query if query response = @connection.request(params) if response.body.empty? :success_with_empty_body else case response.headers['Content-Type'] when /^application\/json/ # puts response.body Fog::JSON.decode(response.body) else response.headers['Content-Type'] end end # rescue Excon::Errors::HTTPStatusError => error # error end |
#set_password(user_name, group_name, password) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/cloudian/requests/admin/set_password.rb', line 5 def set_password(user_name, group_name, password) # POST /user/password Create or change a user's CMC password # # Minimum of nine characters, maximum of 64 characters # Must contain at least three of these four types of characters: # o Lower case letters # o Upper case letters # o Numbers # o Special characters such as !, @, #, $, %, ^, etc. request(:post, 'user/password', nil, { userId: user_name, groupId: group_name, password: password }) # This returns a 200 with an empty body. # # Unless the user does not exist then you'll get a... # # "204 User does not exist" # # ROFLMAO. end |
#set_qos_limits(qos_details) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/fog/cloudian/requests/admin/set_qos_limits.rb', line 19 def set_qos_limits(qos_details) raise 'groupId must be given' unless qos_details[:groupId] details = QOS_LIMITS_DEFAULTS.merge(qos_details) # POST /qos/limits Create QoS settings for a user or group request(:post, 'qos/limits', nil, details) # this returns a 200 with an empty body end |
#update_user(user_details) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/cloudian/requests/admin/update_user.rb', line 5 def update_user(user_details) # The `user_details` must either have `canonicalUserId` XOR # (`userId` AND `groupId`). @cloudian: What are you doing? if user_details["canonicalUserId"] user_details.delete("userId") user_details.delete("groupId") end request(:post, 'user', user_details) end |