Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTP / SCP connectors missing authentication options to use a private key #1170

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions it-tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ tests:
./timer-aws-sns-it-test.sh $(camel-version)
cd aws/aws-kinesis-firehose/sink/ && \
./timer-aws-kinesis-firehose-it-test.sh $(camel-version)
cd misc/sftp/source/ && \
./sftp-log-it-test.sh $(camel-version)
./scripts/results.sh
rm -rf tests

Expand Down
45 changes: 45 additions & 0 deletions it-tests/misc/sftp/source/sftp-log-it-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo $0: usage: sftp-log-it-test.sh camel-version
exit 1
fi

camel_version=$1

docker pull emberstack/sftp
docker run -p 24:22 --name sftp -d emberstack/sftp
sftpid=`docker ps -aqf "name=sftp"`

echo $sftpid

jbang run -Dcamel.jbang.version=$camel_version camel@apache/camel run --local-kamelet-dir=../../../../kamelets/ sftp-log.yaml &

sleep 10

docker exec -it $sftpid bash -c "echo 'Ciao' >> /home/demo/sftp/demos/file1.txt"
docker exec -it $sftpid bash -c "echo 'Ciao' >> /home/demo/sftp/demos/file2.txt"
docker exec -it $sftpid bash -c "echo 'Ciao' >> /home/demo/sftp/demos/file3.txt"
docker exec -it $sftpid bash -c "echo 'Ciao' >> /home/demo/sftp/demos/file4.txt"
docker exec -it $sftpid bash -c "echo 'Ciao' >> /home/demo/sftp/demos/file5.txt"

sleep 10

variable=`jbang run -Dcamel.jbang.version=$camel_version camel@apache/camel get | tail -n +2`
success=`echo $variable | cut -d' ' -f11`
fail=`echo $variable | cut -d' ' -f12`
if [[ $success == 5 && $fail == 0 ]]
then
mkdir -p ../../../tests/
echo "Test Successful" > ../../../tests/sftp-log-it-test.result;
else
mkdir -p ../../../tests/
echo "Test failed" > ../../../tests/sftp-log-it-test.result;
fi

jbang run -Dcamel.jbang.version=$camel_version camel@apache/camel stop sftp-log

docker stop sftp
docker rm sftp

cat ../../../tests/sftp-log-it-test.result
32 changes: 32 additions & 0 deletions it-tests/misc/sftp/source/sftp-log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------

