18
18
require 'fileutils'
19
19
require 'shellwords'
20
20
require 'tempfile'
21
- require 'java_buildpack/component/versioned_dependency_component '
21
+ require 'java_buildpack/component/base_component '
22
22
require 'java_buildpack/framework'
23
23
require 'java_buildpack/util/qualify_path'
24
24
25
25
module JavaBuildpack
26
26
module Framework
27
27
28
- # Encapsulates the functionality for enabling zero-touch Safenet ProtectApp Java Security Provider support .
29
- class CloudSqlSecurityProvider < JavaBuildpack ::Component ::VersionedDependencyComponent
28
+ # Encapsulates the functionality for enabling secure communication with GCP CloudSQL instances .
29
+ class CloudSqlSecurityProvider < JavaBuildpack ::Component ::BaseComponent
30
30
include JavaBuildpack ::Util
31
31
32
32
# (see JavaBuildpack::Component::BaseComponent#compile)
33
33
def compile
34
- log '#release' . yellow
35
- download_zip false
34
+ return unless supports?
36
35
37
36
@droplet . copy_resources
38
37
@@ -41,22 +40,26 @@ def compile
41
40
pkcs12 = merge_client_credentials credentials
42
41
add_client_credentials pkcs12
43
42
44
- add_trusted_certificates credentials [ 'sslrootcert' ]
43
+ add_trusted_certificate credentials [ 'sslrootcert' ]
45
44
end
46
45
47
46
# (see JavaBuildpack::Component::BaseComponent#release)
48
47
def release
49
- log '#release' . yellow
48
+ return unless supports?
49
+
50
50
java_opts = @droplet . java_opts
51
51
52
52
add_additional_properties ( java_opts )
53
53
end
54
54
55
+ def detect
56
+ CloudSqlSecurityProvider . to_s . dash_case
57
+ end
58
+
55
59
protected
56
60
57
61
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
58
62
def supports?
59
- log '#supports?' . yellow
60
63
@application . services . one_service? FILTER , 'sslrootcert' , 'sslcert' , 'sslkey'
61
64
end
62
65
@@ -67,9 +70,6 @@ def supports?
67
70
private_constant :FILTER
68
71
69
72
70
- def log ( message )
71
- puts "#{ '===========>' . blue } #{ 'CloudSqlSecurityProvider' . red . bold } #{ message } "
72
- end
73
73
def add_additional_properties ( java_opts )
74
74
java_opts
75
75
. add_system_property ( 'javax.net.ssl.keyStore' , keystore )
@@ -82,10 +82,12 @@ def add_client_credentials(pkcs12)
82
82
" -alias #{ File . basename ( pkcs12 ) } "
83
83
end
84
84
85
- def add_trusted_certificates ( trusted_certificate )
86
- File . open ( "#{ @droplet . root } /etc/ssl/certs/ca-certificates.crt" , 'a' ) do |f |
87
- f . write ( "#{ trusted_certificate } \n " )
88
- end
85
+ def add_trusted_certificate ( trusted_certificate )
86
+ cert = Tempfile . new ( 'ca-cert-' )
87
+ cert . write ( trusted_certificate )
88
+ cert . close
89
+
90
+ shell "#{ keytool } -import -trustcacerts -cacerts -storepass changeit -noprompt -alias CloudSQLCA -file #{ cert . path } "
89
91
end
90
92
91
93
def ext_dir
0 commit comments