Skip to content

Commit

Permalink
Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois committed Jan 13, 2025
1 parent 0636374 commit 12def24
Showing 1 changed file with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void register(
}
}
// Check error to avoid changing ID
List<Contract> contracts = contractor.contracts();
List<Contract> contractSTATIQUE = contractor.contracts();
if (injector != null) {
injector.setName(name);
injector.setExternal(false);
Expand All @@ -112,43 +112,53 @@ public void register(
injector
.getContracts()
.forEach(
contract -> {
contractDB -> {

// Contractor -> code static
// Injector -> code DB

// 1. contrat statique a changé
// 2. contrat dynamique a changé
Optional<Contract> current =
contracts.stream().filter(c -> c.getId().equals(contract.getId())).findFirst();
contractSTATIQUE.stream()
.filter(cSTATIQUE -> cSTATIQUE.getId().equals(contractDB.getId()))
.findFirst();
if (current.isPresent()) {
existing.add(contract.getId());
contract.setManual(current.get().isManual());
contract.setAtomicTesting(current.get().isAtomicTesting());
contract.setPlatforms(current.get().getPlatforms().toArray(new PLATFORM_TYPE[0]));
contract.setNeedsExecutor(current.get().isNeedsExecutor());
existing.add(contractDB.getId());
contractDB.setManual(current.get().isManual());
contractDB.setAtomicTesting(current.get().isAtomicTesting());
contractDB.setPlatforms(
current.get().getPlatforms().toArray(new PLATFORM_TYPE[0]));
contractDB.setNeedsExecutor(current.get().isNeedsExecutor());
Map<String, String> labels =
current.get().getLabel().entrySet().stream()
.collect(
Collectors.toMap(e -> e.getKey().toString(), Map.Entry::getValue));
contract.setLabels(labels);
contractDB.setLabels(labels);
// If no override of TTPs, retrieve those of the contract
if (contract.getAttackPatterns().isEmpty()) {
if (contractDB.getAttackPatterns().isEmpty()) {
if (!current.get().getAttackPatternsExternalIds().isEmpty()) {
List<AttackPattern> attackPatterns =
fromIterable(
attackPatternRepository.findAllByExternalIdInIgnoreCase(
current.get().getAttackPatternsExternalIds()));
contract.setAttackPatterns(attackPatterns);
contractDB.setAttackPatterns(attackPatterns);
}
}
try {
contract.setContent(mapper.writeValueAsString(current.get()));
contractDB.setContent(mapper.writeValueAsString(current.get()));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
toUpdates.add(contract);
} else if (!contract.getCustom()
&& (!injector.isPayloads() || contract.getPayload() == null)) {
toDeletes.add(contract.getId());
toUpdates.add(contractDB);
// pas custom && (pas de payloads OU payload est null)
} else if (!contractDB.getCustom()
&& (!injector.isPayloads() || contractDB.getPayload() == null)) {
toDeletes.add(contractDB.getId());
}
});
List<InjectorContract> toCreates =
contracts.stream()
contractSTATIQUE.stream()
.filter(c -> !existing.contains(c.getId()))
.map(
in -> {
Expand Down Expand Up @@ -199,7 +209,7 @@ public void register(
Injector savedInjector = injectorRepository.save(newInjector);
// Save the contracts
List<InjectorContract> injectorContracts =
contracts.stream()
contractSTATIQUE.stream()
.map(
in -> {
InjectorContract injectorContract = new InjectorContract();
Expand Down

0 comments on commit 12def24

Please sign in to comment.