Commit abb9f9e6 authored by Adrien's avatar Adrien

indentation

parent 1afddcad
......@@ -21,5 +21,5 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
class CodeSignApp
fun main(args: Array<String>) {
SpringApplication.run(CodeSignApp::class.java, *args)
SpringApplication.run(CodeSignApp::class.java, *args)
}
\ No newline at end of file
......@@ -18,134 +18,132 @@ import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.bonitasoft.exception.BuildDmgException
import org.bonitasoft.exception.SignException
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
import java.io.File
import java.io.FileInputStream
import java.nio.file.Files
import javax.servlet.http.HttpServletResponse
import java.io.FileOutputStream
import java.io.File
@RestController
class CodeSigningRestController {
val logger: Log = LogFactory.getLog(javaClass)
val macOs: String = "Mac OS X"
var windowsCodeSign = WindowsCodeSign()
var macCodeSign = MacCodeSign()
@PostMapping("/sign")
fun signProduct(@RequestParam("exeFile") file: MultipartFile,
response: HttpServletResponse): StreamingResponseBody {
if (file.isEmpty) {
logger.error("File '%s' is empty".format(file.originalFilename))
response.setStatus(400)
return StreamingResponseBody { outputStream ->
outputStream.write("File '%s' is empty".format(file.originalFilename).toByteArray())
outputStream.close()
}
}
try {
val exeCopy : File = Files.createTempFile(file.originalFilename,"").toFile()
logger.info("Copy of input file as $exeCopy....")
file.transferTo(exeCopy)
val fileSigned : File
try {
if (System.getProperty("os.name") == macOs) {
fileSigned = macCodeSign.signMacProduct(exeCopy)
} else {
fileSigned = windowsCodeSign.signWindowsProduct(exeCopy)
}
} catch (e: SignException) {
logger.error(e)
response.setStatus(500)
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured while signing file.".toByteArray())
}
}
response.setContentType("application/octet-stream")
response.setHeader("Content-Disposition", "attachment; filename='${fileSigned.name}'")
return StreamingResponseBody { outputStream ->
FileInputStream(fileSigned.canonicalFile).use { inputStream ->
inputStream.copyTo(outputStream)
outputStream.flush()
outputStream.close()
}
if (!fileSigned.delete()) {
logger.error("Failed to delete temp file $fileSigned")
}
}
} catch (e: Throwable) {
logger.error("An error occured", e)
}
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured server side. Check logs.".toByteArray())
}
}
@PostMapping( "/buildAndSignMacInstaller")
fun buildAndSignOsxInstaller(@RequestParam("exeFile") file: MultipartFile,
response: HttpServletResponse): StreamingResponseBody {
if (file.isEmpty) {
logger.error("File '%s' is empty".format(file.originalFilename))
response.setStatus(400)
return StreamingResponseBody { outputStream ->
outputStream.write("File '%s' is empty".format(file.originalFilename).toByteArray())
outputStream.close()
}
}
try {
val exeCopy: File = Files.createTempFile(file.originalFilename, "").toFile()
logger.info("Copy of input file as $exeCopy....")
file.transferTo(exeCopy)
try {
val fileSigned: File = macCodeSign.buildAndSignMacInstaller(exeCopy)
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename='${fileSigned.name}'");
return StreamingResponseBody { outputStream ->
FileInputStream(fileSigned).use { inputStream ->
inputStream.copyTo(outputStream)
outputStream.flush()
outputStream.close()
}
if (!fileSigned.delete()) {
logger.error("Failed to delete temp file $fileSigned")
}
}
} catch (e : SignException) {
logger.error(e)
response.setStatus(500);
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured while signing file.".toByteArray())
}
} catch (e : BuildDmgException) {
logger.error(e)
response.setStatus(500);
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured while building dmg.".toByteArray())
}
}
} catch (e: Throwable) {
logger.error("An error occured", e)
}
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured server side. Check logs.".toByteArray())
}
}
val logger: Log = LogFactory.getLog(javaClass)
val macOs: String = "Mac OS X"
var windowsCodeSign = WindowsCodeSign()
var macCodeSign = MacCodeSign()
@PostMapping("/sign")
fun signProduct(@RequestParam("exeFile") file: MultipartFile,
response: HttpServletResponse): StreamingResponseBody {
if (file.isEmpty) {
logger.error("File '%s' is empty".format(file.originalFilename))
response.setStatus(400)
return StreamingResponseBody { outputStream ->
outputStream.write("File '%s' is empty".format(file.originalFilename).toByteArray())
outputStream.close()
}
}
try {
val exeCopy: File = Files.createTempFile(file.originalFilename, "").toFile()
logger.info("Copy of input file as $exeCopy....")
file.transferTo(exeCopy)
val fileSigned: File
try {
if (System.getProperty("os.name") == macOs) {
fileSigned = macCodeSign.signMacProduct(exeCopy)
} else {
fileSigned = windowsCodeSign.signWindowsProduct(exeCopy)
}
} catch (e: SignException) {
logger.error(e)
response.setStatus(500)
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured while signing file.".toByteArray())
}
}
response.setContentType("application/octet-stream")
response.setHeader("Content-Disposition", "attachment; filename='${fileSigned.name}'")
return StreamingResponseBody { outputStream ->
FileInputStream(fileSigned.canonicalFile).use { inputStream ->
inputStream.copyTo(outputStream)
outputStream.flush()
outputStream.close()
}
if (!fileSigned.delete()) {
logger.error("Failed to delete temp file $fileSigned")
}
}
} catch (e: Throwable) {
logger.error("An error occured", e)
}
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured server side. Check logs.".toByteArray())
}
}
@PostMapping("/buildAndSignMacInstaller")
fun buildAndSignOsxInstaller(@RequestParam("exeFile") file: MultipartFile,
response: HttpServletResponse): StreamingResponseBody {
if (file.isEmpty) {
logger.error("File '%s' is empty".format(file.originalFilename))
response.setStatus(400)
return StreamingResponseBody { outputStream ->
outputStream.write("File '%s' is empty".format(file.originalFilename).toByteArray())
outputStream.close()
}
}
try {
val exeCopy: File = Files.createTempFile(file.originalFilename, "").toFile()
logger.info("Copy of input file as $exeCopy....")
file.transferTo(exeCopy)
try {
val fileSigned: File = macCodeSign.buildAndSignMacInstaller(exeCopy)
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename='${fileSigned.name}'");
return StreamingResponseBody { outputStream ->
FileInputStream(fileSigned).use { inputStream ->
inputStream.copyTo(outputStream)
outputStream.flush()
outputStream.close()
}
if (!fileSigned.delete()) {
logger.error("Failed to delete temp file $fileSigned")
}
}
} catch (e: SignException) {
logger.error(e)
response.setStatus(500);
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured while signing file.".toByteArray())
}
} catch (e: BuildDmgException) {
logger.error(e)
response.setStatus(500);
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured while building dmg.".toByteArray())
}
}
} catch (e: Throwable) {
logger.error("An error occured", e)
}
return StreamingResponseBody { outputStream ->
outputStream.write("An error occured server side. Check logs.".toByteArray())
}
}
}
\ No newline at end of file
......@@ -24,8 +24,8 @@ class MacCodeSign {
val logger: Log = LogFactory.getLog(javaClass)
val separator = System.getProperty("file.separator")
fun signMacProduct(zipFile: File) : File {
val file : File = unzip(zipFile);
fun signMacProduct(zipFile: File): File {
val file: File = unzip(zipFile);
if (!zipFile.delete()) {
logger.error("Failed to delete temp file $zipFile")
throw Throwable()
......@@ -34,7 +34,7 @@ class MacCodeSign {
logger.info("Signing osx application...")
val signResult = ProcessBuilder()
.inheritIO()
.command("codesign", "--deep", "-s", "Bonitasoft" , file.canonicalPath)
.command("codesign", "--deep", "-s", "Bonitasoft", file.canonicalPath)
.start()
.waitFor()
if (signResult != 0) {
......@@ -50,8 +50,8 @@ class MacCodeSign {
return newZipFile
}
fun buildAndSignMacInstaller(zipFile: File) : File {
val file : File = unzip(zipFile);
fun buildAndSignMacInstaller(zipFile: File): File {
val file: File = unzip(zipFile);
if (!zipFile.delete()) {
throw Throwable("Failed to delete temp file $zipFile")
}
......@@ -75,7 +75,7 @@ class MacCodeSign {
.start()
.waitFor()
var dmg = File(dmgPath);
if (buildDmgResult != 0 || ! dmg.exists()) {
if (buildDmgResult != 0 || !dmg.exists()) {
throw BuildDmgException("An error occured while building dmg")
}
......@@ -96,13 +96,13 @@ class MacCodeSign {
return dmg
}
fun unzip(zipFile: File) : File {
fun unzip(zipFile: File): File {
ProcessBuilder()
.inheritIO()
.command("unzip", zipFile.canonicalPath, "-d", zipFile.parentFile.canonicalPath)
.start()
.waitFor()
var file :File = File(zipFile.parentFile.canonicalPath + separator + zipFile.nameWithoutExtension + ".app")
var file: File = File(zipFile.parentFile.canonicalPath + separator + zipFile.nameWithoutExtension + ".app")
if (!file.exists()) {
logger.error("failed to unzip $zipFile")
throw Throwable()
......@@ -110,14 +110,14 @@ class MacCodeSign {
return file
}
fun zip(file: File) : File {
val zipPath : String = file.parentFile.canonicalPath + separator + file.nameWithoutExtension + ".zip"
fun zip(file: File): File {
val zipPath: String = file.parentFile.canonicalPath + separator + file.nameWithoutExtension + ".zip"
ProcessBuilder()
.inheritIO()
.command("zip", zipPath, "-r", file.canonicalPath)
.start()
.waitFor()
var zipFile = File(zipPath)
var zipFile = File(zipPath)
if (!zipFile.exists()) {
logger.error("failed to unzip $file")
throw Throwable()
......@@ -125,7 +125,7 @@ class MacCodeSign {
return zipFile
}
fun deleteApplication(application : File) {
fun deleteApplication(application: File) {
ProcessBuilder()
.inheritIO()
.command("rm", "-r", application.canonicalPath)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment