@@ -65,41 +65,57 @@ void createRuntimeConfigurations() {
6565 baseConfiguration .loadFromConfigMapIfChanged ();
6666
6767 // Get List of engagement types from base config
68- List <String > engagementTypes = getEngagementTypes ();
68+ Collection <String > engagementTypes = getEngagementOptions (). keySet ();
6969
70- engagementTypes .stream (). forEach (this ::createOverrideConfig );
70+ engagementTypes .forEach (this ::createOverrideConfig );
7171 LOGGER .debug ("override configurations: {}" , overrideConfigurations .keySet ());
7272
7373 }
7474
75+ @ SuppressWarnings ("unchecked" )
76+ public Map <Object , Object > getArtifactOptions () {
77+ Map <String , Object > configuration = baseConfiguration .getConfiguration ();
78+ List <Map <String , Object >> typesList = Optional .of (configuration )
79+ .map (m -> (Map <String , Object >) m .get ("artifact_options" ))
80+ .map (m -> (Map <String , Object >) m .get ("types" ))
81+ .map (m -> (List <Map <String , Object >>) m .get ("options" )).orElse (new ArrayList <>());
82+
83+ return typesList .stream ().collect (Collectors .toMap (s -> s .get ("value" ), s -> s .get ("label" )));
84+ }
85+
86+
7587 /**
76- * Returns a {@link List} of {@link String} engagement type values from the
77- * configured base {@link RuntimeConfiguration}. Otherwise, an empty
78- * {@link List} is returned.
79- *
80- * @return
88+ * Returns a {@link Map} of {@link String} engagement type key / values from the
89+ * configured base {@link RuntimeConfiguration}. Empty if none found
90+ *
91+ * @return a map of engagements
8192 */
82- @ SuppressWarnings ("unchecked" )
83- List <String > getEngagementTypes () {
93+ public Map <String , String > getEngagementOptions () {
94+ return getEngagementOptions ("engagement_types" );
95+ }
8496
97+ public Map <String , String > getEngagementRegionOptions () {
98+ return getEngagementOptions ("engagement_regions" );
99+ }
100+
101+ @ SuppressWarnings ("unchecked" )
102+ private Map <String , String > getEngagementOptions (String type ) {
85103 Map <String , Object > configuration = baseConfiguration .getConfiguration ();
86104 List <Map <String , Object >> typesList = Optional .of (configuration )
87105 .map (m -> (Map <String , Object >) m .get ("basic_information" ))
88- .map (m -> (Map <String , Object >) m .get ("engagement_types" ))
106+ .map (m -> (Map <String , Object >) m .get (type ))
89107 .map (m -> (List <Map <String , Object >>) m .get ("options" )).orElse (new ArrayList <>());
90108
91- return typesList .stream ().flatMap (m -> m .entrySet ().stream ()).filter (e -> e .getKey ().equals ("value" ))
92- .map (e -> e .getValue ().toString ()).collect (Collectors .toList ());
93-
109+ return typesList .stream ().collect (Collectors .toMap (s -> (String ) s .get ("value" ), s -> (String ) s .get ("label" )));
94110 }
95111
96112 /**
97113 * Creates and adds a {@link RuntimeConfiguration} to the override
98114 * configurations {@link Map} for the given engagement type.
99- *
100- * @param engagementType
115+ *
116+ * @param engagementType - the type of engagement
101117 */
102- void createOverrideConfig (String engagementType ) {
118+ void createOverrideConfig (String engagementType ) {
103119 String filePath = this .runtimeBaseConfig .replaceAll ("base" , engagementType );
104120 RuntimeConfiguration rc = RuntimeConfiguration .builder ().filePath (filePath ).build ();
105121 if (rc .checkPath ()) {
@@ -116,29 +132,33 @@ void createOverrideConfig(String engagementType) {
116132 * configuration will be returned.
117133 *
118134 * @param engagementType
119- * @return
135+ * @return a map of runtime configurations
120136 */
121- public String getRuntimeConfiguration (Optional <String > engagementType ) {
137+ public Map < String , Object > mapRuntimeConfiguration (Optional <String > engagementType ) {
122138
123139 // get map for base configuration
124140 Map <String , Object > base = baseConfiguration .getConfiguration ();
125141
126142 if (engagementType .isPresent () && overrideConfigurations .containsKey (engagementType .get ())) {
127143
128144 Map <String , Object > override = overrideConfigurations .get (engagementType .get ()).getConfiguration ();
129- return jsonb . toJson ( MarshalUtils .merge (base , override ) );
145+ base = MarshalUtils .merge (base , override );
130146
131147 }
132148
133- return jsonb . toJson ( base ) ;
149+ return base ;
134150
135151 }
152+
153+ public String getRuntimeConfiguration (Optional <String > engagementType ) {
154+ return jsonb .toJson (mapRuntimeConfiguration (engagementType ));
155+ }
136156
137157 /**
138158 * Returns a mapping of engagement type to rbac access indicating the groups
139159 * that can write engagements. The purpose is to inform the front end on a user's
140160 * ability to write data for an engagement
141- * @return
161+ * @return a map of permissions per group
142162 */
143163 @ SuppressWarnings ("unchecked" )
144164 public Map <String , Set <String >> getPermission () {
0 commit comments