From acd42c63c6f2d592ad6ccefbc6a3699ba46471ce Mon Sep 17 00:00:00 2001 From: az Date: Wed, 31 Aug 2022 18:53:20 +0200 Subject: [PATCH] refactor checkLocalFile --- .../ubuntu/filesystem/base/Filesystem.kt | 13 ++++++++++ .../DefaultApplicationFileRepository.kt | 7 +++--- .../provs/server/infrastructure/localFiles.kt | 12 ---------- ° | 24 ------------------- 4 files changed, 16 insertions(+), 40 deletions(-) delete mode 100644 src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/localFiles.kt delete mode 100644 ° diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt index b1ac8b1..10a7101 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt @@ -6,6 +6,19 @@ import java.io.File import java.util.* +/** + * Returns true if the given file exists in the LOCAL file system. + */ +fun checkLocalFile(fileName: String): Boolean { + if (fileName.isEmpty()) { + return false + } else if ((!File(fileName).exists())) { + return false + } + return true +} + + /** * Returns true if the given file exists. */ diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt index 6efd0fc..806356d 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepository.kt @@ -1,15 +1,14 @@ package org.domaindrivenarchitecture.provs.server.infrastructure +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkLocalFile import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository class DefaultApplicationFileRepository : ApplicationFileRepository { override fun assertExists(applicationFileName: ApplicationFileName?) { - if (applicationFileName != null) { - if (!genericFileExistenceCheck(applicationFileName.fullqualified())) { - throw RuntimeException("Application file ${applicationFileName.fileName} not found. Please check if path is correct.") - } + if (applicationFileName != null && !checkLocalFile(applicationFileName.fullqualified())) { + throw RuntimeException("Application file ${applicationFileName.fileName} not found. Please check if path is correct.") } } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/localFiles.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/localFiles.kt deleted file mode 100644 index 35c37e4..0000000 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/localFiles.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.domaindrivenarchitecture.provs.server.infrastructure - -import java.io.File - -fun genericFileExistenceCheck(fileName: String): Boolean { - if (fileName.isEmpty()) { - return false - } else if ((!File(fileName).exists())) { - return false - } - return true -} diff --git a/° b/° deleted file mode 100644 index 162fca6..0000000 --- a/° +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -e -set -o noglob - -function usage() { - echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name} {domain_name}" -} - -function main() { - local cluster_name="${1}"; shift - local domain_name="${1:-meissa-gmbh.de}"; shift - - /usr/local/bin/k3s-create-context.sh ${cluster_name} - kubectl config use-context ${cluster_name} - ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 -} - -if [ $# -gt 0 ] -then - main $1 -else - usage - exit -1 -fi