Skip to content

Commit

Permalink
optionMapper accepts null
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Nov 12, 2024
1 parent 2661652 commit f1c16f1
Showing 1 changed file with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,32 @@ private void configureDatabase() {
}

private void configureStorage() {
TrustifySpec.StorageSpec storageSpec = cr.getSpec().storageSpec();
TrustifySpec.StorageStrategyType storageStrategyType = Objects.nonNull(storageSpec) && Objects.nonNull(storageSpec.type()) ? storageSpec.type() : TrustifySpec.StorageStrategyType.FILESYSTEM;
List<EnvVar> envVars = new ArrayList<>();

List<EnvVar> envVars = optionMapper(storageSpec)
.mapOption("TRUSTD_STORAGE_COMPRESSION", spec -> Objects.nonNull(spec) && Objects.nonNull(spec.compression()) ? spec.compression().getValue() : null)
.mapOption("TRUSTD_STORAGE_STRATEGY", spec -> storageStrategyType.getValue())
.getEnvVars();
TrustifySpec.StorageSpec storageSpec = Optional.ofNullable(cr.getSpec().storageSpec())
.orElse(new TrustifySpec.StorageSpec(null, null, null, null));

// Storage type
TrustifySpec.StorageStrategyType storageStrategyType = Objects.nonNull(storageSpec.type()) ? storageSpec.type() : TrustifySpec.StorageStrategyType.FILESYSTEM;
envVars.add(new EnvVarBuilder()
.withName("TRUSTD_STORAGE_STRATEGY")
.withValue(storageStrategyType.getValue())
.build()
);

// Other config
envVars.addAll(optionMapper(storageSpec)
.mapOption("TRUSTD_STORAGE_COMPRESSION", spec -> Objects.nonNull(spec.compression()) ? spec.compression().getValue() : null)
.getEnvVars()
);

switch (storageStrategyType) {
case FILESYSTEM -> {
List<EnvVar> filesystemEnvVars = optionMapper(storageSpec)
.mapOption("TRUSTD_STORAGE_FS_PATH", spec -> "/opt/trustify/storage")
.getEnvVars();
envVars.addAll(filesystemEnvVars);
envVars.add(new EnvVarBuilder()
.withName("TRUSTD_STORAGE_FS_PATH")
.withValue("/opt/trustify/storage")
.build()
);

var volume = new VolumeBuilder()
.withName("trustify-pvol")
Expand All @@ -154,17 +166,13 @@ private void configureStorage() {
allVolumeMounts.add(volumeMount);
}
case S3 -> {
List<EnvVar> s3EnvVars = Optional.ofNullable(storageSpec)
.flatMap(spec -> Optional.ofNullable(spec.s3StorageSpec()))
.map(spec -> optionMapper(spec)
.mapOption("TRUSTD_S3_BUCKET", TrustifySpec.S3StorageSpec::bucket)
.mapOption("TRUSTD_S3_REGION", TrustifySpec.S3StorageSpec::region)
.mapOption("TRUSTD_S3_ACCESS_KEY", TrustifySpec.S3StorageSpec::accessKey)
.mapOption("TRUSTD_S3_SECRET_KEY", TrustifySpec.S3StorageSpec::secretKey)
.getEnvVars()
)
.orElseGet(ArrayList::new);
envVars.addAll(s3EnvVars);
envVars.addAll(optionMapper(storageSpec.s3StorageSpec())
.mapOption("TRUSTD_S3_BUCKET", TrustifySpec.S3StorageSpec::bucket)
.mapOption("TRUSTD_S3_REGION", TrustifySpec.S3StorageSpec::region)
.mapOption("TRUSTD_S3_ACCESS_KEY", TrustifySpec.S3StorageSpec::accessKey)
.mapOption("TRUSTD_S3_SECRET_KEY", TrustifySpec.S3StorageSpec::secretKey)
.getEnvVars()
);
}
}

Expand Down

0 comments on commit f1c16f1

Please sign in to comment.