Module: Fog::Radosgw::UserUtils

Included in:
Provisioning::Mock, Provisioning::Real
Defined in:
lib/fog/radosgw/user_utils.rb

Instance Method Summary collapse

Instance Method Details

#update_mock_user(user_id, user) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/radosgw/user_utils.rb', line 29

def update_mock_user(user_id, user)
  if data[user_id]
    if suspended = user[:suspended]
      data[user_id][:suspended] = suspended
    end

    Excon::Response.new.tap do |response|
      response.status = 200
      response.body   = data[user_id]
    end
  else
    Excon::Response.new.tap do |response|
      response.status = 403
    end
  end
end

#update_radosgw_user(user_id, user) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/radosgw/user_utils.rb', line 4

def update_radosgw_user(user_id, user)
  path         = "admin/user"
  user_id      = escape(user_id)
  params       = {
      :method => 'POST',
      :path => path,
  }
  query        = "?uid=#{user_id}&format=json&suspended=#{user[:suspended]}"
  begin
    response = Excon.post("#{@scheme}://#{@host}/#{path}#{query}",
                          :headers => signed_headers(params))
    if !response.body.empty?
      case response.headers['Content-Type']
        when 'application/json'
          response.body = Fog::JSON.decode(response.body)
      end
    end
    response
  rescue Excon::Errors::NotFound => e
    raise Fog::Radosgw::Provisioning::NoSuchUser.new
  rescue Excon::Errors::BadRequest => e
    raise Fog::Radosgw::Provisioning::ServiceUnavailable.new
  end
end