Skip to content

Commit f476e25

Browse files
committed
Accept lab_id, proxy and enable_upgrade from user provisioned service
+Explicitly set agent automatic upgrade flag
1 parent 4dedaf4 commit f476e25

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

docs/framework-sealights_agent.md

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ The credential payload can contain the following entries.
1919
| Name | Description
2020
| ---- | -----------
2121
| `token` | A Sealights Agent token
22+
| `proxy` | Specify a HTTP proxy used to communicate with the Sealights backend. Required when a corporate network prohibits communication to cloud services. The default is to have no proxy configured. This does not inherit from `http_proxy`/`https_proxy` or `http.proxyHost/https.proxyHost`, you must set this specifically if a proxy is needed.
23+
| `lab_id` | Specify a Sealights [Lab ID][]
24+
25+
All fields above except the agent token may be also specified in the [Configuration Section](#configuration) below.
2226

2327
## Configuration
2428
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
@@ -33,6 +37,8 @@ The framework can be configured by modifying the [`config/sealights_agent.yml`][
3337
| `auto_upgrade` | Enable/disable agent auto-upgrade. Off by default
3438
| `version` | The version of Auto-reconfiguration to use. Candidate versions can be found in [this listing][]. If auto_upgrade is turned on, a different version may be downloaded and used at runtime
3539

40+
Configuration settings will take precedence over the ones specified in the [User-Provided Service](#user-provided-service), if those are defined.
41+
3642
## Troubleshooting and Support
3743

3844
For additional documentation and support, visit the official [Sealights Java agents documentation] page

lib/java_buildpack/framework/sealights_agent.rb

+20-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@ def release
4343
credentials = @application.services.find_service(FILTER, TOKEN)['credentials']
4444
@droplet.java_opts.add_system_property('sl.token', Shellwords.escape(credentials[TOKEN]))
4545
@droplet.java_opts.add_system_property('sl.tags', 'pivotal_cloud_foundry')
46-
add_system_property 'sl.enableUpgrade', ENABLE_UPGRADE
46+
47+
# add sl.enableUpgrade system property
48+
@droplet.java_opts.add_system_property('sl.enableUpgrade', @configuration[ENABLE_UPGRADE] ? 'true' : 'false')
49+
50+
# add sl.proxy system property if defined (either in config or user provisioned service)
51+
add_system_property_from_cfg_or_svc credentials, 'sl.proxy', PROXY
52+
53+
# add sl.labId system property if defined (either in config or user provisioned service)
54+
add_system_property_from_cfg_or_svc credentials, 'sl.labId', LAB_ID
55+
56+
# add build session if defined in config
4757
add_system_property 'sl.buildSessionId', BUILD_SESSION_ID
48-
add_system_property 'sl.proxy', PROXY
49-
add_system_property 'sl.labId', LAB_ID
5058
end
5159

5260
# wrapper for setting system properties on the droplet from configuration keys
@@ -56,6 +64,15 @@ def add_system_property(system_property, config_key)
5664
@droplet.java_opts.add_system_property(system_property, Shellwords.escape(@configuration[config_key]))
5765
end
5866

67+
# add a system property based on either plugin configuration (which takes precedence) or user provisioned service
68+
def add_system_property_from_cfg_or_svc(svc, system_property, config_key)
69+
if @configuration.key?(config_key)
70+
@droplet.java_opts.add_system_property(system_property, Shellwords.escape(@configuration[config_key]))
71+
elsif svc.key?(config_key)
72+
@droplet.java_opts.add_system_property(system_property, Shellwords.escape(svc[config_key]))
73+
end
74+
end
75+
5976
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
6077
def supports?
6178
@application.services.one_service? FILTER, TOKEN

spec/java_buildpack/framework/sealights_agent_spec.rb

+39-2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,49 @@
106106
expect(java_opts).not_to include(/proxy/)
107107
end
108108

109-
it 'does not specify JAVA_OPTS sl.enableUpgrade if one was not specified' do
109+
it 'sets JAVA_OPTS sl.enableUpgrade to false by default' do
110110
component.release
111111

112-
expect(java_opts).not_to include(/enableUpgrade/)
112+
expect(java_opts).to include('-Dsl.enableUpgrade=false')
113113
end
114+
end
115+
116+
context do
117+
let(:credentials) { { 'token' => 'my_token', 'proxy' => 'my_proxy', 'lab_id' => 'my_lab' } }
118+
let(:configuration) { {} }
119+
120+
it 'updates JAVA_OPTS sl.labId from the user provisioned service' do
121+
component.release
122+
123+
expect(java_opts).to include("-Dsl.labId=#{credentials['lab_id']}")
124+
end
125+
126+
it 'updates JAVA_OPTS sl.proxy from the user provisioned service' do
127+
component.release
128+
129+
expect(java_opts).to include("-Dsl.proxy=#{credentials['proxy']}")
130+
end
131+
end
114132

133+
context do
134+
let(:credentials) { { 'token' => 'my_token', 'proxy' => 'my_proxy', 'lab_id' => 'my_lab' } }
135+
136+
let(:configuration) do
137+
{ 'proxy' => '127.0.0.1:8888',
138+
'lab_id' => 'lab1' }
139+
end
140+
141+
it 'updates JAVA_OPTS sl.labId from config (and not user provisioned service)' do
142+
component.release
143+
144+
expect(java_opts).to include("-Dsl.labId=#{configuration['lab_id']}")
145+
end
146+
147+
it 'updates JAVA_OPTS sl.proxy from config (and not user provisioned service)' do
148+
component.release
149+
150+
expect(java_opts).to include("-Dsl.proxy=#{configuration['proxy']}")
151+
end
115152
end
116153

117154
end

0 commit comments

Comments
 (0)