Skip to content

Commit 9ee815a

Browse files
philippthunsvkrieger
authored andcommitted
Adapt system env presenter
When the app feature 'file-based service bindings' is enabled, SERVICE_BINDING_ROOT is returned instead of VCAP_SERVICES. For an app using file-based service bindings the '/env' endpoint (i.e. GET /v3/apps/:guid/env) returns the following: { ... "system_env_json": { "SERVICE_BINDING_ROOT": "/etc/cf-service-bindings" }, ... } The file runtime_environment/system_env_presenter_spec.rb has been deleted because all the tests it contained are also present in system_environment/system_env_presenter_spec.rb.
1 parent 089f380 commit 9ee815a

File tree

11 files changed

+48
-113
lines changed

11 files changed

+48
-113
lines changed

app/controllers/runtime/apps_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def read_env(guid)
7272
staging_env_json: EnvironmentVariableGroup.staging.environment_json,
7373
running_env_json: EnvironmentVariableGroup.running.environment_json,
7474
environment_json: process.app.environment_variables,
75-
system_env_json: SystemEnvPresenter.new(process.service_bindings).system_env,
75+
system_env_json: SystemEnvPresenter.new(process).system_env,
7676
application_env_json: { 'VCAP_APPLICATION' => vcap_application }
7777
}, mode: :compat)
7878
]

app/models/runtime/process_model.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def revisions_enabled?
177177
app.revisions_enabled
178178
end
179179

180+
delegate :file_based_service_bindings_enabled, to: :app
181+
180182
def package_hash
181183
# this caches latest_package for performance reasons
182184
package = latest_package

app/presenters/system_environment/system_env_presenter.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
require 'presenters/system_environment/service_binding_presenter'
33

44
class SystemEnvPresenter
5-
def initialize(service_bindings)
6-
@service_bindings = service_bindings
5+
def initialize(app_or_process)
6+
@file_based_service_bindings_enabled = app_or_process.file_based_service_bindings_enabled
7+
@service_bindings = app_or_process.service_bindings
78
end
89

910
def system_env
11+
return { SERVICE_BINDING_ROOT: '/etc/cf-service-bindings' } if @file_based_service_bindings_enabled
12+
1013
{ VCAP_SERVICES: service_binding_env_variables }
1114
end
1215

app/presenters/v3/app_env_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def to_hash
2525
environment_variables: app.environment_variables,
2626
staging_env_json: EnvironmentVariableGroup.staging.environment_json,
2727
running_env_json: EnvironmentVariableGroup.running.environment_json,
28-
system_env_json: redact_hash(SystemEnvPresenter.new(app.service_bindings).system_env),
28+
system_env_json: redact_hash(SystemEnvPresenter.new(app).system_env),
2929
application_env_json: vcap_application
3030
}
3131
end

lib/cloud_controller/backends/staging_environment_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def build(app, space, lifecycle, memory_limit, staging_disk_in_mb, vars_from_mes
2727
'MEMORY_LIMIT' => "#{memory_limit}m"
2828
}
2929
).
30-
merge(SystemEnvPresenter.new(app.service_bindings).system_env.stringify_keys)
30+
merge(SystemEnvPresenter.new(app).system_env.stringify_keys)
3131
end
3232
end
3333
end

lib/cloud_controller/diego/environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def common_json_and_merge(&blk)
4141
@initial_env.
4242
merge(process.environment_json || {}).
4343
merge(blk.call).
44-
merge(SystemEnvPresenter.new(process.service_bindings).system_env)
44+
merge(SystemEnvPresenter.new(process).system_env)
4545

4646
diego_env = diego_env.merge(DATABASE_URL: process.database_uri) if process.database_uri
4747

lib/cloud_controller/diego/task_environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def build
1919
initial_envs.
2020
merge(app_env).
2121
merge('VCAP_APPLICATION' => vcap_application, 'MEMORY_LIMIT' => "#{task.memory_in_mb}m").
22-
merge(SystemEnvPresenter.new(app.service_bindings).system_env.stringify_keys)
22+
merge(SystemEnvPresenter.new(app).system_env.stringify_keys)
2323

2424
task_env = task_env.merge('VCAP_PLATFORM_OPTIONS' => credhub_url) if credhub_url.present? && cred_interpolation_enabled?
2525

spec/request/apps_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,20 @@
16011601
end
16021602

16031603
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
1604+
1605+
context 'when file-based service bindings are enabled' do
1606+
let(:app_model_response_object) do
1607+
r = super()
1608+
r[:system_env_json] = { SERVICE_BINDING_ROOT: '/etc/cf-service-bindings' }
1609+
r
1610+
end
1611+
1612+
before do
1613+
app_model.update(file_based_service_bindings_enabled: true)
1614+
end
1615+
1616+
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
1617+
end
16041618
end
16051619

16061620
context 'when VCAP_SERVICES contains potentially sensitive information' do

spec/unit/lib/cloud_controller/diego/environment_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module VCAP::CloudController::Diego
2323
encoded_vcap_application_json = vcap_app.to_json
2424

2525
vcap_services_key = :VCAP_SERVICES
26-
system_env = SystemEnvPresenter.new(process.service_bindings).system_env
26+
system_env = SystemEnvPresenter.new(process).system_env
2727
expect(system_env).to have_key(vcap_services_key)
2828

2929
encoded_vcap_services_json = system_env[vcap_services_key].to_json

spec/unit/presenters/runtime_environment/system_env_presenter_spec.rb

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

0 commit comments

Comments
 (0)