Class: Fog::Radosgw::Provisioning::Mock
- Inherits:
-
Object
- Object
- Fog::Radosgw::Provisioning::Mock
- Defined in:
- lib/fog/radosgw/provisioning.rb,
lib/fog/radosgw/requests/provisioning/get_user.rb,
lib/fog/radosgw/requests/provisioning/list_users.rb,
lib/fog/radosgw/requests/provisioning/create_user.rb,
lib/fog/radosgw/requests/provisioning/delete_user.rb,
lib/fog/radosgw/requests/provisioning/enable_user.rb,
lib/fog/radosgw/requests/provisioning/update_user.rb,
lib/fog/radosgw/requests/provisioning/disable_user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_user(user_id, display_name, email, options = {}) ⇒ Object
- #data ⇒ Object
- #delete_user(user_id) ⇒ Object
- #disable_user(user_id) ⇒ Object
- #enable_user(user_id) ⇒ Object
- #get_user(user_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_users(options = {}) ⇒ Object
- #reset_data ⇒ Object
- #update_user(key_id, user) ⇒ Object
- #user_exists?(user_id) ⇒ Boolean
Methods included from UserUtils
#update_mock_user, #update_radosgw_user
Methods included from Utils
#configure_uri_options, #escape, #radosgw_uri, #signature, #signed_headers
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
32 33 34 |
# File 'lib/fog/radosgw/provisioning.rb', line 32 def initialize( = {}) () end |
Class Method Details
.data ⇒ Object
24 25 26 |
# File 'lib/fog/radosgw/provisioning.rb', line 24 def self.data @data ||= Hash.new({}) end |
.reset ⇒ Object
28 29 30 |
# File 'lib/fog/radosgw/provisioning.rb', line 28 def self.reset @data = nil end |
Instance Method Details
#create_user(user_id, display_name, email, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fog/radosgw/requests/provisioning/create_user.rb', line 47 def create_user(user_id, display_name, email, = {}) if user_exists?(user_id) raise Fog::Radosgw::Provisioning::UserAlreadyExists, "User with user_id #{user_id} already exists." end secret_key = rand(1000).to_s data[user_id] = { :email => email, :user_id => user_id, :display_name => display_name, :suspended => 0, :secret_key => secret_key, } Excon::Response.new.tap do |response| response.status = 200 response.headers['Content-Type'] = 'application/json' response.body = { "email" => email, "user_id" => user_id, "display_name" => display_name, "suspended" => 0, "keys" => [ { "access_key" => "XXXXXXXXXXXXXXXXXXXX", "secret_key" => secret_key, "user" => user_id, } ], } end end |
#data ⇒ Object
36 37 38 |
# File 'lib/fog/radosgw/provisioning.rb', line 36 def data self.class.data[radosgw_uri] end |
#delete_user(user_id) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fog/radosgw/requests/provisioning/delete_user.rb', line 41 def delete_user(user_id) if !user_exists?(user_id) raise Fog::Radosgw::Provisioning::NoSuchUser, "No user with user_id #{user_id} exists." end data.delete(user_id) Excon::Response.new.tap do |response| response.status = 200 response.headers['Content-Type'] = 'application/json' response.body = "" end end |
#disable_user(user_id) ⇒ Object
17 18 19 |
# File 'lib/fog/radosgw/requests/provisioning/disable_user.rb', line 17 def disable_user(user_id) update_mock_user(user_id, { :suspended => 1 }) end |
#enable_user(user_id) ⇒ Object
17 18 19 |
# File 'lib/fog/radosgw/requests/provisioning/enable_user.rb', line 17 def enable_user(user_id) update_mock_user(user_id, { :suspended => 0 }) end |
#get_user(user_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/radosgw/requests/provisioning/get_user.rb', line 36 def get_user(user_id) if value = data[user_id] Excon::Response.new.tap do |response| response.status = 200 response.headers['Content-Type'] = 'application/json' response.body = { "email" => value[:email], "user_id" => value[:user_id], "display_name" => value[:display_name], "suspended" => value[:suspended], "keys" => [ { "access_key" => "XXXXXXXXXXXXXXXXXXXX", "secret_key" => value[:secret_key], "user" => value[:user_id], } ], } end else Excon::Response.new.tap do |response| response.status = 404 response.headers['Content-Type'] = 'application/json' end end end |
#list_users(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/radosgw/requests/provisioning/list_users.rb', line 44 def list_users( = {}) filtered_data = [:suspended] ? data.select { |key, value| value[:suspended] == [:suspended] } : data Excon::Response.new.tap do |response| response.status = 200 response.body = filtered_data.map do |key, value| { "email" => value[:email], "display_name" => value[:user_id], "user_id" => value[:user_id], "suspended" => value[:suspended], "keys" => [ { "access_key" => "XXXXXXXXXXXXXXXXXXXX", "secret_key" => value[:secret_key], "user" => value[:user_id], } ], } end.compact end end |
#reset_data ⇒ Object
40 41 42 |
# File 'lib/fog/radosgw/provisioning.rb', line 40 def reset_data self.class.data.delete(radosgw_uri) end |
#update_user(key_id, user) ⇒ Object
17 18 19 |
# File 'lib/fog/radosgw/requests/provisioning/update_user.rb', line 17 def update_user(key_id, user) update_mock_user(key_id, user) end |
#user_exists?(user_id) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/fog/radosgw/requests/provisioning/create_user.rb', line 41 def user_exists?(user_id) data.find do |key, value| value[:user_id] == user_id end end |