Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 9cc945a

Browse files
Validate content type is yaml for manifest diff endpoint
- Also update documentation with some extra definitions and a table of possible return values [#173478913](https://www.pivotaltracker.com/story/show/173478913) Co-authored-by: Nick Webb <nwebb@pivotal.io> Co-authored-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent 1646f2c commit 9cc945a

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

app/controllers/v3/space_manifests_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class SpaceManifestsController < ApplicationController
99
wrap_parameters :body, format: [:yaml]
1010

11-
before_action :validate_content_type!, only: :apply_manifest
11+
before_action :validate_content_type!
1212

1313
def apply_manifest
1414
space = Space.find(guid: hashed_params[:guid])
@@ -103,7 +103,7 @@ def compound_error!(error_messages)
103103

104104
def validate_content_type!
105105
if !request_content_type_is_yaml?
106-
logger.error("Context-type isn't yaml: #{request.content_type}")
106+
logger.error("Content-type isn't yaml: #{request.content_type}")
107107
invalid_request!('Content-Type must be yaml')
108108
end
109109
end

docs/v3/source/includes/resources/manifests/_create_diff.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Example Request
77
```shell
88
curl "https://api.example.org/v3/spaces/[guid]/manifest_diff" \
99
-X POST \
10+
-H "Content-Type: application/x-yaml" \
1011
-H "Authorization: bearer [token]" \
1112
-d @/path/to/manifest.yml
1213
```
@@ -41,12 +42,28 @@ Content-Type: application/json
4142
}
4243
```
4344

44-
Create a manifest diff for apps in the provided manifest and their underlying processes. Currently manifest_diff only supports version 1 manifests.
45+
This endpoint returns a JSON representation of the difference between the
46+
provided manifest and the current state of a space.
4547

46-
Manifests require the `applications` field.
48+
Currently, this endpoint can only diff [version 1](#the-manifest-schema) manifests.
49+
50+
##### The diff object
51+
52+
The diff object format is inspired by the [JSON Patch
53+
specification](https://tools.ietf.org/html/rfc6902).
54+
55+
Name | Type | Description
56+
-------------- | ---- | -----------
57+
**op** | _string_ | Type of change; valid values are `add`, `remove`, `replace`
58+
**path** | _string_ | Path to changing manifest field
59+
**was** | _any_ | For `remove` and `replace` operations, the previous value;
60+
otherwise key is omitted
61+
**value** | _any_ | For `add` and `replace` operations, the new value; otherwise
62+
key is omitted
4763

4864
#### Definition
49-
`GET /v3/spaces/:guid/manifest_diff`
65+
66+
`POST /v3/spaces/:guid/manifest_diff`
5067

5168
#### Permitted Roles
5269
|

spec/request/space_manifests_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,53 @@
635635
expect(parsed_response['errors'].first['detail']).to eq('Unsupported manifest schema version. Currently supported versions: [1].')
636636
end
637637
end
638+
639+
context 'the content-type is omitted' do
640+
let(:yml_manifest) do
641+
{
642+
'applications' => [
643+
{
644+
'name' => 'new-app',
645+
},
646+
]
647+
}.to_yaml
648+
end
649+
650+
it 'returns an appropriate error' do
651+
headers = yml_headers(user_header)
652+
headers.delete('CONTENT_TYPE')
653+
post "/v3/spaces/#{space.guid}/manifest_diff", yml_manifest, headers
654+
parsed_response = MultiJson.load(last_response.body)
655+
656+
expect(last_response).to have_status_code(400)
657+
expect(parsed_response['errors'].first['detail']).to eq('The request is invalid')
658+
end
659+
end
660+
661+
context 'the content-type is not yaml' do
662+
let(:yml_manifest) do
663+
{
664+
'applications' => [
665+
{
666+
'name' => 'new-app',
667+
},
668+
]
669+
}.to_yaml
670+
end
671+
672+
it 'returns an appropriate error' do
673+
headers = yml_headers(user_header)
674+
headers['CONTENT_TYPE'] = 'bogus'
675+
676+
post "/v3/spaces/#{space.guid}/manifest_diff", yml_manifest, headers
677+
parsed_response = MultiJson.load(last_response.body)
678+
679+
expect(last_response).to have_status_code(400)
680+
expect(parsed_response['errors'].first['detail']).to eq('The request is invalid')
681+
end
682+
end
638683
end
684+
639685
context 'the space does not exist' do
640686
let(:yml_manifest) do
641687
{

0 commit comments

Comments
 (0)