forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STRATCONN 2557 - LiveRamp SFTP (segmentio#1265)
* Initial scaffolding for LiveRamp * temporarily remove warnings from scaffold * STRATCONN-2553 Add mapping and destination settings for LiveRamp * STRATCONN-2556 Add support for an S3 upload module * improve formatting * add testcases * fix documentation * last fixes * refactor S3 into its own action * add support for SFTP * Fix merge * fix outdated references * restore snapshots * last bug fixes * generate types * add testAuthentication for SFTP * resolve dependencies * update snapshots * add package to the correct location * move types to inner package * DRY SFTP code * remove awaits
- Loading branch information
1 parent
e070029
commit 687a561
Showing
11 changed files
with
191 additions
and
56 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
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
4 changes: 2 additions & 2 deletions
4
...udienceEntered/__tests__/snapshot.test.ts → ...ramp-audiences/__tests__/snapshot.test.ts
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
8 changes: 2 additions & 6 deletions
8
...estination-actions/src/destinations/liveramp-audiences/audienceEntered/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
48 changes: 48 additions & 0 deletions
48
packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/sftp.ts
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 @@ | ||
import { InvalidAuthenticationError } from '@segment/actions-core' | ||
import Client from 'ssh2-sftp-client' | ||
import path from 'path' | ||
import { Settings } from '../generated-types' | ||
|
||
const LIVERAMP_SFTP_SERVER = 'files.liveramp.com' | ||
const LIVERAMP_SFTP_PORT = 22 | ||
|
||
function validateSFTP(settings: Settings) { | ||
if (!settings.sftp_username) { | ||
throw new InvalidAuthenticationError('Selected SFTP upload mode, but missing credentials (Username)') | ||
} | ||
|
||
if (!settings.sftp_password) { | ||
throw new InvalidAuthenticationError('Selected SFTP upload mode, but missing credentials (Password)') | ||
} | ||
|
||
if (!settings.sftp_folder_path) { | ||
throw new InvalidAuthenticationError('Selected SFTP upload mode, but missing SFTP folder path.') | ||
} | ||
} | ||
|
||
async function uploadSFTP(sftp: Client, settings: Settings, filename: string, fileContent: Buffer) { | ||
return doSFTP(sftp, settings, async (sftp) => { | ||
const targetPath = path.join(settings.sftp_folder_path as string, filename) | ||
return sftp.put(fileContent, targetPath) | ||
}) | ||
} | ||
|
||
async function doSFTP(sftp: Client, settings: Settings, action: { (sftp: Client): Promise<unknown> }) { | ||
await sftp.connect({ | ||
host: LIVERAMP_SFTP_SERVER, | ||
port: LIVERAMP_SFTP_PORT, | ||
username: settings.sftp_username, | ||
password: settings.sftp_password | ||
}) | ||
|
||
await action(sftp) | ||
await sftp.end() | ||
} | ||
|
||
async function testAuthenticationSFTP(sftp: Client, settings: Settings) { | ||
return doSFTP(sftp, settings, async (sftp) => { | ||
return sftp.list(settings.sftp_folder_path as string) | ||
}) | ||
} | ||
|
||
export { validateSFTP, uploadSFTP, testAuthenticationSFTP, Client } |
2 changes: 1 addition & 1 deletion
2
packages/destination-actions/src/destinations/liveramp-audiences/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.