diff --git a/build.gradle b/build.gradle index ecc4964..cc826d8 100644 --- a/build.gradle +++ b/build.gradle @@ -18,11 +18,10 @@ plugins { id 'java' - id "io.spring.dependency-management" version "1.0.6.RELEASE" } group 'com.continuumsecurity.elasticagent' -version '2.2.2' +version '2.3.0' // these values that go into plugin.xml project.ext.pluginDesc = [ @@ -35,42 +34,51 @@ project.ext.pluginDesc = [ vendorUrl : 'https://github.com/continuumsecurity/GoCD-EC2-Elastic-Agent-Plugin' ] -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 repositories { - jcenter() mavenCentral() } sourceSets { test { java { - compileClasspath += configurations.compileOnly - runtimeClasspath += configurations.compileOnly resources.srcDirs += ['src/main/resource-templates'] } } } +ext { + deps = [ + gocdPluginApi: 'cd.go.plugin:go-plugin-api:23.5.0', + ] +} + dependencies { - compileOnly group: 'cd.go.plugin', name: 'go-plugin-api', version: '19.8.0' - - compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' - compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' - compile group: 'com.google.guava', name: 'guava', version: '23.0' - compile group: 'joda-time', name: 'joda-time', version: '2.10.3' - compile group: 'commons-io', name: 'commons-io', version: '2.6' - compile group: 'org.freemarker', name: 'freemarker', version: '2.3.29' - compile group: 'software.amazon.awssdk', name: 'ec2', version: '2.10.30' - - testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.2' - testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.3.2' - testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.3.2' - testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1' - testCompile group: 'org.mockito', name: 'mockito-core', version: '3.0.0' - testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.0.0' - testCompile group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.0' + compileOnly project.deps.gocdPluginApi + + implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' + implementation(group: 'com.google.guava', name: 'guava', version: '33.0.0-jre') { + // see https://github.com/google/guava/pull/6606 + exclude(module: 'listenablefuture') + exclude(module: 'error_prone_annotations') + exclude(module: 'checker-qual') + exclude(module: 'jsr305') + } + implementation group: 'joda-time', name: 'joda-time', version: '2.12.7' + implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.32' + implementation group: 'software.amazon.awssdk', name: 'ec2', version: '2.25.38' + + testImplementation project.deps.gocdPluginApi + testImplementation platform('org.junit:junit-bom:5.10.2') + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params' + testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' + testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.11.0' + testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.11.0' + testImplementation group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1' } processResources { @@ -112,7 +120,7 @@ test { } jar { - from(configurations.compile) { + from(configurations.runtimeClasspath) { into "lib/" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca9d628..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,127 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,25 +25,29 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,48 +55,36 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2AgentInstances.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2AgentInstances.java index 6fb74fa..302f811 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2AgentInstances.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2AgentInstances.java @@ -23,12 +23,11 @@ import com.continuumsecurity.elasticagent.ec2.models.JobIdentifier; import com.continuumsecurity.elasticagent.ec2.models.StatusReport; import com.continuumsecurity.elasticagent.ec2.requests.CreateAgentRequest; -import org.apache.commons.lang3.StringUtils; +import com.google.common.base.Joiner; import org.joda.time.Period; import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.ec2.model.*; -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Semaphore; @@ -183,7 +182,7 @@ public void refreshAll(ClusterProfileProperties clusterProfileProperties) throws Map properties = new HashMap<>(); properties.put("ec2_ami", instance.imageId()); properties.put("ec2_instance_type", instance.instanceTypeAsString()); - properties.put("ec2_sg", StringUtils.join(instance.securityGroups(), ",")); + properties.put("ec2_sg", Joiner.on(',').join(instance.securityGroups())); properties.put("ec2_subnets", instance.subnetId()); properties.put("ec2_key", instance.keyName()); @@ -308,7 +307,6 @@ private void register(Ec2Instance instance) { instances.put(instance.id(), instance); } - @Nullable private static String getTag(List tags, String key) { for (Tag tag : tags) { if (tag.key().equals(key)) { diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2Instance.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2Instance.java index da4f57b..a354072 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2Instance.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2Instance.java @@ -76,6 +76,7 @@ public static Ec2Instance create(CreateAgentRequest request, PluginSettings sett "echo \"wrapper.app.parameter.103=NONE\" >> /usr/share/go-agent/wrapper-config/wrapper-properties.conf\n" + "mkdir -p /var/lib/go-agent/config\n" + "echo \"agent.auto.register.key=" + request.autoRegisterKey() + "\" > /var/lib/go-agent/config/autoregister.properties\n" + + (request.hasEnvironment() ? "echo \"agent.auto.register.environments=" + request.environment().trim() + "\" > /var/lib/go-agent/config/autoregister.properties\n" : "") + "HTTP_CODE=`curl -I http://169.254.169.254 | head -n 1 | cut -d$' ' -f2`\n" + "if [[ HTTP_CODE -eq 200 ]];\n" + @@ -93,8 +94,13 @@ public static Ec2Instance create(CreateAgentRequest request, PluginSettings sett "chown -R go:go /var/lib/go-agent/\n" + "chown -R go:go /usr/share/go-agent/\n"; - if (request.properties().get("ec2_user_data") != null) { - userdata += request.properties().get("ec2_user_data") + "\n"; + String additionalUserData = request.properties().get("ec2_user_data"); + if (additionalUserData != null) { + userdata += additionalUserData + "\n"; + + if (additionalUserData.contains("agent.auto.register.environments")) { + consoleLogAppender.accept("The instance user data for this profile may contain an overridden GoCD environment. This may cause issues with GoCD, and should no longer be required with `2.3.0+` of the plugin."); + } } userdata += "systemctl start go-agent.service\n"; diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/MemorySpecification.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/MemorySpecification.java deleted file mode 100644 index cabaf49..0000000 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/MemorySpecification.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.continuumsecurity.elasticagent.ec2; - -import com.google.common.collect.ImmutableSortedMap; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.apache.commons.lang3.StringUtils.isBlank; - -/** - * Parse memory specification. Expected format is: - * - */ -public class MemorySpecification { - private static final Pattern PATTERN = Pattern.compile("(\\d+(\\.\\d+)?)(\\D)"); - - private static final Map SUFFIXES = ImmutableSortedMap.orderedBy(String.CASE_INSENSITIVE_ORDER) - .put("M", BigDecimal.valueOf(1024L * 1024L)) - .put("G", BigDecimal.valueOf(1024L * 1024L * 1024L)) - .put("T", BigDecimal.valueOf(1024L * 1024L * 1024L * 1024L)) - .build(); - - private List errors = new ArrayList<>(); - private Long memory; - - MemorySpecification(String memory) { - this.memory = parse(memory, errors); - } - - Long getMemory() { - return memory; - } - - public static Long parse(String memory, List errors) { - if (isBlank(memory)) { - return null; - } - - final Matcher matcher = PATTERN.matcher(memory); - if (!matcher.matches()) { - errors.add("Invalid size: " + memory); - return null; - } - - final BigDecimal size = new BigDecimal(matcher.group(1)); - final BigDecimal unit = SUFFIXES.get(matcher.group(3)); - if (unit == null) { - errors.add("Invalid size: " + memory + ". Wrong size unit"); - return null; - } - - return size.multiply(unit).longValue(); - } - - public List getErrors() { - return errors; - } -} diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/PluginSettings.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/PluginSettings.java index ac8ff28..6854e74 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/PluginSettings.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/PluginSettings.java @@ -26,7 +26,8 @@ import org.joda.time.Period; import software.amazon.awssdk.regions.Region; -import static org.apache.commons.lang3.StringUtils.isBlank; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; + public class PluginSettings { public static final Gson GSON = new GsonBuilder() @@ -149,7 +150,7 @@ private static Region region(String configuredRegion) { Region newRegion = Region.of(configuredRegion); if (!Region.regions().contains(newRegion)) { - throw new IllegalArgumentException("Region does not exist."); + throw new IllegalArgumentException("Region " + newRegion + " does not exist."); } return newRegion; diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/AgentStatusReportExecutor.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/AgentStatusReportExecutor.java index ce05f53..bdfb10d 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/AgentStatusReportExecutor.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/AgentStatusReportExecutor.java @@ -33,10 +33,10 @@ import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; import freemarker.template.Template; import freemarker.template.TemplateException; -import org.apache.commons.lang3.StringUtils; import java.io.IOException; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; import static java.lang.String.format; public class AgentStatusReportExecutor { @@ -60,7 +60,7 @@ public GoPluginApiResponse execute() throws Exception { LOG.info(format("[status-report] Generating status report for agent: %s with job: %s", elasticAgentId, jobIdentifier)); try { - if (StringUtils.isNotBlank(elasticAgentId)) { + if (!isBlank(elasticAgentId)) { return getStatusReportUsingElasticAgentId(elasticAgentId); } return getStatusReportUsingJobIdentifier(jobIdentifier); diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutor.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutor.java index 08b172d..a058b7a 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutor.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutor.java @@ -49,7 +49,7 @@ public GoPluginApiResponse execute() throws Exception { pluginRequest.appendToConsoleLog(request.jobIdentifier(), message); }; - consoleLogAppender.accept(String.format("Received request to create an instance for %s at %s", request.jobIdentifier().getRepresentation(), new DateTime().toString("yyyy-MM-dd HH:mm:ss ZZ"))); + consoleLogAppender.accept(String.format("Received request to create an instance for %s in env %s at %s", request.jobIdentifier().getRepresentation(), request.hasEnvironment() ? request.environment() : "", new DateTime().toString("yyyy-MM-dd HH:mm:ss ZZ"))); try { agentInstances.create(request, pluginRequest, consoleLogAppender); diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Field.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Field.java index 547a2d9..0497cbd 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Field.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Field.java @@ -21,10 +21,6 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; public class Field { @@ -60,16 +56,6 @@ public Field(String key, String displayName, String defaultValue, Boolean requir this.displayOrder = displayOrder; } - public Map validate(String input) { - HashMap result = new HashMap<>(); - String validationError = doValidate(input); - if (StringUtils.isNotBlank(validationError)) { - result.put("key", key); - result.put("message", validationError); - } - return result; - } - protected String doValidate(String input) { return null; } diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLField.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLField.java index d6d3a24..71d1d8d 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLField.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLField.java @@ -22,7 +22,7 @@ import java.net.URL; import static com.continuumsecurity.elasticagent.ec2.executors.GetClusterProfileMetadataExecutor.GO_SERVER_URL; -import static org.apache.commons.lang3.StringUtils.isBlank; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; public class GoServerURLField extends Field { diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLMetadata.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLMetadata.java index 10c5981..a75fe6f 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLMetadata.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/GoServerURLMetadata.java @@ -21,7 +21,8 @@ import java.net.URISyntaxException; import java.net.URL; -import static org.apache.commons.lang3.StringUtils.isBlank; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; + public class GoServerURLMetadata extends Metadata { private static String GO_SERVER_URL = "go_server_url"; diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Metadata.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Metadata.java index a65c514..2c780d9 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Metadata.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/Metadata.java @@ -18,14 +18,14 @@ package com.continuumsecurity.elasticagent.ec2.executors; +import com.continuumsecurity.elasticagent.ec2.utils.Util; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; public class Metadata { @@ -53,7 +53,7 @@ public Metadata(String key, ProfileMetadata metadata) { public Map validate(String input) { HashMap result = new HashMap<>(); String validationError = doValidate(input); - if (isNotBlank(validationError)) { + if (!isBlank(validationError)) { result.put("key", key); result.put("message", validationError); } @@ -62,7 +62,7 @@ public Map validate(String input) { protected String doValidate(String input) { if (isRequired()) { - if (StringUtils.isBlank(input)) { + if (Util.isBlank(input)) { return this.key + " must not be blank."; } } diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/MigrateConfigurationRequestExecutor.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/MigrateConfigurationRequestExecutor.java index 2bd4752..cb93f13 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/MigrateConfigurationRequestExecutor.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/MigrateConfigurationRequestExecutor.java @@ -20,7 +20,6 @@ import com.continuumsecurity.elasticagent.ec2.requests.MigrateConfigurationRequest; import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse; import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse; -import org.apache.commons.lang3.StringUtils; import java.util.Arrays; import java.util.List; @@ -29,6 +28,7 @@ import java.util.stream.Collectors; import static com.continuumsecurity.elasticagent.ec2.Ec2Plugin.LOG; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; public class MigrateConfigurationRequestExecutor implements RequestExecutor { @@ -111,6 +111,6 @@ private GoPluginApiResponse getGoPluginApiResponse(PluginSettings pluginSettings } private boolean arePluginSettingsConfigured(PluginSettings pluginSettings) { - return !StringUtils.isBlank(pluginSettings.getGoServerUrl()); + return !isBlank(pluginSettings.getGoServerUrl()); } } diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NonBlankField.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NonBlankField.java index 5bc2388..6941a8c 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NonBlankField.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NonBlankField.java @@ -18,7 +18,7 @@ package com.continuumsecurity.elasticagent.ec2.executors; -import org.apache.commons.lang3.StringUtils; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; public class NonBlankField extends Field { @@ -28,7 +28,7 @@ public NonBlankField(String key, String displayName, String defaultValue, Boolea @Override public String doValidate(String input) { - if (StringUtils.isBlank(input)) { + if (isBlank(input)) { return this.displayName + " must not be blank."; } return null; diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NumberMetadata.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NumberMetadata.java index 231d5a4..93acd0e 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NumberMetadata.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/executors/NumberMetadata.java @@ -17,7 +17,7 @@ package com.continuumsecurity.elasticagent.ec2.executors; -import static org.apache.commons.lang3.StringUtils.isBlank; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; public class NumberMetadata extends Metadata { diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/models/ExceptionMessage.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/models/ExceptionMessage.java index efecb73..4fab913 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/models/ExceptionMessage.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/models/ExceptionMessage.java @@ -22,7 +22,7 @@ import java.io.PrintWriter; import java.io.StringWriter; -import static org.apache.commons.lang3.StringUtils.isBlank; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; public class ExceptionMessage { private final Throwable throwable; diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/models/JobIdentifier.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/models/JobIdentifier.java index ac94f25..43815de 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/models/JobIdentifier.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/models/JobIdentifier.java @@ -23,10 +23,9 @@ import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; -import org.apache.commons.lang3.StringUtils; - import java.util.Objects; +import static com.continuumsecurity.elasticagent.ec2.utils.Util.isBlank; import static java.text.MessageFormat.format; public class JobIdentifier { @@ -103,7 +102,7 @@ public String getStageCounter() { } public String getRepresentation() { - if (StringUtils.isBlank(representation)) { + if (isBlank(representation)) { this.representation = format("{0}/{1}/{2}/{3}/{4}", pipelineName, pipelineCounter, stageName, stageCounter, jobName); } return representation; diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/requests/CreateAgentRequest.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/requests/CreateAgentRequest.java index 248969d..269e23f 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/requests/CreateAgentRequest.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/requests/CreateAgentRequest.java @@ -18,15 +18,15 @@ package com.continuumsecurity.elasticagent.ec2.requests; -import com.continuumsecurity.elasticagent.ec2.*; +import com.continuumsecurity.elasticagent.ec2.AgentInstances; +import com.continuumsecurity.elasticagent.ec2.ClusterProfileProperties; +import com.continuumsecurity.elasticagent.ec2.PluginRequest; +import com.continuumsecurity.elasticagent.ec2.RequestExecutor; import com.continuumsecurity.elasticagent.ec2.executors.CreateAgentRequestExecutor; import com.continuumsecurity.elasticagent.ec2.models.JobIdentifier; -import org.apache.commons.lang3.StringUtils; +import com.continuumsecurity.elasticagent.ec2.utils.Util; -import java.io.IOException; -import java.io.StringWriter; import java.util.Map; -import java.util.Properties; import static com.continuumsecurity.elasticagent.ec2.Ec2Plugin.GSON; @@ -34,6 +34,7 @@ public class CreateAgentRequest { private String autoRegisterKey; private JobIdentifier jobIdentifier; + private String environment; private Map elasticAgentProfileProperties; private ClusterProfileProperties clusterProfileProperties; @@ -43,11 +44,13 @@ public CreateAgentRequest() { public CreateAgentRequest(String autoRegisterKey, Map elasticAgentProfileProperties, JobIdentifier jobIdentifier, - Map clusterProfileProperties) { + Map clusterProfileProperties, + String environment) { this.autoRegisterKey = autoRegisterKey; - this.elasticAgentProfileProperties = elasticAgentProfileProperties; this.jobIdentifier = jobIdentifier; + this.elasticAgentProfileProperties = elasticAgentProfileProperties; this.clusterProfileProperties = ClusterProfileProperties.fromConfiguration(clusterProfileProperties); + this.environment = environment; } public CreateAgentRequest(String autoRegisterKey, @@ -68,39 +71,20 @@ public JobIdentifier jobIdentifier() { return jobIdentifier; } - public static CreateAgentRequest fromJSON(String json) { - return GSON.fromJson(json, CreateAgentRequest.class); + public String environment() { + return environment; } - public RequestExecutor executor(AgentInstances agentInstances, PluginRequest pluginRequest) { - return new CreateAgentRequestExecutor(this, agentInstances, pluginRequest); + public boolean hasEnvironment() { + return !Util.isBlank(environment); } - public Properties autoregisterProperties(String elasticAgentId) { - Properties properties = new Properties(); - - if (StringUtils.isNotBlank(autoRegisterKey)) { - properties.put("agent.auto.register.key", autoRegisterKey); - } - - properties.put("agent.auto.register.elasticAgent.agentId", elasticAgentId); - properties.put("agent.auto.register.elasticAgent.pluginId", Constants.PLUGIN_ID); - - return properties; + public static CreateAgentRequest fromJSON(String json) { + return GSON.fromJson(json, CreateAgentRequest.class); } - public String autoregisterPropertiesAsEnvironmentVars(String elasticAgentId) { - Properties properties = autoregisterProperties(elasticAgentId); - - StringWriter writer = new StringWriter(); - - try { - properties.store(writer, ""); - } catch (IOException e) { - throw new RuntimeException(e); - } - - return writer.toString(); + public RequestExecutor executor(AgentInstances agentInstances, PluginRequest pluginRequest) { + return new CreateAgentRequestExecutor(this, agentInstances, pluginRequest); } public Map properties() { diff --git a/src/main/java/com/continuumsecurity/elasticagent/ec2/utils/Util.java b/src/main/java/com/continuumsecurity/elasticagent/ec2/utils/Util.java index e347a12..7af2a76 100644 --- a/src/main/java/com/continuumsecurity/elasticagent/ec2/utils/Util.java +++ b/src/main/java/com/continuumsecurity/elasticagent/ec2/utils/Util.java @@ -29,14 +29,11 @@ import java.io.InputStreamReader; import java.io.StringReader; import java.nio.charset.StandardCharsets; -import java.text.DecimalFormat; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Properties; -import static org.apache.commons.lang3.StringUtils.isBlank; - public class Util { public static String readResource(String resourceFile) { @@ -79,10 +76,7 @@ public String apply(String input) { }); } - public static String readableSize(long size) { - if (size <= 0) return "0"; - final String[] units = new String[]{"B", "KB", "MB", "GB", "TB", "PB", "EB"}; - int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); - return new DecimalFormat("#,##0.##").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; + public static boolean isBlank(String value) { + return value == null || value.isBlank(); } } diff --git a/src/test/java/com/continuumsecurity/elasticagent/ec2/Properties.java b/src/test/java/com/continuumsecurity/elasticagent/ec2/Properties.java index 42949cb..861d19a 100644 --- a/src/test/java/com/continuumsecurity/elasticagent/ec2/Properties.java +++ b/src/test/java/com/continuumsecurity/elasticagent/ec2/Properties.java @@ -3,9 +3,9 @@ public interface Properties { String SERVER_URL = "https://your.gocd.server/"; - String ACCESS_KEY_ID = "ACCES_KEY_ID"; + String ACCESS_KEY_ID = "ACCESS_KEY_ID"; String SECRET_ACCESS_KEY = "SECRET_ACCESS_KEY"; - String REGION = "default_aws_region"; + String REGION = "us-east-1"; String AMI_ID = "ami-id"; String KEY = "key"; String SUBNETS = "subnet-1,subnet-2,subnet-3"; diff --git a/src/test/java/com/continuumsecurity/elasticagent/ec2/Test.java b/src/test/java/com/continuumsecurity/elasticagent/ec2/Test.java index bdae404..d195419 100644 --- a/src/test/java/com/continuumsecurity/elasticagent/ec2/Test.java +++ b/src/test/java/com/continuumsecurity/elasticagent/ec2/Test.java @@ -8,7 +8,6 @@ import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.ec2.model.*; -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -119,7 +118,6 @@ public static void main(String[] args) { } - @Nullable private static String getTag(List tags, String key) { for (Tag tag : tags) { if (tag.key().equals(key)) { diff --git a/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutorTest.java b/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutorTest.java index 651efca..bdc4038 100644 --- a/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutorTest.java +++ b/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/CreateAgentRequestExecutorTest.java @@ -31,11 +31,11 @@ public class CreateAgentRequestExecutorTest { @Test - public void shouldAskDockerContainersToCreateAnAgent() throws Exception { + public void shouldAskAgentInstancesToCreateAnAgent() throws Exception { final HashMap elasticAgentProfileProperties = new HashMap<>(); elasticAgentProfileProperties.put("Image", "image1"); final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1L, "l1", "s1", "1", "j1", 1L); - CreateAgentRequest request = new CreateAgentRequest("key1", elasticAgentProfileProperties, jobIdentifier, new HashMap<>()); + CreateAgentRequest request = new CreateAgentRequest("key1", elasticAgentProfileProperties, jobIdentifier, new HashMap<>(), "my_env"); AgentInstances agentInstances = mock(Ec2AgentInstances.class); PluginRequest pluginRequest = mock(PluginRequest.class); @@ -50,7 +50,7 @@ public void shouldLogErrorMessageToConsoleIfAgentCreateFails() throws Exception final HashMap elasticAgentProfileProperties = new HashMap<>(); elasticAgentProfileProperties.put("Image", "image1"); final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1L, "l1", "s1", "1", "j1", 1L); - CreateAgentRequest request = new CreateAgentRequest("key1", elasticAgentProfileProperties, jobIdentifier, new HashMap<>()); + CreateAgentRequest request = new CreateAgentRequest("key1", elasticAgentProfileProperties, jobIdentifier, new HashMap<>(), "my_env"); AgentInstances agentInstances = mock(Ec2AgentInstances.class); PluginRequest pluginRequest = mock(PluginRequest.class); diff --git a/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/GetProfileMetadataExecutorTest.java b/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/GetProfileMetadataExecutorTest.java index 28a3673..9e055e2 100644 --- a/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/GetProfileMetadataExecutorTest.java +++ b/src/test/java/com/continuumsecurity/elasticagent/ec2/executors/GetProfileMetadataExecutorTest.java @@ -80,14 +80,14 @@ public void assertJsonStructure() throws Exception { " }\n" + " },\n" + " {\n" + - " \"key\": \"ec2_instance_profile\",\n" + + " \"key\": \"ec2_user_data\",\n" + " \"metadata\": {\n" + " \"required\": false,\n" + " \"secure\": false\n" + " }\n" + " },\n" + " {\n" + - " \"key\": \"ec2_user_data\",\n" + + " \"key\": \"ec2_instance_profile\",\n" + " \"metadata\": {\n" + " \"required\": false,\n" + " \"secure\": false\n" +