-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- to avoid implementing always same builder logic for every PDS adapter a refactoring was done: - PDSAdapterConfigData is contained by every PDSAdapterConfig variant. PDS relevant config data is stored there now. - PDSAdapterConfiguratoris also contained now in every pds adapter config variant and is used for configuration by common PDSAdapterConfigurationStrategy - The data and the configuration is implemented in one class: PDSAdapterDataConfigurator - documented PDS adapter configuration in architecture concepts
- Loading branch information
Showing
26 changed files
with
579 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 1 addition & 10 deletions
11
sechub-adapter-pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.mercedesbenz.sechub.adapter.AdapterConfig; | ||
|
||
public interface PDSAdapterConfig extends AdapterConfig { | ||
|
||
Map<String, String> getJobParameters(); | ||
|
||
UUID getSecHubJobUUID(); | ||
|
||
String getPdsProductIdentifier(); | ||
public interface PDSAdapterConfig extends AdapterConfig, PDSAdapterConfigDataProvider { | ||
|
||
} |
27 changes: 1 addition & 26 deletions
27
...dapter-pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,7 @@ | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.mercedesbenz.sechub.adapter.AdapterConfigBuilder; | ||
import com.mercedesbenz.sechub.commons.model.SecHubConfigurationModel; | ||
|
||
public interface PDSAdapterConfigBuilder extends AdapterConfigBuilder { | ||
|
||
PDSAdapterConfigBuilder setBinariesTarFileInputStream(InputStream binariesTarFileInputStream); | ||
|
||
PDSAdapterConfigBuilder setSourceCodeZipFileInputStream(InputStream sourceCodeZipFileInputStream); | ||
|
||
PDSAdapterConfigBuilder setSecHubJobUUID(UUID sechubJobUUID); | ||
|
||
PDSAdapterConfigBuilder setSecHubConfigModel(SecHubConfigurationModel model); | ||
|
||
PDSAdapterConfigBuilder setSourceZipFileChecksum(String sourceZipFileChecksum); | ||
|
||
PDSAdapterConfigBuilder setPDSProductIdentifier(String productIdentifier); | ||
|
||
/** | ||
* Set job parameters - mandatory | ||
* | ||
* @param jobParameters a map with key values | ||
* @return builder | ||
*/ | ||
PDSAdapterConfigBuilder setJobParameters(Map<String, String> jobParameters); | ||
public interface PDSAdapterConfigBuilder extends AdapterConfigBuilder, PDSAdapterConfiguratorProvider { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...b-adapter-pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterConfigData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.mercedesbenz.sechub.commons.model.ScanType; | ||
import com.mercedesbenz.sechub.commons.model.SecHubConfigurationModel; | ||
|
||
public interface PDSAdapterConfigData { | ||
|
||
/** | ||
* @return an unmodifiable map with job parameters | ||
*/ | ||
Map<String, String> getJobParameters(); | ||
|
||
UUID getSecHubJobUUID(); | ||
|
||
String getPdsProductIdentifier(); | ||
|
||
InputStream getSourceCodeZipFileInputStreamOrNull(); | ||
|
||
String getSourceCodeZipFileChecksumOrNull(); | ||
|
||
InputStream getBinaryTarFileInputStreamOrNull(); | ||
|
||
boolean isReusingSecHubStorage(); | ||
|
||
boolean isSourceCodeZipFileRequired(); | ||
|
||
boolean isBinaryTarFileRequired(); | ||
|
||
SecHubConfigurationModel getSecHubConfigurationModel(); | ||
|
||
ScanType getScanType(); | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...r-pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterConfigDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
public interface PDSAdapterConfigDataProvider { | ||
|
||
PDSAdapterConfigData getPDSAdapterConfigData(); | ||
} |
64 changes: 64 additions & 0 deletions
64
...adapter-pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.mercedesbenz.sechub.commons.model.ScanType; | ||
import com.mercedesbenz.sechub.commons.model.SecHubConfigurationModel; | ||
|
||
public interface PDSAdapterConfigurator { | ||
|
||
void setPdsProductIdentifier(String pdsProductIdentifier); | ||
|
||
void setSourceCodeZipFileInputStreamOrNull(InputStream sourceCodeZipFileInputStreamOrNull); | ||
|
||
void setSourceCodeZipFileChecksumOrNull(String sourceCodeZipFileChecksumOrNull); | ||
|
||
void setBinaryTarFileInputStreamOrNull(InputStream binaryTarFileInputStreamOrNull); | ||
|
||
void setSecHubJobUUID(UUID secHubJobUUID); | ||
|
||
/** | ||
* Set job parameters - mandatory | ||
* | ||
* @param jobParameters a map with key values | ||
* @return builder | ||
*/ | ||
void setJobParameters(Map<String, String> jobParameters); | ||
|
||
void setSecHubConfigurationModel(SecHubConfigurationModel secHubConfigurationModel); | ||
|
||
void setReusingSecHubStorage(boolean reusingSecHubStorage); | ||
|
||
void setSourceCodeZipFileRequired(boolean sourceCodeZipFileRequired); | ||
|
||
void setBinaryTarFileRequired(boolean binaryTarFileRequired); | ||
|
||
void setScanType(ScanType scanType); | ||
|
||
/** | ||
* Will be automatically called by {@link #configure()}. and validates defined | ||
* parts only | ||
*/ | ||
void validateNonCalculatedParts(); | ||
|
||
/** | ||
* Will be automatically called by {@link #configure()}. If the calculated parts | ||
* needs a validation as well, this must be done also here. The | ||
* {@link #validateNonCalculatedParts()} method does only check the non | ||
* calculated parts. | ||
*/ | ||
void calculate(); | ||
|
||
/** | ||
* First {@link #validateNonCalculatedParts()} will be called by this method. | ||
* Then the {@link #calculate()} method is called. The default implementation | ||
* does this already and should not be changed. | ||
*/ | ||
public default void configure() { | ||
validateNonCalculatedParts(); | ||
calculate(); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterConfiguratorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
public interface PDSAdapterConfiguratorProvider { | ||
|
||
PDSAdapterConfigurator getPDSAdapterConfigurator(); | ||
} |
182 changes: 182 additions & 0 deletions
182
...ter-pds/src/main/java/com/mercedesbenz/sechub/adapter/pds/PDSAdapterDataConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package com.mercedesbenz.sechub.adapter.pds; | ||
|
||
import java.io.InputStream; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.mercedesbenz.sechub.commons.model.ScanType; | ||
import com.mercedesbenz.sechub.commons.model.SecHubConfigurationModel; | ||
import com.mercedesbenz.sechub.commons.model.SecHubConfigurationModelReducedCloningSupport; | ||
import com.mercedesbenz.sechub.commons.pds.PDSDefaultParameterKeyConstants; | ||
|
||
public class PDSAdapterDataConfigurator implements PDSAdapterConfigData, PDSAdapterConfigurator { | ||
private static final String EMPTY_TARGET_TYPE = ""; | ||
|
||
private String pdsProductIdentifier; | ||
private InputStream sourceCodeZipFileInputStreamOrNull; | ||
private String sourceCodeZipFileChecksumOrNull; | ||
private InputStream binaryTarFileInputStreamOrNull; | ||
private UUID secHubJobUUID; | ||
private Map<String, String> jobParameters; | ||
private SecHubConfigurationModel secHubConfigurationModel; | ||
private boolean reusingSecHubStorage; | ||
|
||
private boolean sourceCodeZipFileRequired; | ||
private boolean binaryTarFileRequired; | ||
private String targetType = EMPTY_TARGET_TYPE; | ||
private ScanType scanType; | ||
|
||
public void setTargetType(String targetType) { | ||
if (targetType == null) { | ||
this.targetType = EMPTY_TARGET_TYPE; | ||
} else { | ||
this.targetType = targetType; | ||
} | ||
} | ||
|
||
@Override | ||
public void setScanType(ScanType scanType) { | ||
this.scanType = scanType; | ||
} | ||
|
||
@Override | ||
public ScanType getScanType() { | ||
return scanType; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getJobParameters() { | ||
return Collections.unmodifiableMap(jobParameters); | ||
} | ||
|
||
public void addJobParameter(String key, String value) { | ||
jobParameters.put(key, value); | ||
} | ||
|
||
@Override | ||
public UUID getSecHubJobUUID() { | ||
return secHubJobUUID; | ||
} | ||
|
||
@Override | ||
public String getPdsProductIdentifier() { | ||
return pdsProductIdentifier; | ||
} | ||
|
||
@Override | ||
public InputStream getSourceCodeZipFileInputStreamOrNull() { | ||
return sourceCodeZipFileInputStreamOrNull; | ||
} | ||
|
||
@Override | ||
public String getSourceCodeZipFileChecksumOrNull() { | ||
return sourceCodeZipFileChecksumOrNull; | ||
} | ||
|
||
@Override | ||
public InputStream getBinaryTarFileInputStreamOrNull() { | ||
return binaryTarFileInputStreamOrNull; | ||
} | ||
|
||
@Override | ||
public boolean isReusingSecHubStorage() { | ||
return reusingSecHubStorage; | ||
} | ||
|
||
@Override | ||
public boolean isSourceCodeZipFileRequired() { | ||
return sourceCodeZipFileRequired; | ||
} | ||
|
||
@Override | ||
public boolean isBinaryTarFileRequired() { | ||
return binaryTarFileRequired; | ||
} | ||
|
||
@Override | ||
public SecHubConfigurationModel getSecHubConfigurationModel() { | ||
return secHubConfigurationModel; | ||
} | ||
|
||
@Override | ||
public void setPdsProductIdentifier(String pdsProductIdentifier) { | ||
this.pdsProductIdentifier = pdsProductIdentifier; | ||
} | ||
|
||
@Override | ||
public void setSourceCodeZipFileInputStreamOrNull(InputStream sourceCodeZipFileInputStreamOrNull) { | ||
this.sourceCodeZipFileInputStreamOrNull = sourceCodeZipFileInputStreamOrNull; | ||
} | ||
|
||
@Override | ||
public void setSourceCodeZipFileChecksumOrNull(String sourceCodeZipFileChecksumOrNull) { | ||
this.sourceCodeZipFileChecksumOrNull = sourceCodeZipFileChecksumOrNull; | ||
} | ||
|
||
@Override | ||
public void setBinaryTarFileInputStreamOrNull(InputStream binaryTarFileInputStreamOrNull) { | ||
this.binaryTarFileInputStreamOrNull = binaryTarFileInputStreamOrNull; | ||
} | ||
|
||
@Override | ||
public void setSecHubJobUUID(UUID secHubJobUUID) { | ||
this.secHubJobUUID = secHubJobUUID; | ||
} | ||
|
||
@Override | ||
public void setJobParameters(Map<String, String> jobParameters) { | ||
this.jobParameters = jobParameters; | ||
} | ||
|
||
@Override | ||
public void setSecHubConfigurationModel(SecHubConfigurationModel secHubConfigurationModel) { | ||
this.secHubConfigurationModel = secHubConfigurationModel; | ||
} | ||
|
||
public void setReusingSecHubStorage(boolean reusingSecHubStorage) { | ||
this.reusingSecHubStorage = reusingSecHubStorage; | ||
} | ||
|
||
public void setSourceCodeZipFileRequired(boolean sourceCodeZipFileRequired) { | ||
this.sourceCodeZipFileRequired = sourceCodeZipFileRequired; | ||
} | ||
|
||
public void setBinaryTarFileRequired(boolean binaryTarFileRequired) { | ||
this.binaryTarFileRequired = binaryTarFileRequired; | ||
} | ||
|
||
@Override | ||
public void validateNonCalculatedParts() { | ||
if (pdsProductIdentifier == null) { | ||
throw new IllegalStateException("pds product identifier not set!"); | ||
} | ||
if (jobParameters == null) { | ||
throw new IllegalStateException("job parameters not set!"); | ||
} | ||
if (secHubJobUUID == null) { | ||
throw new IllegalStateException("sechubJobUUID not set!"); | ||
} | ||
if (scanType == null) { | ||
throw new IllegalStateException("scanType not set!"); | ||
} | ||
if (targetType == null) { | ||
/* | ||
* remark: the target type is only set by network specific scans like infra | ||
* scan, or web scan, but not for code or license scans! | ||
*/ | ||
throw new IllegalStateException("targetType may notbe null!"); | ||
} | ||
} | ||
|
||
@Override | ||
public void calculate() { | ||
if (secHubConfigurationModel != null) { | ||
String reducedConfigJSON = SecHubConfigurationModelReducedCloningSupport.DEFAULT.createReducedScanConfigurationCloneJSON(secHubConfigurationModel, | ||
scanType); | ||
jobParameters.put(PDSDefaultParameterKeyConstants.PARAM_KEY_PDS_SCAN_CONFIGURATION, reducedConfigJSON); | ||
} | ||
jobParameters.put(PDSDefaultParameterKeyConstants.PARAM_KEY_PDS_SCAN_TARGET_TYPE, targetType); | ||
} | ||
|
||
} |
Oops, something went wrong.