Skip to content

Commit

Permalink
Add an option to process a file while it's streamed (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColman authored Oct 29, 2020
1 parent 7fc98ab commit 53fc010
Show file tree
Hide file tree
Showing 20 changed files with 494 additions and 273 deletions.
30 changes: 30 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes
$CHANGES
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build

on:
pull_request:
paths-ignore:
- '*.md'
push:

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: check
run: ./gradlew check
14 changes: 14 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Drafter

on:
push:
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: "Release Version"
required: true

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Publish to Maven Central
run: ./gradlew clean build bintrayUpload -PbintrayUser=${BINTRAY_USER} -PbintrayKey=${BINTRAY_KEY} -PdryRun=false
env:
RELEASE_VERSION: ${{ github.event.inputs.version }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ connector.transfer(sftpFilePath = "sftp/file/path", s3File = "foo/MyFile.txt")

You can optionally pass a KMS Key ID to request a server-side encryption with it
```kotlin
connector.transfer("sft/file/path", "foo/MyFile.txt", kmsKeyId = "aws:kms:mykeyid")
connector.transfer("sftp/file/path", "foo/MyFile.txt", kmsKeyId = "aws:kms:mykeyid")
```

You can optionally pass a Stream Transformer to process the file while it's being streamed. This can be useful for filters or event notifications of some sort.
```kotlin
connector.transfer("sftp/file/path", "foo/MyFile.txt", transformer = { inputStream, outputStream -> inputStream.copyTo(outputStream) })
```

## Features

- The file will be streamed from one point to the other, therefore there won't be any problems regarding file size in-memory. Although unmeasured, the memory footprint of this library should be small
- As per S3 specification, if there is any errors (such as an interrupted connection) during the transfer, no file chunks will be persisted
- The files can be encrypted if provided with a KMS key ID
- It's possible to process the file (as an InputStream) while it's being streamed to S3

## Limitations
- Currently this library doesn't have a way to select which files you want transferred other than by specific path and name.
Expand Down
25 changes: 10 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.novoda.gradle.release.PublishExtension
import io.gitlab.arturbosch.detekt.detekt
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand All @@ -16,44 +15,45 @@ buildscript {


plugins {
kotlin("jvm") version "1.3.50"
kotlin("jvm") version "1.4.10"
`maven-publish`
id("org.jetbrains.dokka") version "0.9.17"
id("io.gitlab.arturbosch.detekt").version("1.1.1")
id("io.gitlab.arturbosch.detekt").version("1.14.2")
}

apply(plugin = "com.novoda.bintray-release")

group = "br.com.guiabolso"
version = "0.1.2"

repositories {
mavenCentral()
jcenter()
}

dependencies {
// Kotlin
implementation(kotlin("stdlib-jdk8"))

// SFTP
implementation("com.jcraft:jsch:0.1.55")
implementation("org.apache.commons:commons-vfs2:2.4.1")

testImplementation("com.github.stefanbirkner:fake-sftp-server-lambda:1.0.0")
testImplementation("org.apache.sshd:sshd-sftp:2.4.0")

// S3
api("com.amazonaws:aws-java-sdk-s3:1.11.488")
testImplementation("com.adobe.testing:s3mock-junit5:2.1.16")

// KotlinTest
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.4.2")
// Kotest
testImplementation("io.kotest:kotest-runner-junit5:4.3.0")
}

tasks.withType<Test> {
useJUnitPlatform()
}

kotlin {
explicitApi()
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Expand All @@ -72,11 +72,6 @@ val javadocJar by tasks.registering(Jar::class) {
from(javadoc.outputDirectory)
}

detekt {
toolVersion = "1.1.1"
input = files("src/main/kotlin", "src/test/kotlin")
}

publishing {
publications {

Expand Down Expand Up @@ -115,7 +110,7 @@ configure<PublishExtension> {
groupId = "br.com.guiabolso"
userOrg = "gb-opensource"
setLicences("APACHE-2.0")
publishVersion = version.toString()
publishVersion = System.getenv("RELEASE_VERSION") ?: "local"
uploadName = "SFTP-to-S3-Connector"
website = "https://github.com/GuiaBolso/sftp-to-s3-connector"
setPublications("maven")
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
53 changes: 33 additions & 20 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed 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
#
# https://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.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -66,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 53fc010

Please sign in to comment.