2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2020 Nokia. All rights reserved.
4 * ===============================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the
11 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12 * either express or implied. See the License for the specific language governing permissions
13 * and limitations under the License.
14 * ============LICENSE_END========================================================================
17 package org.oran.datafile.ftp;
21 import org.oran.datafile.configuration.SftpConfig;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class SftpClientSettings {
27 private static final Logger logger = LoggerFactory.getLogger(SftpClientSettings.class);
29 private final SftpConfig sftpConfig;
31 public SftpClientSettings(SftpConfig sftpConfig) {
32 this.sftpConfig = sftpConfig;
35 public boolean shouldUseStrictHostChecking() {
36 boolean strictHostKeyChecking = false;
37 if (this.sftpConfig.strictHostKeyChecking) {
38 File file = new File(getKnownHostsFilePath());
39 strictHostKeyChecking = file.isFile();
40 logUsageOfStrictHostCheckingFlag(strictHostKeyChecking, file.getAbsolutePath());
42 logger.info("StrictHostKeyChecking will be disabled.");
44 return strictHostKeyChecking;
47 public String getKnownHostsFilePath() {
48 return this.sftpConfig.knownHostsFilePath;
51 private void logUsageOfStrictHostCheckingFlag(boolean strictHostKeyChecking, String filePath) {
52 if (strictHostKeyChecking) {
53 logger.info("StrictHostKeyChecking will be enabled with KNOWN_HOSTS_FILE_PATH [{}].", filePath);
56 "StrictHostKeyChecking is enabled but environment variable KNOWN_HOSTS_FILE_PATH is not set or points to not existing file [{}] --> falling back to StrictHostKeyChecking='no'.",