Class: ChefZero::Endpoints::CookbookArtifactIdentifierEndpoint

Inherits:
CookbookVersionEndpoint show all
Defined in:
lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb

Constant Summary

Constants inherited from RestBase

RestBase::DEFAULT_REQUEST_VERSION, RestBase::DEFAULT_RESPONSE_VERSION

Instance Attribute Summary

Attributes inherited from RestObjectEndpoint

#identity_keys

Attributes inherited from RestBase

#server

Instance Method Summary collapse

Methods inherited from CookbookVersionEndpoint

#get_checksums

Methods inherited from RestObjectEndpoint

#initialize, #patch_request_body

Methods inherited from RestBase

#accepts?, #already_json_response, #build_uri, build_uri, #call, #check_api_version, #create_data, #create_data_dir, #data_store, #delete_data, #delete_data_dir, #error, #exists_data?, #exists_data_dir?, #get_data, #get_data_or_else, #hashify_list, #head_request, #initialize, #json_only, #json_response, #list_data, #list_data_or_else, #parse_json, #policy_name_invalid?, #populate_defaults, rfc2396_parser, #set_data, #text_response, #to_json

Constructor Details

This class inherits a constructor from ChefZero::Endpoints::RestObjectEndpoint

Instance Method Details

#delete(request) ⇒ Object

DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb', line 29

def delete(request)
  doomed_cookbook_json = get_data(request)
  identified_cookbook_data = normalize(request, doomed_cookbook_json)
  delete_data(request)

  # go through the recipes and delete stuff in the file store.
  hoover_unused_checksums(get_checksums(doomed_cookbook_json), request)

  # if this was the last revision, delete the directory so future requests will 404, instead of
  # returning 200 with an empty list.
  # Last one out turns out the lights: delete /organizations/ORG/cookbooks/COOKBOOK if it no longer has versions
  cookbook_path = request.rest_path[0..3]
  if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
    delete_data_dir(request, cookbook_path)
  end

  json_response(200, identified_cookbook_data)
rescue RestErrorResponse => ex
  if ex.response_code == 404
    error(404, "not_found")
  else
    raise
  end
end

#get(request) ⇒ Object

GET /organizations/ORG/cookbook_artifacts/NAME/IDENTIFIER



11
12
13
14
# File 'lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb', line 11

def get(request)
  cookbook_data = normalize(request, get_data(request))
  json_response(200, cookbook_data)
end

#put(request) ⇒ Object

PUT /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER



17
18
19
20
21
22
23
24
25
26
# File 'lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb', line 17

def put(request)
  if exists_data?(request)
    return error(409, "Cookbooks cannot be modified, and a cookbook with this identifier already exists.")
  end

  cb_data = normalize(request, request.body)
  set_data(request, nil, to_json(cb_data), :create_dir, :create)

  already_json_response(201, request.body)
end