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

Remove ftp functionality #2064

Merged
merged 20 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
385 changes: 8 additions & 377 deletions packages/fulfilment-job/package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/fulfilment-job/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"merge2": "^1.4.1",
"moment": "^2.29.1",
"openpgp": "^5.0.0-1",
"pluralize": "^8.0.0",
"ssh2-sftp-client": "^6.0.1"
"pluralize": "^8.0.0"
}
}
9 changes: 0 additions & 9 deletions packages/fulfilment-job/src/__mocks__/ssh2-sftp-client.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Readable, PassThrough, Writable } from 'stream'
import { deliverFulfilmentFiles } from '../deliver-fulfilment-files.js'
import { createS3WriteStream, readS3PartFiles } from '../../transport/s3.js'
import { createFtpWriteStream } from '../../transport/ftp.js'
import { FULFILMENT_FILE_STATUS_OPTIONSET, getOptionSetEntry } from '../staging-common.js'
import { FulfilmentRequestFile, executeQuery, persist } from '@defra-fish/dynamics-lib'
import openpgp from 'openpgp'
Expand All @@ -10,7 +9,6 @@ import streamHelper from '../streamHelper.js'
import merge2 from 'merge2'

jest.mock('../../transport/s3.js')
jest.mock('../../transport/ftp.js')
jest.mock('openpgp', () => ({
readKey: jest.fn(() => ({})),
encrypt: jest.fn(({ message: readableStream }) => readableStream),
Expand Down Expand Up @@ -46,20 +44,10 @@ describe('deliverFulfilmentFiles', () => {
executeQuery.mockResolvedValue([{ entity: mockFulfilmentRequestFile2 }, { entity: mockFulfilmentRequestFile1 }])

// Streams for file1
const {
s3DataStreamFile: s3DataStreamFile1,
ftpDataStreamFile: ftpDataStreamFile1,
s3HashStreamFile: s3HashStreamFile1,
ftpHashStreamFile: ftpHashStreamFile1
} = createMockFileStreams()
const { s3DataStreamFile: s3DataStreamFile1, s3HashStreamFile: s3HashStreamFile1 } = createMockFileStreams()

// Streams for file2
const {
s3DataStreamFile: s3DataStreamFile2,
ftpDataStreamFile: ftpDataStreamFile2,
s3HashStreamFile: s3HashStreamFile2,
ftpHashStreamFile: ftpHashStreamFile2
} = createMockFileStreams()
const { s3DataStreamFile: s3DataStreamFile2, s3HashStreamFile: s3HashStreamFile2 } = createMockFileStreams()

// Run the delivery
await expect(deliverFulfilmentFiles()).resolves.toBeUndefined()
Expand All @@ -69,22 +57,14 @@ describe('deliverFulfilmentFiles', () => {
// File 1 expectations
expect(createS3WriteStream).toHaveBeenNthCalledWith(1, 'EAFF202006180001.json')
expect(createS3WriteStream).toHaveBeenNthCalledWith(3, 'EAFF202006180001.json.sha256')
expect(createFtpWriteStream).toHaveBeenNthCalledWith(1, 'EAFF202006180001.json')
expect(createFtpWriteStream).toHaveBeenNthCalledWith(3, 'EAFF202006180001.json.sha256')
expect(JSON.parse(s3DataStreamFile1.dataProcessed)).toEqual({ licences: [{ part: 0 }, { part: 1 }] })
expect(JSON.parse(ftpDataStreamFile1.dataProcessed)).toEqual({ licences: [{ part: 0 }, { part: 1 }] })
expect(s3HashStreamFile1.dataProcessed).toEqual(fileShaHash) // validated
expect(ftpHashStreamFile1.dataProcessed).toEqual(fileShaHash) // validated

// File 2 expectations
expect(createS3WriteStream).toHaveBeenNthCalledWith(4, 'EAFF202006180002.json')
expect(createS3WriteStream).toHaveBeenNthCalledWith(6, 'EAFF202006180002.json.sha256')
expect(createFtpWriteStream).toHaveBeenNthCalledWith(4, 'EAFF202006180002.json')
expect(createFtpWriteStream).toHaveBeenNthCalledWith(6, 'EAFF202006180002.json.sha256')
expect(JSON.parse(s3DataStreamFile2.dataProcessed)).toEqual({ licences: [{ part: 0 }, { part: 1 }] })
expect(JSON.parse(ftpDataStreamFile2.dataProcessed)).toEqual({ licences: [{ part: 0 }, { part: 1 }] })
expect(s3HashStreamFile2.dataProcessed).toEqual(fileShaHash) // validated
expect(ftpHashStreamFile2.dataProcessed).toEqual(fileShaHash) // validated

// Persist to dynamics for file 1
expect(persist).toHaveBeenNthCalledWith(1, [
Expand Down Expand Up @@ -197,10 +177,7 @@ describe('deliverFulfilmentFiles', () => {
const s3 = createTestableStream()
streamHelper.pipelinePromise.mockResolvedValue()
openpgp.encrypt.mockResolvedValue(s2)
merge2
.mockReturnValueOnce(s1)
.mockReturnValueOnce(s2)
.mockReturnValueOnce(s3)
merge2.mockReturnValueOnce(s1).mockReturnValueOnce(s2).mockReturnValueOnce(s3)
await mockExecuteQuery()
createMockFileStreams()

Expand All @@ -227,27 +204,18 @@ const createMockFulfilmentRequestFile = async (fileName, date) =>

const createMockFileStreams = () => {
const s3DataStreamFile = createTestableStream()
const ftpDataStreamFile = createTestableStream()
createS3WriteStream.mockReturnValueOnce({ s3WriteStream: s3DataStreamFile, managedUpload: Promise.resolve() })
createFtpWriteStream.mockReturnValueOnce({ ftpWriteStream: ftpDataStreamFile, managedUpload: Promise.resolve() })

const s3EncryptedDataStreamFile = createTestableStream()
const ftpEncryptedDataStreamFile = createTestableStream()
createS3WriteStream.mockReturnValueOnce({ s3WriteStream: s3EncryptedDataStreamFile, managedUpload: Promise.resolve() })
createFtpWriteStream.mockReturnValueOnce({ ftpWriteStream: ftpEncryptedDataStreamFile, managedUpload: Promise.resolve() })

const s3HashStreamFile = createTestableStream()
const ftpHashStreamFile = createTestableStream()
createS3WriteStream.mockReturnValueOnce({ s3WriteStream: s3HashStreamFile, managedUpload: Promise.resolve() })
createFtpWriteStream.mockReturnValueOnce({ ftpWriteStream: ftpHashStreamFile, managedUpload: Promise.resolve() })

return {
s3DataStreamFile,
ftpDataStreamFile,
s3EncryptedDataStreamFile,
ftpEncryptedDataStreamFile,
s3HashStreamFile,
ftpHashStreamFile
s3HashStreamFile
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import merge2 from 'merge2'
import moment from 'moment'
import { executeQuery, persist, findFulfilmentFiles } from '@defra-fish/dynamics-lib'
import { createS3WriteStream, readS3PartFiles } from '../transport/s3.js'
import { createFtpWriteStream } from '../transport/ftp.js'
import { FULFILMENT_FILE_STATUS_OPTIONSET, getOptionSetEntry } from './staging-common.js'
import db from 'debug'
import openpgp from 'openpgp'
Expand Down Expand Up @@ -69,11 +68,6 @@ const createEncryptedDataReadStream = async file => {
*/
const deliver = async (targetFileName, readableStream, ...transforms) => {
const { s3WriteStream: s3DataStream, managedUpload: s3DataManagedUpload } = createS3WriteStream(targetFileName)
const { ftpWriteStream: ftpDataStream, managedUpload: ftpDataManagedUpload } = createFtpWriteStream(targetFileName)

await Promise.all([
streamHelper.pipelinePromise([readableStream, ...transforms, s3DataStream, ftpDataStream]),
s3DataManagedUpload,
ftpDataManagedUpload
])
await Promise.all([streamHelper.pipelinePromise([readableStream, ...transforms, s3DataStream]), s3DataManagedUpload])
}
63 changes: 0 additions & 63 deletions packages/fulfilment-job/src/transport/__tests__/ftp.spec.js

This file was deleted.

28 changes: 0 additions & 28 deletions packages/fulfilment-job/src/transport/ftp.js

This file was deleted.

Loading
Loading