Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:[CORE-1207] fix for data dog reported issue with policy - Enable_… #1484

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.amazonaws.util.StringUtils;
import com.google.common.collect.HashMultimap;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
Expand Down Expand Up @@ -85,32 +86,16 @@ private boolean checkAddonEnabledForKubernetes(String esUrl, Map<String, Object>
if (resultJson != null && resultJson.has(PacmanRuleConstants.HITS)) {
String hitsString = resultJson.get(PacmanRuleConstants.HITS).toString();
logger.debug("hit content in result json: {}", hitsString);
JsonObject hitsJson = (JsonObject) parser.parse(hitsString);
JsonArray hitsJsonArray = hitsJson.getAsJsonObject().get(PacmanRuleConstants.HITS).getAsJsonArray();
if (hitsJsonArray.size() > 0) {
JsonObject jsonDataItem = (JsonObject) ((JsonObject) hitsJsonArray.get(0))
.get(PacmanRuleConstants.SOURCE);
logger.debug("Validating the data item: {}", jsonDataItem);
Gson gson = new Gson();
Map<String,Object> hitsMap = gson.fromJson(hitsString, Map.class);
Optional<Boolean> isAddonEnabledOptional = Optional.ofNullable(hitsMap.get(PacmanRuleConstants.HITS)).map(obj -> (List<Map<String, Object>>) obj).map(obj -> obj.get(0))
.map(obj -> (Map<String, Object>) obj.get(PacmanRuleConstants.SOURCE)).map(obj -> (Map<String, Object>) obj.get(PacmanRuleConstants.PROPERTIES))
.map(obj -> (Map<String, Object>) obj.get(PacmanRuleConstants.ADDON_PROFILES)).map(obj -> (Map<String, Object>) obj.get(PacmanRuleConstants.AZURE_POLICY))
.map(obj -> (Boolean) obj.get(PacmanRuleConstants.ENABLED));

JsonObject properties=jsonDataItem.getAsJsonObject().get(PacmanRuleConstants.PROPERTIES).getAsJsonObject();
logger.debug("Validating the properties: {}",properties);

JsonObject addonProfiles=properties.getAsJsonObject().get(PacmanRuleConstants.ADDON_PROFILES).getAsJsonObject();
logger.debug("Validating the addon Profiles: {}",addonProfiles);

if(addonProfiles!=null) {
JsonObject azurePolicy = addonProfiles.getAsJsonObject().get(PacmanRuleConstants.AZURE_POLICY).getAsJsonObject();
logger.debug("Validating the azurePolicy: {}", azurePolicy);

if (azurePolicy != null) {
boolean isAddonEnabled = azurePolicy.get(PacmanRuleConstants.ENABLED).getAsBoolean();

if (isAddonEnabled) {
validationResult = true;
}
}
}
}
if(isAddonEnabledOptional.isPresent()){
validationResult = isAddonEnabledOptional.get();
}
}
return validationResult;
}
Expand Down
Loading