In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after November 30, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

This Server has been upgraded to GitLab release 14.2.6

App.kt 2.01 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * sftp-reader
 * Copyright (C) 2020 Memoriav
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package org.memobase

import java.io.File
import kotlin.system.exitProcess
Jonas Waeber's avatar
Jonas Waeber committed
23
import org.apache.logging.log4j.LogManager
Jonas Waeber's avatar
Jonas Waeber committed
24
25
26
27
28
29
30
31
32

class App {
    companion object {
        private val log = LogManager.getLogger("SftpReader")
        @JvmStatic fun main(args: Array<String>) {
            try {
                val settings = SettingsLoader()
                val producer = Producer(settings.kafkaProducerProperties, settings.topic)
                val sftp = SftpClient(settings.sftpSettings)
Jonas Waeber's avatar
Jonas Waeber committed
33
                val validator = FileValidation(sftp)
Jonas Waeber's avatar
Jonas Waeber committed
34

Jonas Waeber's avatar
Jonas Waeber committed
35
                val files = sftp.listFiles(settings.appSettings["directory"].orEmpty()).map { File(it) }
Jonas Waeber's avatar
Jonas Waeber committed
36
37

                for (file in files) {
Jonas Waeber's avatar
Jonas Waeber committed
38
39
                    val report = validator.validate(file)
                    when (report.status) {
Jonas Waeber's avatar
Jonas Waeber committed
40
41
                        "valid" -> producer.sendMessage(file.name, file.path, report.format)
                        else -> producer.sendMessage(file.name, "ERROR", report.format)
Jonas Waeber's avatar
Jonas Waeber committed
42
                    }
Jonas Waeber's avatar
Jonas Waeber committed
43
                    producer.sendReport(report)
Jonas Waeber's avatar
Jonas Waeber committed
44
45
46
47
48
49
50
51
52
53
                }
                producer.close()
                sftp.close()
            } catch (ex: Exception) {
                ex.printStackTrace()
                log.error("Stopping application due to error: " + ex.message)
                exitProcess(1)
            }
        }
    }
Jonas Waeber's avatar
Jonas Waeber committed
54
}