Skip to content

Commit

Permalink
Use lifecycle option instead of boolean
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Pannemans <[email protected]>
  • Loading branch information
2 people authored and pbusko committed Apr 22, 2024
1 parent f8218cb commit 424ebe9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/messages/app_manifest_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AppManifestMessage < BaseMessage
instances
metadata
memory
cnb
lifecycle
name
no_route
processes
Expand Down Expand Up @@ -71,7 +71,7 @@ def self.underscore_keys(hash)
validate :validate_buildpack_and_buildpacks_combination!
validate :validate_docker_enabled!
validate :validate_cnb_enabled!
validate :validate_cnb_buildpacks!, if: ->(record) { record.requested?(:cnb) }
validate :validate_cnb_buildpacks!, if: ->(record) { record.lifecycle == 'cnb' }
validate :validate_docker_buildpacks_combination!
validate :validate_service_bindings_message!, if: ->(record) { record.requested?(:services) }
validate :validate_env_update_message!, if: ->(record) { record.requested?(:env) }
Expand Down Expand Up @@ -122,7 +122,7 @@ def audit_hash
end

def app_lifecycle_hash
lifecycle_data = if requested?(:cnb)
lifecycle_data = if requested?(:lifecycle) && @lifecycle == 'cnb'
cnb_lifecycle_data
elsif requested?(:docker)
docker_lifecycle_data
Expand Down Expand Up @@ -477,13 +477,13 @@ def validate_docker_enabled!
end

def validate_cnb_enabled!
FeatureFlag.raise_unless_enabled!(:diego_cnb) if requested?(:cnb)
FeatureFlag.raise_unless_enabled!(:diego_cnb) if requested?(:lifecycle) && @lifecycle == 'cnb'
rescue StandardError => e
errors.add(:base, e.message)
end

def validate_cnb_buildpacks!
return if requested?(:cnb) && (requested?(:buildpack) || requested?(:buildpacks))
return if requested?(:lifecycle) && @lifecycle == 'cnb' && (requested?(:buildpack) || requested?(:buildpacks))

errors.add(:base, 'Buildpack(s) must be specified when using Cloud Native Buildpacks')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/messages/app_manifest_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ module VCAP::CloudController
FeatureFlag.make(name: 'diego_cnb', enabled: true, error_message: nil)
end

let(:params_from_yaml) { { name: 'eugene', cnb: true } }
let(:params_from_yaml) { { name: 'eugene', lifecycle: 'cnb' } }

it 'is not valid' do
message = AppManifestMessage.create_from_yml(params_from_yaml)
Expand Down Expand Up @@ -2082,7 +2082,7 @@ module VCAP::CloudController
end

context 'when cnb is specified' do
let(:parsed_yaml) { { name: 'cnb', cnb: true, buildpacks: %w[nodejs java], stack: stack.name } }
let(:parsed_yaml) { { name: 'cnb', lifecycle: 'cnb', buildpacks: %w[nodejs java], stack: stack.name } }

context 'when cnb is enabled' do
before do
Expand Down

0 comments on commit 424ebe9

Please sign in to comment.