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

Commit ce3d1a0

Browse files
authored
Merge pull request cloudfoundry#1960 from cloudfoundry/remove_apply_app_manifest
Remove app apply manifest endpoint
2 parents 5228fe1 + f3a0087 commit ce3d1a0

21 files changed

Lines changed: 180 additions & 1757 deletions

app/actions/space_diff_manifest.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'presenters/v3/app_manifest_presenter'
2+
require 'messages/app_manifest_message'
23
require 'json-diff'
34

45
module VCAP::CloudController
@@ -62,7 +63,7 @@ def self.filter_manifest_app_hash(manifest_app_hash)
6263
# rubocop:todo Metrics/CyclomaticComplexity
6364
def self.generate_diff(app_manifests, space)
6465
json_diff = []
65-
recognized_top_level_keys = NamedAppManifestMessage.allowed_keys.map(&:to_s)
66+
recognized_top_level_keys = AppManifestMessage.allowed_keys.map(&:to_s)
6667
app_manifests.each_with_index do |manifest_app_hash, index|
6768
manifest_app_hash = SpaceDiffManifest.filter_manifest_app_hash(manifest_app_hash)
6869
existing_app = space.app_models.find { |app| app.name == manifest_app_hash['name'] }

app/controllers/v3/app_manifests_controller.rb

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,6 @@
55
class AppManifestsController < ApplicationController
66
include AppSubResource
77

8-
wrap_parameters :body, format: [:yaml]
9-
10-
before_action :validate_content_type!, only: :apply_manifest
11-
12-
def apply_manifest
13-
message = AppManifestMessage.create_from_yml(parsed_app_manifest_params)
14-
compound_error!(message.errors.full_messages) unless message.valid?
15-
16-
app, space, org = AppFetcher.new.fetch(hashed_params[:guid])
17-
18-
app_not_found! unless app && permission_queryer.can_read_from_space?(space.guid, org.guid)
19-
unauthorized! unless permission_queryer.can_write_to_space?(space.guid)
20-
unsupported_for_docker_apps!(message) if incompatible_with_buildpacks(app.lifecycle_type, message)
21-
22-
apply_manifest_action = AppApplyManifest.new(user_audit_info)
23-
apply_manifest_job = VCAP::CloudController::Jobs::AppApplyManifestActionJob.new(app.guid, message, apply_manifest_action)
24-
25-
record_apply_manifest_audit_event(app, message, space)
26-
job = Jobs::Enqueuer.new(apply_manifest_job, queue: Jobs::Queues.generic).enqueue_pollable
27-
TelemetryLogger.v3_emit(
28-
'apply-manifest',
29-
{
30-
'app-id' => app.guid,
31-
'user-id' => current_user.guid
32-
}
33-
)
34-
35-
head HTTP::ACCEPTED, 'Location' => url_builder.build_url(path: "/v3/jobs/#{job.guid}")
36-
end
37-
388
def show
399
app, space, org = AppFetcher.new.fetch(hashed_params[:guid])
4010

@@ -45,44 +15,4 @@ def show
4515
manifest_yaml = manifest_presenter.to_hash.deep_stringify_keys.to_yaml
4616
render status: :ok, plain: manifest_yaml, content_type: YAML_CONTENT_TYPE
4717
end
48-
49-
private
50-
51-
def record_apply_manifest_audit_event(app, message, space)
52-
audited_request_yaml = { 'applications' => [message.audit_hash] }.to_yaml
53-
Repositories::AppEventRepository.new.record_app_apply_manifest(app, space, user_audit_info, audited_request_yaml)
54-
end
55-
56-
def unsupported_for_docker_apps!(manifest)
57-
error_message = manifest.buildpacks ? 'Buildpacks' : 'Buildpack'
58-
raise unprocessable(error_message + ' cannot be configured for a docker lifecycle app.')
59-
end
60-
61-
def incompatible_with_buildpacks(lifecycle_type, manifest)
62-
lifecycle_type == 'docker' && (manifest.buildpack || manifest.buildpacks)
63-
end
64-
65-
def compound_error!(error_messages)
66-
underlying_errors = error_messages.map { |message| unprocessable(message) }
67-
raise CloudController::Errors::CompoundError.new(underlying_errors)
68-
end
69-
70-
def validate_content_type!
71-
if !request_content_type_is_yaml?
72-
logger.error("Context-type isn't yaml: #{request.content_type}")
73-
bad_request!('Content-Type must be yaml')
74-
end
75-
end
76-
77-
def request_content_type_is_yaml?
78-
Mime::Type.lookup(request.content_type) == :yaml
79-
end
80-
81-
def parsed_app_manifest_params
82-
parsed_application = parsed_yaml['applications'] && parsed_yaml['applications'].first
83-
84-
raise bad_request!('Invalid app manifest') unless parsed_application.present?
85-
86-
parsed_application
87-
end
8818
end

