davsclaus opened a new pull request, #3339:
URL: https://github.com/apache/camel-kamelets/pull/3339

   Two new Kamelets for Windows and Samba file shares (SMB), on the Camel `smb` 
component, modelled on `sftp-source` and `sftp-sink`.
   
   ## smb-source
   
   Reads the files in a directory of a share, one message per file, and by 
default leaves them on the share.
   
   - Options: `connectionHost`, `connectionPort` (445), `shareName`, 
`directoryName`, `username`, `password`, `domain`, `recursive`, `idempotent` 
(true), `idempotentRepository`, `autoCreate`, `delete`, `move`, `moveFailed`, 
`preMove`, `include`, `exclude`, `antInclude`, `readLock` (`none`, `changed`, 
`rename`), `readLockMinAge`, `delay`, `maxMessagesPerPoll`, `sortBy`, 
`streamDownload`.
   - Output: the body is the file content as bytes (a stream with 
`streamDownload`), `Content-Type: application/octet-stream`. Headers: `file`, 
`ce-file`, `CamelFileName`, `CamelFileLength`, `CamelFileLastModified`, 
`CamelSmbUncPath` (such as `\\fileserver\exports\orders\orders.csv`).
   
   ## smb-sink
   
   Writes each message as a file to a directory of a share.
   
   - Options: `connectionHost`, `connectionPort` (445), `shareName`, 
`directoryName`, `username`, `password`, `domain`, `fileExist` (`Override`, 
`Append`, `Fail`, `Ignore`), `autoCreate`, `tempPrefix`, `doneFileName`.
   - Input: the body as text, bytes or a stream. The file name comes from 
`file`, then `ce-file`, with any directory dropped (`/` and `\`). Otherwise 
`CamelFileName` is used as it is, and without any of these headers a unique 
name is generated.
   - Output: the message is unchanged, plus `CamelFileNameProduced`.
   - Security: before writing, the sink removes 
`Camel(File|OverruleFile|Smb).*` except `CamelFileName`. `sftp-sink` only 
strips the first two. The `CamelSmb` part is needed because `SmbOperations` 
reads `CamelSmbFileExists` from the message and lets it override `fileExist`. A 
`CamelFileName` that points outside `directoryName`, such as `../x` or `..\x`, 
fails the message, because `jailStartingDirectory` is on by default.
   
   ## Design choices
   
   - `directoryName` is required, because an optional `{{?directoryName}}` in a 
path parameter breaks the endpoint URI (see the finding below). Use `/` for the 
top of the share. The source then gives names with a leading `/`.
   - `username` and `password` are required. Without a password the component 
throws an NPE.
   - `sortBy` is an enum of `file:name`, `file:modified` and `file:length`. 
`reverse:`, `ignoreCase:` and `;` groups fail on `smb` (see below).
   - The descriptions state the SMB-specific facts I checked: 
`readLock=changed` checks every 1 s and gives up after 10 s, not 5 s and 20 s 
as on FTP. With `move` and `delete` both set, the file is deleted and `move` is 
ignored, with no start error. A share that requires encryption refuses the 
connection.
   
   ## Tests
   
   `SmbIT` runs package `smb` against `dockurr/samba:4.23.10`, a maintained 
Docker Hub image. The `citrus` user's password contains `&` and `+`.
   
   - `smb-sink-route-test`: the file header `reports/day 1.csv` is written as 
`upload/day 1.csv` over an existing file, with the body as its content. 
`CamelSmbFileExists=Fail` and `CamelOverruleFileName=../overruled.csv` on the 
message are ignored. The message comes out unchanged with 
`CamelFileNameProduced`. A second message with `CamelFileName=../outside.csv` 
fails with "jailed to the starting directory", and no file is written outside 
`upload`.
   - `smb-source-route-test`: `orders/order 1.csv` arrives as bytes with 
`application/octet-stream`, `file`, `ce-file` and `CamelFileName` set to `order 
1.csv`, `CamelFileLength` 15 and the UNC path. It is then moved to 
`orders/.done`.
   
   Local results: `./mvnw -o clean install -DskipITs` passes. `SmbIT` passes (2 
tests) on 5 consecutive runs, in about 16 s. I also checked by hand with `camel 
run` against the container: the `delete`, `move` expression, `moveFailed`, 
`preMove`+`move`, `recursive`, `include`/`exclude`, `antInclude`, `readLock` 
(`changed`, `changed` with `readLockMinAge`, `rename`), 
`sortBy`+`maxMessagesPerPoll`, `streamDownload` and `idempotent=false` options 
of the source, and the `fileExist` modes, `tempPrefix` (also with `/` and with 
`Append`), `doneFileName`, `autoCreate=false`, `/` and nested directories, and 
wrong-password behaviour of the sink.
   
   Fixes #3332.
   
   ## Upgrade note
   
   ```
   * New Kamelets `smb-source` and `smb-sink` read and write files on Windows 
and Samba file shares (SMB).
   ```
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to