- route:
from:
uri: "kamelet:sftp-source"
parameters:
username: demo
password: demo
connectionHost: localhost
connectionPort: 24
directoryName: demos/
recursive: true
steps:
- to:
uri: "kamelet:log-sink"
parameters:
showStreams: false
37 changes: 33 additions & 4 deletions kamelets/sftp-sink.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ spec:
required:
- connectionHost
- connectionPort
- username
- password
- directoryName
type: object
properties:
Expand Down Expand Up @@ -89,6 +87,31 @@ spec:
default: false
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
privateKeyFile:
title: Private Key File
description: Set the private key file so that the SFTP endpoint can do private key verification.
type: string
privateKeyPassphrase:
title: Private Key Passphrase
description: Set the private key file passphrase so that the SFTP endpoint can do private key verification.
type: string
privateKeyUri:
title: Private Key URI
description: Set the private key file (loaded from classpath by default) so that the SFTP endpoint can do private key verification.
type: string
pattern: "^(http|https|file|classpath)://.*"
strictHostKeyChecking:
title: Strict Host Checking
description: Sets whether to use strict host key checking.
type: string
default: no
useUserKnownHostsFile:
title: Use User Known Hosts File
description: If knownHostFile has not been explicit configured then use the host file from System.getProperty(user.home)/.ssh/known_hosts.
type: boolean
default: true
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
dependencies:
- "camel:ftp"
- "camel:core"
Expand All @@ -110,9 +133,15 @@ spec:
name: CamelFileName
simple: "${header[ce-file]}"
- to:
uri: "sftp:{{username}}@{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
uri: "sftp:{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
parameters:
password: "{{password}}"
username: "{{?username}}"
password: "{{?password}}"
privateKeyFile: "{{?privateKeyFile}}"
privateKeyPassphrase: "{{?privateKeyPassphrase}}"
privateKeyUri: "{{?privateKeyUri}}"
strictHostKeyChecking: "{{?strictHostKeyChecking}}"
useUserKnownHostsFile: "{{?useUserKnownHostsFile}}"
passiveMode: "{{passiveMode}}"
fileExist: "{{fileExist}}"
binary: "{{binary}}"
41 changes: 35 additions & 6 deletions kamelets/sftp-source.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ spec:
required:
- connectionHost
- connectionPort
- username
- password
- directoryName
type: object
properties:
Expand Down Expand Up @@ -101,27 +99,58 @@ spec:
default: false
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
privateKeyFile:
title: Private Key File
description: Set the private key file so that the SFTP endpoint can do private key verification.
type: string
privateKeyPassphrase:
title: Private Key Passphrase
description: Set the private key file passphrase so that the SFTP endpoint can do private key verification.
type: string
privateKeyUri:
title: Private Key URI
description: Set the private key file (loaded from classpath by default) so that the SFTP endpoint can do private key verification.
type: string
pattern: "^(http|https|file|classpath)://.*"
strictHostKeyChecking:
title: Strict Host Checking
description: Sets whether to use strict host key checking.
type: string
default: no
useUserKnownHostsFile:
title: Use User Known Hosts File
description: If knownHostFile has not been explicit configured then use the host file from System.getProperty(user.home)/.ssh/known_hosts.
type: boolean
default: true
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
dependencies:
- "camel:ftp"
- "camel:core"
- "camel:kamelet"
template:
from:
uri: "sftp:{{username}}@{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
uri: "sftp:{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
parameters:
password: "{{password}}"
username: "{{?username}}"
password: "{{?password}}"
privateKeyFile: "{{?privateKeyFile}}"
privateKeyPassphrase: "{{?privateKeyPassphrase}}"
privateKeyUri: "{{?privateKeyUri}}"
strictHostKeyChecking: "{{?strictHostKeyChecking}}"
useUserKnownHostsFile: "{{?useUserKnownHostsFile}}"
passiveMode: "{{passiveMode}}"
recursive: "{{recursive}}"
idempotent: "{{idempotent}}"
ignoreFileNotFoundOrPermissionError: "{{ignoreFileNotFoundOrPermissionError}}"
binary: "{{binary}}"
steps:
- set-body:
simple: "${body.getBody()}"
- set-header:
name: file
simple: "${header[CamelFileName]}"
- set-header:
name: ce-file
simple: "${header[CamelFileName]}"
- convert-body-to:
type: "java.io.InputStream"
- to: "kamelet:sink"
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ spec:
required:
- connectionHost
- connectionPort
- username
- password
- directoryName
type: object
properties:
Expand Down Expand Up @@ -89,6 +87,31 @@ spec:
default: false
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
privateKeyFile:
title: Private Key File
description: Set the private key file so that the SFTP endpoint can do private key verification.
type: string
privateKeyPassphrase:
title: Private Key Passphrase
description: Set the private key file passphrase so that the SFTP endpoint can do private key verification.
type: string
privateKeyUri:
title: Private Key URI
description: Set the private key file (loaded from classpath by default) so that the SFTP endpoint can do private key verification.
type: string
pattern: "^(http|https|file|classpath)://.*"
strictHostKeyChecking:
title: Strict Host Checking
description: Sets whether to use strict host key checking.
type: string
default: no
useUserKnownHostsFile:
title: Use User Known Hosts File
description: If knownHostFile has not been explicit configured then use the host file from System.getProperty(user.home)/.ssh/known_hosts.
type: boolean
default: true
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
dependencies:
- "camel:ftp"
- "camel:core"
Expand All @@ -110,9 +133,15 @@ spec:
name: CamelFileName
simple: "${header[ce-file]}"
- to:
uri: "sftp:{{username}}@{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
uri: "sftp:{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
parameters:
password: "{{password}}"
username: "{{?username}}"
password: "{{?password}}"
privateKeyFile: "{{?privateKeyFile}}"
privateKeyPassphrase: "{{?privateKeyPassphrase}}"
privateKeyUri: "{{?privateKeyUri}}"
strictHostKeyChecking: "{{?strictHostKeyChecking}}"
useUserKnownHostsFile: "{{?useUserKnownHostsFile}}"
passiveMode: "{{passiveMode}}"
fileExist: "{{fileExist}}"
binary: "{{binary}}"
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ spec:
required:
- connectionHost
- connectionPort
- username
- password
- directoryName
type: object
properties:
Expand Down Expand Up @@ -101,27 +99,58 @@ spec:
default: false
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
privateKeyFile:
title: Private Key File
description: Set the private key file so that the SFTP endpoint can do private key verification.
type: string
privateKeyPassphrase:
title: Private Key Passphrase
description: Set the private key file passphrase so that the SFTP endpoint can do private key verification.
type: string
privateKeyUri:
title: Private Key URI
description: Set the private key file (loaded from classpath by default) so that the SFTP endpoint can do private key verification.
type: string
pattern: "^(http|https|file|classpath)://.*"
strictHostKeyChecking:
title: Strict Host Checking
description: Sets whether to use strict host key checking.
type: string
default: no
useUserKnownHostsFile:
title: Use User Known Hosts File
description: If knownHostFile has not been explicit configured then use the host file from System.getProperty(user.home)/.ssh/known_hosts.
type: boolean
default: true
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:checkbox'
dependencies:
- "camel:ftp"
- "camel:core"
- "camel:kamelet"
template:
from:
uri: "sftp:{{username}}@{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
uri: "sftp:{{connectionHost}}:{{connectionPort}}/{{directoryName}}"
parameters:
password: "{{password}}"
username: "{{?username}}"
password: "{{?password}}"
privateKeyFile: "{{?privateKeyFile}}"
privateKeyPassphrase: "{{?privateKeyPassphrase}}"
privateKeyUri: "{{?privateKeyUri}}"
strictHostKeyChecking: "{{?strictHostKeyChecking}}"
useUserKnownHostsFile: "{{?useUserKnownHostsFile}}"
passiveMode: "{{passiveMode}}"
recursive: "{{recursive}}"
idempotent: "{{idempotent}}"
ignoreFileNotFoundOrPermissionError: "{{ignoreFileNotFoundOrPermissionError}}"
binary: "{{binary}}"
steps:
- set-body:
simple: "${body.getBody()}"
- set-header:
name: file
simple: "${header[CamelFileName]}"
- set-header:
name: ce-file
simple: "${header[CamelFileName]}"
- convert-body-to:
type: "java.io.InputStream"
- to: "kamelet:sink"
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.map(ComponentModel.EndpointOptionModel::getName)
.collect(Collectors.toList());
for (Map.Entry<String, Object> entry : p.entrySet()) {
if (!entry.getKey().equals("period") && (!name.equals("kafka-ssl-source") && !name.equals("timer-source") && !name.equals("cron-source") && !name.equals("fhir-source") && !name.equals("beer-source"))) {
if (!entry.getKey().equals("period") && (!name.equals("sftp-source") && !name.equals("kafka-ssl-source") && !name.equals("timer-source") && !name.equals("cron-source") && !name.equals("fhir-source") && !name.equals("beer-source"))) {
if (!ceInternal.contains(entry.getKey())) {
getLog().error("Kamelet Name: " + name);
getLog().error("Scheme Name: " + cleanName);
Expand Down