Skip to content

Commit

Permalink
add 404 response to jobs (hopefully it matches the AWS API
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jan 16, 2013
1 parent 81edc39 commit 1221b7b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/icemelt/application.rb
Expand Up @@ -200,14 +200,14 @@ def common_response_headers
v = vault(params[:vault_name])

if v.exists?
status 202
status 202

options = JSON.parse(request.body.read)
job = Job.create(v, options)
options = JSON.parse(request.body.read)
job = Job.create(v, options)

headers \
"Location" => "#{params[:account_id]}/vaults/#{params[:vault_name]}/jobs/#{job.id}",
'x-amz-job-id' => job.id.to_s
headers \
"Location" => "#{params[:account_id]}/vaults/#{params[:vault_name]}/jobs/#{job.id}",
'x-amz-job-id' => job.id.to_s

nil
else
Expand All @@ -227,6 +227,18 @@ def common_response_headers
get '/:account_id/vaults/:vault_name/jobs/:job_id' do
common_response_headers

if job.expired? or job.new?
headers \
"Content-Type" => 'application/json'
status 404

return ({
"code" => "ResourceNotFoundException",
"message" => "The job ID was not found: #{job.id}",
"type" => "Client"
}).to_json
end

status 200

headers \
Expand All @@ -243,9 +255,17 @@ def common_response_headers
v = vault(params[:vault_name])
job = v.job params[:job_id]

raise "??" if job.expired?

# what happens if the job was expired?
if job.expired? or job.new?
headers \
"Content-Type" => 'application/json'
status 404

return ({
"code" => "ResourceNotFoundException",
"message" => "The job ID was not found: #{job.id}",
"type" => "Client"
}).to_json
end

case job.type
when "archive-retrieval"
Expand Down
5 changes: 5 additions & 0 deletions lib/icemelt/job.rb
Expand Up @@ -44,6 +44,10 @@ def format
options['Format'] || 'JSON'
end

def new?
options.fetch(:_saved, false)
end

def action
case type
when "archive-retrieval"
Expand Down Expand Up @@ -71,6 +75,7 @@ def content
end

def save
self.options[:_saved] = true
vault.add_job(self)
end

Expand Down

0 comments on commit 1221b7b

Please sign in to comment.