app/controllers/v3/apps_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
require 'messages/update_environment_variables_message'
2121
require 'messages/app_manifest_message'
2222
require 'messages/app_builds_list_message'
23-
require 'messages/named_app_manifest_message'
2423
require 'presenters/v3/app_presenter'
2524
require 'presenters/v3/app_env_presenter'
2625
require 'presenters/v3/app_environment_variables_presenter'

app/controllers/v3/space_manifests_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'presenters/v3/app_manifest_presenter'
22
require 'repositories/app_event_repository'
3-
require 'messages/named_app_manifest_message'
3+
require 'messages/app_manifest_message'
44
require 'actions/app_find_or_create_skeleton'
55
require 'actions/app_create'
66
require 'actions/space_diff_manifest'
@@ -15,7 +15,7 @@ def apply_manifest
1515
space_not_found! unless space && permission_queryer.can_read_from_space?(space.guid, space.organization.guid)
1616
unauthorized! unless permission_queryer.can_write_to_space?(space.guid)
1717

18-
messages = parsed_app_manifests.map { |app_manifest| NamedAppManifestMessage.create_from_yml(app_manifest) }
18+
messages = parsed_app_manifests.map { |app_manifest| AppManifestMessage.create_from_yml(app_manifest) }
1919
errors = messages.each_with_index.flat_map { |message, i| errors_for_message(message, i) }
2020
compound_error!(errors) unless errors.empty?
2121

@@ -49,7 +49,7 @@ def diff_manifest
4949

5050
parsed_manifests = parsed_app_manifests.map(&:to_hash)
5151

52-
messages = parsed_app_manifests.map { |app_manifest| NamedAppManifestMessage.create_from_yml(app_manifest) }
52+
messages = parsed_app_manifests.map { |app_manifest| AppManifestMessage.create_from_yml(app_manifest) }
5353
errors = messages.each_with_index.flat_map { |message, i| errors_for_message(message, i) }
5454
compound_error!(errors) unless errors.empty?
5555

app/jobs/app_apply_manifest_action_job.rb

Lines changed: 0 additions & 59 deletions
This file was deleted.

app/messages/app_manifest_message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppManifestMessage < BaseMessage
2525
:instances,
2626
:metadata,
2727
:memory,
28+
:name,
2829
:no_route,
2930
:processes,
3031
:random_route,
@@ -53,6 +54,7 @@ def self.underscore_keys(hash)
5354
end
5455
end
5556

57+
validates :name, presence: { message: 'must not be empty' }, string: true
5658
validate :validate_top_level_web_process!
5759
validate :validate_processes!, if: ->(record) { record.requested?(:processes) }
5860
validate :validate_sidecars!, if: ->(record) { record.requested?(:sidecars) }

app/messages/named_app_manifest_message.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
get '/apps/:guid/ssh_enabled', to: 'app_features#ssh_enabled'
2828

2929
# app manifests
30-
post '/apps/:guid/actions/apply_manifest', to: 'app_manifests#apply_manifest'
3130
get '/apps/:guid/manifest', to: 'app_manifests#show'
3231

3332
# app revisions

docs/v3/source/includes/experimental_resources/app_manifest/_apply.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

docs/v3/source/includes/experimental_resources/app_manifest/_header.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)