1515# See the License for the specific language governing permissions and
1616# limitations under the License.
1717
18+ require 'java_buildpack/component/versioned_dependency_component'
1819require 'java_buildpack/framework'
1920
2021module JavaBuildpack
2122 module Framework
2223
2324 # Encapsulates the functionality for running with Checkmarx IAST Agent
24- class CheckmarxIastAgent < JavaBuildpack ::Component ::BaseComponent
25+ class CheckmarxIastAgent < JavaBuildpack ::Component ::VersionedDependencyComponent
2526 include JavaBuildpack ::Util
2627
2728 # Creates an instance. In addition to the functionality inherited from +BaseComponent+, +@version+ and +@uri+
2829 # instance variables are exposed.
2930 #
3031 # @param [Hash] context a collection of utilities used by components
3132 def initialize ( context )
32- super ( context )
33-
34- # Save the IAST server URL in server, if found
35- service = @application . services . find_service ( FILTER , 'server' )
36- @server = service [ 'credentials' ] [ 'server' ] . chomp '/' if service
37- end
33+ @application = context [ :application ]
34+ @component_name = self . class . to_s . space_case
35+ @configuration = context [ :configuration ]
36+ @droplet = context [ :droplet ]
37+
38+ if supports?
39+ @version = ''
40+ @uri = @application . services . find_service ( FILTER , 'server' ) [ 'credentials' ] [ 'server' ] . chomp +
41+ '/iast/compilation/download/JAVA'
42+ end
3843
39- # (see JavaBuildpack::Component::BaseComponent#detect)
40- def detect
41- @server
44+ @logger = JavaBuildpack ::Logging ::LoggerFactory . instance . get_logger DynatraceOneAgent
4245 end
4346
4447 # (see JavaBuildpack::Component::BaseComponent#compile)
4548 def compile
46- # Download and extract the agent from the IAST server
47- FileUtils . mkdir_p @droplet . sandbox
48- # curl --insecure: most IAST servers will use self-signed SSL
49- shell 'curl --fail --insecure --silent --show-error ' \
50- "#{ @server } /iast/compilation/download/JAVA -o #{ @droplet . sandbox } /cx-agent.zip"
51- shell "unzip #{ @droplet . sandbox } /cx-agent.zip -d #{ @droplet . sandbox } "
49+ JavaBuildpack ::Util ::Cache ::InternetAvailability . instance . available (
50+ true , 'The Checkmarx IAST download location is always accessible'
51+ ) do
52+ download_zip ( false )
53+ end
5254
5355 # Disable cache (no point, when running in a container)
54- File . open ( " #{ @droplet . sandbox } / #{ OVERRIDE_CONFIG } " , 'a' ) do |file |
55- file . write ( "\n enableWeavedClassCache=false\n " )
56+ File . open ( @droplet . sandbox + 'cx_agent.override.properties' , 'a' ) do |f |
57+ f . write ( "\n enableWeavedClassCache=false\n " )
5658 end
5759 end
5860
@@ -63,25 +65,27 @@ def release
6365 # Default team to CxServer if not set as env var
6466 team = ENV [ 'cxTeam' ] || 'CxServer'
6567
66- javaagent = "-javaagent:#{ qualify_path ( @droplet . sandbox + JAVA_AGENT_JAR , @droplet . root ) } "
6768 @droplet . java_opts
68- . add_preformatted_options ( javaagent )
69- . add_preformatted_options ( '-Xverify:none' )
70- . add_system_property ( 'cx.logToConsole' , 'true' )
71- . add_system_property ( 'cx.appName' , application_name )
72- . add_system_property ( 'cxAppTag' , app_tag )
73- . add_system_property ( 'cxTeam' , team )
69+ . add_javaagent ( @droplet . sandbox + 'cx-launcher.jar' )
70+ . add_preformatted_options ( '-Xverify:none' )
71+ . add_system_property ( 'cx.logToConsole' , 'true' )
72+ . add_system_property ( 'cx.appName' , application_name )
73+ . add_system_property ( 'cxAppTag' , app_tag )
74+ . add_system_property ( 'cxTeam' , team )
7475 end
7576
76- private
77+ protected
7778
78- JAVA_AGENT_JAR = 'cx-launcher.jar'
79+ # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
80+ def supports?
81+ @application . services . find_service ( FILTER , 'server' )
82+ end
7983
80- OVERRIDE_CONFIG = 'cx_agent.override.properties'
84+ private
8185
8286 FILTER = /^checkmarx-iast$/ . freeze
8387
84- private_constant :JAVA_AGENT_JAR , : FILTER, :OVERRIDE_CONFIG
88+ private_constant :FILTER
8589
8690 def application_name
8791 @application . details [ 'application_name' ] || 'ROOT'
0 commit comments