Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 19 additions & 1 deletion plugins/sftp/service/src/configuration/SFTPPluginConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { MageEventId } from '@ngageoint/mage.service/lib/entities/events/entities.events';
import { ArchiveFormat, CompletionAction, TriggerRule } from '../format/entities.format';

/**
* Determines how the events list is applied when filtering which events to sync.
* - All: Sync all active events
* - Include: Sync only events selected
* - Exclude: Sync all events except those selected
*/
export enum EventFilterMode {
All = 'all',
Include = 'include',
Exclude = 'exclude'
}

/**
* Contains various configuration values used by the plugin.
*/
Expand All @@ -22,7 +34,12 @@ export interface SFTPPluginConfig {
pageSize: number

/**
* Events in which to SFTP observations
* Determines how the event sync filters events
*/
eventFilterMode: EventFilterMode

/**
* Events to include or exclude based on eventFilterMode
*/
events: Array<MageEventId>

Expand Down Expand Up @@ -59,6 +76,7 @@ export const defaultSFTPPluginConfig = Object.freeze<SFTPPluginConfig>({
enabled: false,
interval: 60,
pageSize: 100,
eventFilterMode: EventFilterMode.All,
events: [],
archiveFormat: ArchiveFormat.GeoJSON,
completionAction: CompletionAction.None,
Expand Down
25 changes: 23 additions & 2 deletions plugins/sftp/service/src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UserRepository } from "@ngageoint/mage.service/lib/entities/users/entit
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api';
import SFTPClient from 'ssh2-sftp-client';
import { PassThrough } from 'stream';
import { SFTPPluginConfig, defaultSFTPPluginConfig } from '../configuration/SFTPPluginConfig';
import { SFTPPluginConfig, defaultSFTPPluginConfig, EventFilterMode } from '../configuration/SFTPPluginConfig';
import { ArchiveFormat, ArchiveStatus, ArchiverFactory, ArchiveResult, TriggerRule } from '../format/entities.format';
import fs from 'fs';
import { SftpObservationRepository, SftpStatus, MongooseSftpObservationRepository, SftpObservationModel } from '../adapters/adapters.sftp.mongoose';
Expand Down Expand Up @@ -232,6 +232,20 @@ export class SftpController {
return { ...this.status }
}

/**
* Gets all active events for display in the configuration UI.
* @returns Array of active events with id and name.
*/
public async getActiveEvents(): Promise<{ id: number; name: string }[]> {
try {
const events = await this.eventRepository.findActiveEvents()
return events.map(e => ({ id: e.id, name: e.name }))
} catch (e) {
this.console.error('Error fetching active events:', e)
return []
}
}

/**
* Tests the connection to an SFTP server with the given configuration
* @param config The SFTP client configuration to test
Expand Down Expand Up @@ -322,7 +336,14 @@ export class SftpController {
const configuration = await this.getConfiguration();
if (this.isRunning) {
try {
const events = await this.eventRepository.findActiveEvents();
let events = await this.eventRepository.findActiveEvents();

const filterMode = configuration.eventFilterMode || EventFilterMode.All
if (filterMode === EventFilterMode.Include && configuration.events.length > 0) {
events = events.filter(e => configuration.events.includes(e.id))
} else if (filterMode === EventFilterMode.Exclude && configuration.events.length > 0) {
events = events.filter(e => !configuration.events.includes(e.id))
}

for (const attrs of events) {
const event = new MageEvent(attrs)
Expand Down
11 changes: 11 additions & 0 deletions plugins/sftp/service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ const sftpPluginHooks: InitPluginHook<typeof InjectedServices> = {
}
})

routes.route('/events')
.get(async (_req, res, _next) => {
try {
const events = await controller.getActiveEvents()
res.json(events)
} catch (error) {
console.error('Error getting events:', error)
res.status(500).json([])
}
})

return routes
}
}
Expand Down
Loading