@@ -62,34 +62,40 @@ public class AgentOptionsParser {
6262 private final TeamscaleConfig teamscaleConfig ;
6363 private final String environmentConfigId ;
6464 private final String environmentConfigFile ;
65+ @ Nullable
6566 private final TeamscaleCredentials credentials ;
67+ @ Nullable
68+ private final String environmentAccessToken ;
6669 private final List <Exception > collectedErrors ;
6770
6871 /**
6972 * Parses the given command-line options.
7073 *
71- * @param environmentConfigId The Profiler configuration ID given via an environment variable.
72- * @param environmentConfigFile The Profiler configuration file given via an environment variable.
74+ * @param environmentConfigId The Profiler configuration ID given via an environment variable.
75+ * @param environmentConfigFile The Profiler configuration file given via an environment variable.
76+ * @param credentials Optional Teamscale credentials from a teamscale.properties file.
77+ * @param environmentAccessToken Optional access token for accessing Teamscale, read from an env variable.
7378 */
7479 public static Pair <AgentOptions , List <Exception >> parse (String optionsString , String environmentConfigId ,
75- String environmentConfigFile ,
76- @ Nullable TeamscaleCredentials credentials ,
80+ String environmentConfigFile , @ Nullable TeamscaleCredentials credentials ,
81+ @ Nullable String environmentAccessToken ,
7782 ILogger logger ) throws AgentOptionParseException , AgentOptionReceiveException {
7883 AgentOptionsParser parser = new AgentOptionsParser (logger , environmentConfigId , environmentConfigFile ,
79- credentials );
84+ credentials , environmentAccessToken );
8085 AgentOptions options = parser .parse (optionsString );
8186 return Pair .createPair (options , parser .getCollectedErrors ());
8287 }
8388
8489 @ VisibleForTesting
8590 AgentOptionsParser (ILogger logger , String environmentConfigId , String environmentConfigFile ,
86- TeamscaleCredentials credentials ) {
91+ @ Nullable TeamscaleCredentials credentials , @ Nullable String environmentAccessToken ) {
8792 this .logger = logger ;
8893 this .filePatternResolver = new FilePatternResolver (logger );
8994 this .teamscaleConfig = new TeamscaleConfig (logger , filePatternResolver );
9095 this .environmentConfigId = environmentConfigId ;
9196 this .environmentConfigFile = environmentConfigFile ;
9297 this .credentials = credentials ;
98+ this .environmentAccessToken = environmentAccessToken ;
9399 this .collectedErrors = Lists .newArrayList ();
94100 }
95101
@@ -126,6 +132,9 @@ public void throwOnCollectedErrors() throws Exception {
126132 options .teamscaleServer .userName = credentials .userName ;
127133 options .teamscaleServer .userAccessToken = credentials .accessKey ;
128134 }
135+ if (environmentAccessToken != null ) {
136+ options .teamscaleServer .userAccessToken = environmentAccessToken ;
137+ }
129138
130139 if (!StringUtils .isEmpty (optionsString )) {
131140 String [] optionParts = optionsString .split ("," );
@@ -179,7 +188,7 @@ private void handleConfigId(AgentOptions options) throws AgentOptionReceiveExcep
179188 readConfigFromTeamscale (options );
180189 }
181190
182- private void handleConfigFile (AgentOptions options ) throws AgentOptionParseException , AgentOptionReceiveException {
191+ private void handleConfigFile (AgentOptions options ) throws AgentOptionParseException {
183192 if (environmentConfigFile != null ) {
184193 handleOptionPart (options , "config-file=" + environmentConfigFile );
185194 }
@@ -195,7 +204,7 @@ private void handleConfigFile(AgentOptions options) throws AgentOptionParseExcep
195204 * Parses and stores the given option in the format <code>key=value</code>.
196205 */
197206 private void handleOptionPart (AgentOptions options ,
198- String optionPart ) throws AgentOptionParseException , AgentOptionReceiveException {
207+ String optionPart ) throws AgentOptionParseException {
199208 Pair <String , String > keyAndValue = parseOption (optionPart );
200209 handleOption (options , keyAndValue .getFirst (), keyAndValue .getSecond ());
201210 }
@@ -204,7 +213,7 @@ private void handleOptionPart(AgentOptions options,
204213 * Parses and stores the option with the given key and value.
205214 */
206215 private void handleOption (AgentOptions options ,
207- String key , String value ) throws AgentOptionParseException , AgentOptionReceiveException {
216+ String key , String value ) throws AgentOptionParseException {
208217 if (key .startsWith (DEBUG )) {
209218 handleDebugOption (options , value );
210219 return ;
@@ -299,7 +308,7 @@ private Pair<String, String> parseOption(String optionPart) throws AgentOptionPa
299308 * @return true if it has successfully processed the given option.
300309 */
301310 private boolean handleAgentOptions (AgentOptions options , String key , String value )
302- throws AgentOptionParseException , AgentOptionReceiveException {
311+ throws AgentOptionParseException {
303312 switch (key ) {
304313 case "config-id" :
305314 options .teamscaleServer .configId = value ;
@@ -447,7 +456,7 @@ public static <T extends Enum<T>> T parseEnumValue(String key, String value, Cla
447456 * excludes=third.party.*
448457 */
449458 private void readConfigFromFile (AgentOptions options ,
450- File configFile ) throws AgentOptionParseException , AgentOptionReceiveException {
459+ File configFile ) throws AgentOptionParseException {
451460 try {
452461 String content = FileSystemUtils .readFileUTF8 (configFile );
453462 readConfigFromString (options , content );
@@ -460,8 +469,7 @@ private void readConfigFromFile(AgentOptions options,
460469 }
461470 }
462471
463- private void readConfigFromString (AgentOptions options ,
464- String content ) throws AgentOptionParseException , AgentOptionReceiveException {
472+ private void readConfigFromString (AgentOptions options , String content ) {
465473 List <String > configFileKeyValues = org .conqat .lib .commons .string .StringUtils .splitLinesAsList (
466474 content );
467475 for (String optionKeyValue : configFileKeyValues ) {
0 commit comments