Class: Visor::Image::HeadImage

Inherits:
Goliath::API
  • Object
show all
Includes:
Common::Exception, Common::Util
Defined in:
lib/image/routes/head_image.rb

Overview

Head metadata about the image with the given id.

Instance Method Summary collapse

Instance Method Details

#exit_error(code, message) ⇒ Array

Produce an HTTP response with an error code and message.

Parameters:

  • code (Fixnum)

    The error code.

  • message (String)

    The error message.

Returns:

  • (Array)

    The HTTP response containing an error code and its message.



46
47
48
49
# File 'lib/image/routes/head_image.rb', line 46

def exit_error(code, message)
  logger.error message
  [code, {'x-error-code' => code.to_s, 'x-error-message' => message}, nil]
end

#on_headers(env, headers) ⇒ Object

Pre-process headers as they arrive and load them into a environment variable.

Parameters:

  • env (Object)

    The Goliath environment variables.

  • headers (Object)

    The incoming request HTTP headers.



17
18
19
20
# File 'lib/image/routes/head_image.rb', line 17

def on_headers(env, headers)
  logger.debug "Received headers: #{headers.inspect}"
  env['headers'] = headers
end

#response(env) ⇒ Object

Query database to retrieve the wanted image meta and return it as HTTP headers.

Parameters:

  • env (Object)

    The Goliath environment variables.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/image/routes/head_image.rb', line 26

def response(env)
  authorize(env, vas)
  meta   = vms.get_image(params[:id])
  header = push_meta_into_headers(meta)
  [200, header, nil]
rescue Forbidden => e
  exit_error(403, e.message)
rescue NotFound => e
  exit_error(404, e.message)
rescue InternalError => e
  exit_error(503, e.message)
end