Skip to content

Commit 8ad0be0

Browse files
committed
Polishing
[resolves #741] Signed-off-by: Ben Hale <[email protected]>
1 parent 18d37aa commit 8ad0be0

File tree

8 files changed

+69
-272
lines changed

8 files changed

+69
-272
lines changed

.idea/dictionaries/bhale.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The buildpack supports extension through the use of Git repository forking. The
103103
* [Metric Writer](docs/framework-metric_writer.md) ([Configuration](docs/framework-metric_writer.md#configuration))
104104
* [New Relic Agent](docs/framework-new_relic_agent.md) ([Configuration](docs/framework-new_relic_agent.md#configuration))
105105
* [PostgreSQL JDBC](docs/framework-postgresql_jdbc.md) ([Configuration](docs/framework-postgresql_jdbc.md#configuration))
106-
* [ProtectApp Security Provider](docs/framework-protect_app_security_provider.md) ([Configuration](docs/framework-protect_app_security_provider.md#configuration))
106+
* [ProtectApp Security Provider](docs/framework-protect_app_security_provider.md) ([Configuration](docs/framework-protect_app_security_provider.md#configuration))
107107
* [Riverbed AppInternals Agent](docs/framework-riverbed_appinternals_agent.md) ([Configuration](docs/framework-riverbed_appinternals_agent.md#configuration))
108108
* [Seeker Security Provider](docs/framework-seeker_security_provider.md) ([Configuration](docs/framework-seeker_security_provider.md#configuration))
109109
* [Spring Auto Reconfiguration](docs/framework-spring_auto_reconfiguration.md) ([Configuration](docs/framework-spring_auto_reconfiguration.md#configuration))

config/seeker_agent.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Seeker Security Provider Framework
2+
The Seeker Security Provider Framework causes an application to be bound with a [Seeker Security Provider][s] service instance.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound Seeker Security Provider service. The existence of a provider service is defined by the <a href="http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES"><code>VCAP_SERVICES</code></a> payload containing a service name, label or tag with <code>seeker</code> as a substring.
7+
</td>
8+
</tr>
9+
<tr>
10+
<td><strong>Tags</strong></td>
11+
<td><tt>seeker-service-provider</tt></td>
12+
</tr>
13+
</table>
14+
Tags are printed to standard output by the buildpack detect script
15+
16+
## User-Provided Service
17+
When binding Appinternals using a user-provided service, it must have <code>seeker</code> as substring. The credential payload must contain the following entries:
18+
19+
| Name | Description
20+
| ---- | -----------
21+
| `seeker_server_url` | The fully qualified URL of a Synopsys Seeker Server (e.g. `https://seeker.example.com`)
22+
23+
**NOTE**
24+
In order to use this integration, the Seeker Server version must be at least `2019.08` or later.

lib/java_buildpack/framework/seeker_security_provider.rb

Lines changed: 27 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -15,163 +15,78 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
require 'java_buildpack/logging/logger_factory'
1918
require 'java_buildpack/component/base_component'
2019
require 'java_buildpack/framework'
21-
require 'fileutils'
22-
require 'net/http'
23-
require 'json'
24-
require 'date'
25-
require 'cgi'
20+
require 'java_buildpack/util/dash_case'
2621

2722
module JavaBuildpack
2823
module Framework
2924

3025
# Encapsulates the functionality for enabling zero-touch Seeker support.
3126
class SeekerSecurityProvider < JavaBuildpack::Component::BaseComponent
27+
3228
# Creates an instance
3329
#
3430
# @param [Hash] context a collection of utilities used the component
3531
def initialize(context)
3632
super(context)
37-
@logger = JavaBuildpack::Logging::LoggerFactory.instance.get_logger SeekerSecurityProvider
33+
34+
@uri = download_url(credentials) if supports?
3835
end
3936

4037
# (see JavaBuildpack::Component::BaseComponent#detect)
4138
def detect
42-
@application.services.one_service? FILTER
39+
@uri ? self.class.to_s.dash_case : nil
4340
end
4441

4542
# (see JavaBuildpack::Component::BaseComponent#compile)
46-
4743
def compile
48-
@logger.info { 'Seeker buildpack compile stage start' }
49-
credentials = fetch_credentials
50-
@logger.info { "Credentials #{credentials}" }
51-
assert_configuration_valid(credentials)
52-
if should_download_sensor(credentials[ENTERPRISE_SERVER_URL_SERVICE_CONFIG_KEY])
53-
fetch_agent_within_sensor(credentials)
54-
else
55-
fetch_agent_direct(credentials)
44+
JavaBuildpack::Util::Cache::InternetAvailability.instance.available(
45+
true, 'Downloading from Synopsys Seeker Server'
46+
) do
47+
download_zip('', @uri, false, @droplet.sandbox, @component_name)
5648
end
5749
@droplet.copy_resources
58-
end
59-
60-
# extract seeker relevant configuration as map
61-
def fetch_credentials
62-
service = @application.services.find_service FILTER
63-
service['credentials']
64-
end
65-
66-
# verify required agent configuration is present
67-
def assert_configuration_valid(credentials)
68-
mandatory_config_keys =
69-
[ENTERPRISE_SERVER_URL_SERVICE_CONFIG_KEY, SENSOR_HOST_SERVICE_CONFIG_KEY,
70-
SENSOR_PORT_SERVICE_CONFIG_KEY, SEEKER_SERVER_URL_CONFIG_KEY]
71-
mandatory_config_keys.each do |config_key|
72-
raise "'#{config_key}' credential must be set" unless credentials[config_key]
73-
end
50+
rescue StandardError => e
51+
raise "Synopsys Seeker download failed: #{e}"
7452
end
7553

7654
# (see JavaBuildpack::Component::BaseComponent#release)
7755
def release
78-
@logger.info { 'Seeker buildpack release stage start' }
79-
credentials = fetch_credentials
56+
c = credentials
57+
8058
@droplet.java_opts.add_javaagent(@droplet.sandbox + 'seeker-agent.jar')
8159
@droplet.environment_variables
82-
.add_environment_variable('SEEKER_SENSOR_HOST', credentials[SENSOR_HOST_SERVICE_CONFIG_KEY])
83-
.add_environment_variable('SEEKER_SENSOR_HTTP_PORT', credentials[SENSOR_PORT_SERVICE_CONFIG_KEY])
84-
.add_environment_variable('SEEKER_SERVER_URL', credentials[SEEKER_SERVER_URL_CONFIG_KEY])
60+
.add_environment_variable('SEEKER_SERVER_URL', c[SEEKER_SERVER_URL_CONFIG_KEY])
8561
end
8662

87-
# JSON key for the host of the seeker sensor
88-
SENSOR_HOST_SERVICE_CONFIG_KEY = 'sensor_host'
89-
90-
# JSON key for the port of the seeker sensor
91-
SENSOR_PORT_SERVICE_CONFIG_KEY = 'sensor_port'
92-
# JSON key for the address of seeker sensor
93-
SEEKER_SERVER_URL_CONFIG_KEY = 'seeker_server_url'
94-
95-
# Enterprise server url, for example: `https://seeker-server.com:8082`
96-
ENTERPRISE_SERVER_URL_SERVICE_CONFIG_KEY = 'enterprise_server_url'
97-
98-
# Relative path of the sensor zip
99-
SENSOR_ZIP_RELATIVE_PATH_AT_ENTERPRISE_SERVER = 'rest/ui/installers/binaries/LINUX'
100-
101-
# Relative path of the Java agent jars after Sensor extraction
102-
AGENT_JARS_PATH = 'inline/agents/java/*'
63+
private
10364

10465
# Relative path of the agent zip
10566
AGENT_PATH = '/rest/api/latest/installers/agents/binaries/JAVA'
10667

107-
# Version details of Seekers server REST API path
108-
SEEKER_VERSION_API = '/rest/api/version'
109-
11068
# seeker service name identifier
111-
FILTER = /seeker/.freeze
112-
113-
private_constant :SENSOR_HOST_SERVICE_CONFIG_KEY, :SENSOR_PORT_SERVICE_CONFIG_KEY,
114-
:ENTERPRISE_SERVER_URL_SERVICE_CONFIG_KEY, :SENSOR_ZIP_RELATIVE_PATH_AT_ENTERPRISE_SERVER,
115-
:AGENT_JARS_PATH, :AGENT_PATH, :SEEKER_VERSION_API
116-
117-
private
118-
119-
def should_download_sensor(server_base_url)
120-
json_response = get_seeker_version_details(server_base_url)
121-
@logger.debug { "Seeker server response for version WS: #{json_response}" }
122-
seeker_version_response = JSON.parse(json_response)
123-
seeker_version = seeker_version_response['version']
124-
version_prefix = seeker_version[0, 7]
125-
last_seeker_version_without_agent_direct_download_date = Date.parse('2018.05.01')
126-
@logger.info { "Current Seeker version #{version_prefix}" }
127-
current_seeker_version = Date.parse(version_prefix + '.01')
128-
current_seeker_version <= last_seeker_version_without_agent_direct_download_date
129-
end
69+
FILTER = /seeker/i.freeze
13070

131-
def get_seeker_version_details(server_base_url)
132-
uri = URI.parse(server_base_url)
133-
http = Net::HTTP.new(uri.host, uri.port)
134-
if uri.scheme == 'https'
135-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
136-
http.use_ssl = true
137-
end
138-
http_response = http.request_get(SEEKER_VERSION_API)
139-
http_response.body
140-
end
71+
# JSON key for the address of seeker sensor
72+
SEEKER_SERVER_URL_CONFIG_KEY = 'seeker_server_url'
14173

142-
def agent_direct_link(credentials)
143-
URI.join(credentials[ENTERPRISE_SERVER_URL_SERVICE_CONFIG_KEY], AGENT_PATH).to_s
144-
end
74+
private_constant :AGENT_PATH, :FILTER, :SEEKER_SERVER_URL_CONFIG_KEY
14575

146-
def fetch_agent_direct(credentials)
147-
@logger.info { 'Trying to download agent directly...' }
148-
java_agent_zip_uri = agent_direct_link(credentials)
149-
download_agent(java_agent_zip_uri)
76+
def credentials
77+
@application.services.find_service(FILTER, SEEKER_SERVER_URL_CONFIG_KEY)['credentials']
15078
end
15179

152-
def download_agent(java_agent_zip_uri)
153-
@logger.debug { "Before downloading Agent from: #{java_agent_zip_uri}" }
154-
download_zip('', java_agent_zip_uri, false, @droplet.sandbox)
80+
def download_url(credentials)
81+
"#{credentials[SEEKER_SERVER_URL_CONFIG_KEY]}#{AGENT_PATH}"
15582
end
15683

157-
def fetch_agent_within_sensor(credentials)
158-
@logger.info { 'Trying to download sensor...' }
159-
seeker_tmp_dir = @droplet.sandbox + 'seeker_tmp_sensor'
160-
shell "rm -rf #{seeker_tmp_dir}"
161-
sensor_direct_link = sensor_direct_link(credentials)
162-
@logger.debug { "Before downloading Sensor from: #{sensor_direct_link}" }
163-
download_zip('', sensor_direct_link,
164-
false, seeker_tmp_dir, 'SensorInstaller.zip')
165-
inner_jar_file = seeker_tmp_dir + 'SeekerInstaller.jar'
166-
# Unzip only the java agent - to save time
167-
shell "unzip -j #{inner_jar_file} #{AGENT_JARS_PATH} -d #{@droplet.sandbox} 2>&1"
168-
shell "rm -rf #{seeker_tmp_dir}"
84+
def supports?
85+
@application.services.one_service?(FILTER, SEEKER_SERVER_URL_CONFIG_KEY)
16986
end
17087

171-
def sensor_direct_link(credentials)
172-
enterprise_server_uri = URI.parse(credentials[ENTERPRISE_SERVER_URL_SERVICE_CONFIG_KEY].strip)
173-
URI.join(enterprise_server_uri, SENSOR_ZIP_RELATIVE_PATH_AT_ENTERPRISE_SERVER).to_s
174-
end
17588
end
89+
17690
end
91+
17792
end

spec/fixtures/sensor.zip

-762 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)