Skip to content

Commit

Permalink
Feat: Download Publication Archive after Upload to AssetManager (#181)
Browse files Browse the repository at this point in the history
* Add Download of uploaded files

* Fix Unit-Tests

* Sonar

* fix: updated License.txt and Readme.txt

* feat: dispatch build
- dispach build
- git: ignore .DS_Store files

* Revert "feat: dispatch build"

This reverts commit 693b0ff.

* fix: update spring boot 2.6.7

* Revert "Revert "feat: dispatch build""

This reverts commit b5d2914.

* Update License Header and Third Party Notices

Co-authored-by: Andreas Scheibal <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
3 people committed May 12, 2022
1 parent 062f5ec commit 4e0c283
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 176 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: ci-main
on:
workflow_dispatch:

push:
branches:
- main
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ build/
!/tools/*.sh

certs/*
.DS_Store
78 changes: 39 additions & 39 deletions THIRD-PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ThirdParty Licenses
| com.fasterxml:classmate:1.5.1 | Apache License, Version 2.0 |
| com.fasterxml.jackson.core:jackson-annotations:2.13.2 | The Apache Software License, Version 2.0 |
| com.fasterxml.jackson.core:jackson-core:2.13.2 | The Apache Software License, Version 2.0 |
| com.fasterxml.jackson.core:jackson-databind:2.13.2.2 | The Apache Software License, Version 2.0 |
| com.fasterxml.jackson.core:jackson-databind:2.13.2.1 | The Apache Software License, Version 2.0 |
| com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2 | The Apache Software License, Version 2.0 |
| com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.2 | The Apache Software License, Version 2.0 |
| com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.2 | The Apache Software License, Version 2.0 |
Expand Down Expand Up @@ -47,7 +47,7 @@ ThirdParty Licenses
| io.github.openfeign:feign-slf4j:11.8 | The Apache Software License, Version 2.0 |
| io.github.openfeign.form:feign-form:3.8.0 | The Apache Software License, Version 2.0 |
| io.github.openfeign.form:feign-form-spring:3.8.0 | The Apache Software License, Version 2.0 |
| io.micrometer:micrometer-core:1.8.4 | The Apache Software License, Version 2.0 |
| io.micrometer:micrometer-core:1.8.5 | The Apache Software License, Version 2.0 |
| io.swagger.core.v3:swagger-annotations:2.1.12 | Apache License 2.0 |
| io.swagger.core.v3:swagger-core:2.1.12 | Apache License 2.0 |
| io.swagger.core.v3:swagger-models:2.1.12 | Apache License 2.0 |
Expand All @@ -74,9 +74,9 @@ ThirdParty Licenses
| org.apache.httpcomponents:httpcore:4.4.15 | Apache License, Version 2.0 |
| org.apache.logging.log4j:log4j-api:2.17.2 | Apache License, Version 2.0 |
| org.apache.logging.log4j:log4j-to-slf4j:2.17.2 | Apache License, Version 2.0 |
| org.apache.tomcat.embed:tomcat-embed-core:9.0.60 | Apache License, Version 2.0 |
| org.apache.tomcat.embed:tomcat-embed-el:9.0.60 | Apache License, Version 2.0 |
| org.apache.tomcat.embed:tomcat-embed-websocket:9.0.60 | Apache License, Version 2.0 |
| org.apache.tomcat.embed:tomcat-embed-core:9.0.62 | Apache License, Version 2.0 |
| org.apache.tomcat.embed:tomcat-embed-el:9.0.62 | Apache License, Version 2.0 |
| org.apache.tomcat.embed:tomcat-embed-websocket:9.0.62 | Apache License, Version 2.0 |
| org.apiguardian:apiguardian-api:1.1.2 | The Apache License, Version 2.0 |
| org.aspectj:aspectjweaver:1.9.7 | Eclipse Public License - v 2.0 |
| org.assertj:assertj-core:3.21.0 | Apache License, Version 2.0 |
Expand Down Expand Up @@ -115,45 +115,45 @@ ThirdParty Licenses
| org.springdoc:springdoc-openapi-common:1.6.6 | The Apache License, Version 2.0 |
| org.springdoc:springdoc-openapi-ui:1.6.6 | The Apache License, Version 2.0 |
| org.springdoc:springdoc-openapi-webmvc-core:1.6.6 | The Apache License, Version 2.0 |
| org.springframework:spring-aop:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-aspects:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-beans:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-context:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-core:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-expression:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-jcl:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-jdbc:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-orm:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-test:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-tx:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-web:5.3.18 | Apache License, Version 2.0 |
| org.springframework:spring-webmvc:5.3.18 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-actuator:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-actuator-autoconfigure:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-autoconfigure:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-actuator:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-aop:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-data-jpa:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-jdbc:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-json:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-logging:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-test:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-tomcat:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-validation:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-web:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-test:2.6.6 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-test-autoconfigure:2.6.6 | Apache License, Version 2.0 |
| org.springframework:spring-aop:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-aspects:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-beans:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-context:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-core:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-expression:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-jcl:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-jdbc:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-orm:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-test:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-tx:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-web:5.3.19 | Apache License, Version 2.0 |
| org.springframework:spring-webmvc:5.3.19 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-actuator:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-actuator-autoconfigure:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-autoconfigure:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-actuator:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-aop:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-data-jpa:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-jdbc:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-json:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-logging:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-test:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-tomcat:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-validation:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-starter-web:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-test:2.6.7 | Apache License, Version 2.0 |
| org.springframework.boot:spring-boot-test-autoconfigure:2.6.7 | Apache License, Version 2.0 |
| org.springframework.cloud:spring-cloud-commons:3.1.1 | Apache License, Version 2.0 |
| org.springframework.cloud:spring-cloud-context:3.1.1 | Apache License, Version 2.0 |
| org.springframework.cloud:spring-cloud-openfeign-core:3.1.1 | Apache License, Version 2.0 |
| org.springframework.cloud:spring-cloud-starter:3.1.1 | Apache License, Version 2.0 |
| org.springframework.cloud:spring-cloud-starter-openfeign:3.1.1 | Apache License, Version 2.0 |
| org.springframework.data:spring-data-commons:2.6.3 | Apache License, Version 2.0 |
| org.springframework.data:spring-data-jpa:2.6.3 | Apache License, Version 2.0 |
| org.springframework.security:spring-security-core:5.6.2 | Apache License, Version 2.0 |
| org.springframework.security:spring-security-crypto:5.6.2 | Apache License, Version 2.0 |
| org.springframework.data:spring-data-commons:2.6.4 | Apache License, Version 2.0 |
| org.springframework.data:spring-data-jpa:2.6.4 | Apache License, Version 2.0 |
| org.springframework.security:spring-security-core:5.6.3 | Apache License, Version 2.0 |
| org.springframework.security:spring-security-crypto:5.6.3 | Apache License, Version 2.0 |
| org.springframework.security:spring-security-rsa:1.0.10.RELEASE | Apache 2.0 |
| org.springframework.security:spring-security-web:5.6.2 | Apache License, Version 2.0 |
| org.webjars:swagger-ui:4.5.0 | Apache 2.0 |
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<version>2.6.7</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -210,6 +210,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand All @@ -52,14 +53,22 @@ ResponseEntity<Void> uploadFile(@RequestHeader(HttpHeaders.AUTHORIZATION) String
@RequestBody byte[] file);

@PostMapping(
value = "/ocs/v2.php/apps/files/api/v2/synchronize",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
value = "/ocs/v2.php/apps/files/api/v2/synchronize",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
ResponseEntity<AssetManagerSynchronizeResponseDto> synchronize(
@RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader,
@RequestHeader("OCS-APIRequest") String ocsApiRequest,
@RequestBody SynchronizeFormData formData);
@RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader,
@RequestHeader("OCS-APIRequest") String ocsApiRequest,
@RequestBody SynchronizeFormData formData);

@GetMapping(
value = "/remote.php/dav/files/{uid}/{path}/{filename}",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
ResponseEntity<byte[]> downloadFile(@RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader,
@PathVariable("uid") String uid,
@PathVariable("path") String path,
@PathVariable("filename") String filename);

@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static class Publication {
private KeyStoreWithAlias keystore = new KeyStoreWithAlias();
private Boolean enabled;
private Boolean synchronizeEnabled;
private Boolean downloadEnabled;
private String downloadPath;
private String url;
private String amngrUid;
private String path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -92,6 +95,11 @@ public void publishGatewayData() {
byte[] signature = calculateSignature(zip);
uploadGatewayData(zip, signature);

if (Boolean.TRUE.equals(properties.getPublication().getDownloadEnabled())) {
downloadFile(properties.getPublication().getArchiveFilename());
downloadFile(properties.getPublication().getSignatureFilename());
}

log.info("Finished publishing of packed Gateway data");
}

Expand Down Expand Up @@ -277,10 +285,52 @@ private void uploadGatewayData(byte[] zip, byte[] signature) {
log.info("Upload and Synchronize successful");
}

private void downloadFile(String filename) {
log.info("Downloading uploaded DGCG Publication File: {}", filename);

ResponseEntity<byte[]> downloadResponse;
try {
downloadResponse = assetManagerClient.downloadFile(getAuthHeader(),
properties.getPublication().getAmngrUid(), properties.getPublication().getPath(), filename);

if (downloadResponse.getStatusCode().is2xxSuccessful()) {
log.info("Download of file {} was successful.", filename);
} else {
log.error("Failed to download file: {}", downloadResponse.getStatusCode());
}
} catch (FeignException.FeignServerException e) {
log.error("Failed to Download file: {}", e.status());
return;
}

File targetFile = Paths.get(properties.getPublication().getDownloadPath(), filename).toFile();

try {
Files.deleteIfExists(targetFile.toPath());
} catch (IOException e) {
log.error("Failed to delete existing file: {}, {}", targetFile.getAbsolutePath(), e.getMessage());
return;
}

if (downloadResponse.hasBody() && downloadResponse.getBody() != null) {
try (FileOutputStream fileOutputStream = new FileOutputStream(targetFile)) {
fileOutputStream.write(downloadResponse.getBody());
log.info("Saved file {} to {} ({} Bytes)",
filename, targetFile.getAbsolutePath(), downloadResponse.getBody().length);
} catch (IOException e) {
log.error("Failed to write downloaded file to disk: {}, {}",
targetFile.getAbsolutePath(), e.getMessage());
}
} else {
log.error("Download Response does not contain any body");
}

}

private String getAuthHeader() {
String header = "Basic ";
header += Base64.getEncoder().encodeToString((properties.getPublication().getUser() + ":"
+ properties.getPublication().getPassword()).getBytes(StandardCharsets.UTF_8));
+ properties.getPublication().getPassword()).getBytes(StandardCharsets.UTF_8));
return header;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dgc:
publication:
enbaled: false
synchronizeEnabled: false
downloadEnabled: false
keystore:
keyStorePath: /ec/prod/app/san/dgcg/dgc-publication.jks
keyStorePass: dgc-p4ssw0rd
Expand Down
Loading

0 comments on commit 4e0c283

Please sign in to comment.