|
| 1 | +# Encoding: utf-8 |
| 2 | +# Cloud Foundry Java Buildpack |
| 3 | +# Copyright 2013-2017 the original author or authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +require 'base64' |
| 18 | +require 'java_buildpack/component/versioned_dependency_component' |
| 19 | +require 'java_buildpack/framework' |
| 20 | + |
| 21 | +module JavaBuildpack |
| 22 | + module Framework |
| 23 | + |
| 24 | + # Encapsulates the functionality for enabling zero-touch Google Cloud Debugger support. |
| 25 | + class GoogleStackdriverDebugger < JavaBuildpack::Component::VersionedDependencyComponent |
| 26 | + |
| 27 | + # (see JavaBuildpack::Component::BaseComponent#compile) |
| 28 | + def compile |
| 29 | + download_tar false |
| 30 | + |
| 31 | + credentials = @application.services.find_service(FILTER)['credentials'] |
| 32 | + write_json_file credentials[PRIVATE_KEY_DATA] |
| 33 | + end |
| 34 | + |
| 35 | + # (see JavaBuildpack::Component::BaseComponent#release) |
| 36 | + def release |
| 37 | + java_opts = @droplet.java_opts |
| 38 | + |
| 39 | + java_opts |
| 40 | + .add_agentpath_with_props(@droplet.sandbox + 'cdbg_java_agent.so', '--logtostderr' => 1) |
| 41 | + .add_system_property('com.google.cdbg.auth.serviceaccount.enable', true) |
| 42 | + .add_system_property('com.google.cdbg.auth.serviceaccount.jsonfile', json_file) |
| 43 | + .add_system_property('com.google.cdbg.module', @application.details['application_name']) |
| 44 | + .add_system_property('com.google.cdbg.version', @application.details['application_version']) |
| 45 | + end |
| 46 | + |
| 47 | + protected |
| 48 | + |
| 49 | + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) |
| 50 | + def supports? |
| 51 | + @application.services.one_service? FILTER, PRIVATE_KEY_DATA |
| 52 | + end |
| 53 | + |
| 54 | + FILTER = /google-stackdriver-debugger/ |
| 55 | + |
| 56 | + PRIVATE_KEY_DATA = 'PrivateKeyData'.freeze |
| 57 | + |
| 58 | + private_constant :FILTER, :PRIVATE_KEY_DATA |
| 59 | + |
| 60 | + private |
| 61 | + |
| 62 | + def json_file |
| 63 | + @droplet.sandbox + 'svc.json' |
| 64 | + end |
| 65 | + |
| 66 | + def write_json_file(json_file_data) |
| 67 | + FileUtils.mkdir_p json_file.parent |
| 68 | + json_file.open(File::CREAT | File::WRONLY) do |f| |
| 69 | + f.write "#{Base64.decode64 json_file_data}\n" |
| 70 | + f.sync |
| 71 | + f |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + end |
| 76 | + |
| 77 | + end |
| 78 | +end |
0 commit comments