generated from kestra-io/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tasks): introduce SMB protocol VFS (Samba for eg.)
closes #23
- Loading branch information
1 parent
2a19a93
commit 3f34eb1
Showing
30 changed files
with
1,078 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ out/ | |
.attach* | ||
src/test/resources/application-test.yml | ||
id_rsa* | ||
shares/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.runners.RunContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
|
||
import java.io.IOException; | ||
|
||
@SuperBuilder(toBuilder = true) | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Delete a file from a SMB (Samba for eg.) server." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
code = { | ||
"host: localhost", | ||
"port: 445", | ||
"username: foo", | ||
"password: pass", | ||
"uri: \"/my_share/dir1/file.txt\"", | ||
} | ||
) | ||
} | ||
) | ||
public class Delete extends io.kestra.plugin.fs.vfs.Delete implements SmbInterface { | ||
@Builder.Default | ||
protected String port = "445"; | ||
|
||
@Override | ||
protected FileSystemOptions fsOptions(RunContext runContext) throws IllegalVariableEvaluationException, IOException { | ||
return SmbService.fsOptions(runContext, this); | ||
} | ||
|
||
@Override | ||
protected String scheme() { | ||
return "smb"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.runners.RunContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
|
||
import java.io.IOException; | ||
|
||
@SuperBuilder(toBuilder = true) | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Download file from SMB (Samba for eg.) server" | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
code = { | ||
"host: localhost", | ||
"port: 445", | ||
"username: foo", | ||
"password: pass", | ||
"from: \"/my_share/file.txt\"", | ||
} | ||
) | ||
} | ||
) | ||
public class Download extends io.kestra.plugin.fs.vfs.Download implements SmbInterface { | ||
@Builder.Default | ||
protected String port = "445"; | ||
|
||
@Override | ||
protected FileSystemOptions fsOptions(RunContext runContext) throws IllegalVariableEvaluationException, IOException { | ||
return SmbService.fsOptions(runContext, this); | ||
} | ||
|
||
@Override | ||
protected String scheme() { | ||
return "smb"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.runners.RunContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
|
||
import java.io.IOException; | ||
|
||
@SuperBuilder(toBuilder = true) | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Download multiple files from a SMB (Samba for eg.) server" | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
title = "Download files from `my_share` and move them to an `archive_share`", | ||
code = { | ||
"host: localhost", | ||
"port: 445", | ||
"username: foo", | ||
"password: pass", | ||
"from: \"/my_share/\"", | ||
"interval: PT10S", | ||
"action: MOVE", | ||
"moveDirectory: \"/archive_share/\"", | ||
} | ||
) | ||
} | ||
) | ||
public class Downloads extends io.kestra.plugin.fs.vfs.Downloads implements SmbInterface { | ||
@Builder.Default | ||
protected String port = "445"; | ||
|
||
@Override | ||
protected FileSystemOptions fsOptions(RunContext runContext) throws IllegalVariableEvaluationException, IOException { | ||
return SmbService.fsOptions(runContext, this); | ||
} | ||
|
||
@Override | ||
protected String scheme() { | ||
return "smb"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.runners.RunContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
|
||
import java.io.IOException; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "List files from a SMB (Samba for eg.) server directory" | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
code = { | ||
"host: localhost", | ||
"port: 445", | ||
"username: foo", | ||
"password: pass", | ||
"from: \"/my_share/dir1/\"", | ||
"regExp: \".*\\/dir1\\/.*\\.(yaml|yml)\"", | ||
} | ||
) | ||
} | ||
) | ||
public class List extends io.kestra.plugin.fs.vfs.List implements SmbInterface { | ||
@Builder.Default | ||
protected String port = "445"; | ||
|
||
@Override | ||
protected FileSystemOptions fsOptions(RunContext runContext) throws IllegalVariableEvaluationException, IOException { | ||
return SmbService.fsOptions(runContext, this); | ||
} | ||
|
||
@Override | ||
protected String scheme() { | ||
return "smb"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.runners.RunContext; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
|
||
import java.io.IOException; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Move a file to a different share / folder on a SMB (Samba for eg.) server.", | ||
description = "If the destination directory doesn't exist, it will be created" | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
code = { | ||
"host: localhost", | ||
"port: 445", | ||
"username: foo", | ||
"password: pass", | ||
"from: \"/my_share/dir1/file.txt\"", | ||
"to: \"/my_share/dir2/file.txt\"", | ||
} | ||
) | ||
} | ||
) | ||
public class Move extends io.kestra.plugin.fs.vfs.Move implements SmbInterface { | ||
@Builder.Default | ||
protected String port = "445"; | ||
|
||
@Override | ||
protected FileSystemOptions fsOptions(RunContext runContext) throws IllegalVariableEvaluationException, IOException { | ||
return SmbService.fsOptions(runContext, this); | ||
} | ||
|
||
@Override | ||
protected String scheme() { | ||
return "smb"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.plugin.fs.vfs.AbstractVfsInterface; | ||
|
||
public interface SmbInterface extends AbstractVfsInterface { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.kestra.plugin.fs.smb; | ||
|
||
import io.kestra.core.exceptions.IllegalVariableEvaluationException; | ||
import io.kestra.core.runners.RunContext; | ||
import org.apache.commons.vfs2.FileSystemOptions; | ||
import org.apache.commons.vfs2.auth.StaticUserAuthenticator; | ||
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
public abstract class SmbService { | ||
public static FileSystemOptions fsOptions(RunContext runContext, SmbInterface smbInterface) throws IOException, IllegalVariableEvaluationException { | ||
FileSystemOptions opts = new FileSystemOptions(); | ||
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( | ||
opts, | ||
new StaticUserAuthenticator("", smbInterface.getUsername(), smbInterface.getPassword()) | ||
); | ||
|
||
return opts; | ||
} | ||
} |
Oops, something went wrong.