@@ -15,6 +15,7 @@ import readline from 'node:readline';
15
15
import { pipeline , Transform , Writable } from 'node:stream' ;
16
16
import { promisify } from 'node:util' ;
17
17
18
+ import { isNil , omitBy } from 'lodash' ;
18
19
import pino from 'pino' ;
19
20
import pretty from 'pino-pretty' ;
20
21
@@ -202,6 +203,46 @@ export function overrideCatalog(
202
203
return processedCatalog ;
203
204
}
204
205
206
+ /**
207
+ * Copy Faros API settings from destination config to source config.
208
+ * This is for users' convenience so that they don't have to provide the same settings
209
+ * in both source and destination configs.
210
+ */
211
+ export function updateSrcConfigWithFarosConfig ( airbyteConfig : { src : AirbyteConfig ; dst : AirbyteConfig } ) : void {
212
+ const srcDockerImage = airbyteConfig . src ?. image ;
213
+ const dstDockerImage = airbyteConfig . dst ?. image ;
214
+ const dstConfig = airbyteConfig . dst ?. config as any ;
215
+
216
+ if (
217
+ srcDockerImage ?. startsWith ( 'farosai/airbyte-faros-feeds-source' ) &&
218
+ dstDockerImage ?. startsWith ( 'farosai/airbyte-faros-destination' )
219
+ ) {
220
+ // take Faros API settings from destination config
221
+ const farosApiConfig : any = {
222
+ api_key : dstConfig ?. edition_configs ?. api_key ,
223
+ api_url : dstConfig ?. edition_configs ?. api_url ,
224
+ graph : dstConfig ?. edition_configs ?. graph ,
225
+ graph_api : dstConfig ?. edition_configs ?. graph_api ,
226
+ } ;
227
+ const compactFarosApiConfig = omitBy ( farosApiConfig , isNil ) ;
228
+ if ( Object . entries ( compactFarosApiConfig ) . length === 0 ) {
229
+ return ;
230
+ }
231
+
232
+ const debugLog = JSON . stringify ( { faros : compactFarosApiConfig } ) . replace (
233
+ compactFarosApiConfig ?. [ 'api_key' ] ,
234
+ 'REDACTED' ,
235
+ ) ;
236
+ logger . debug ( `Updating source config with Faros API settings from destination config: ${ debugLog } ` ) ;
237
+
238
+ // merge Faros API config into source config
239
+ airbyteConfig . src . config = {
240
+ ...airbyteConfig . src . config ,
241
+ faros : compactFarosApiConfig ,
242
+ } ;
243
+ }
244
+ }
245
+
205
246
/**
206
247
* Write Airbyte config to temporary dir and a json file
207
248
*/
@@ -227,12 +268,17 @@ export function writeConfig(tmpDir: string, config: FarosConfig): void {
227
268
} ;
228
269
}
229
270
271
+ // if not running source only, copy faros api settings from destination config to source config
272
+ if ( ! config . srcOutputFile ) {
273
+ updateSrcConfigWithFarosConfig ( airbyteConfig ) ;
274
+ }
275
+
230
276
// write config to temporary directory config files
231
277
logger . debug ( `Writing Airbyte config to files...` ) ;
232
278
const srcConfigFilePath = `${ tmpDir } ${ sep } ${ SRC_CONFIG_FILENAME } ` ;
233
279
const dstConfigFilePath = `${ tmpDir } ${ sep } ${ FILENAME_PREFIX } _dst_config.json` ;
234
- writeFileSync ( srcConfigFilePath , JSON . stringify ( airbyteConfig . src . config ?? { } , null , 2 ) ) ;
235
- writeFileSync ( dstConfigFilePath , JSON . stringify ( airbyteConfig . dst . config ?? { } , null , 2 ) ) ;
280
+ writeFileSync ( srcConfigFilePath , JSON . stringify ( airbyteConfig . src . config ?? { } ) ) ;
281
+ writeFileSync ( dstConfigFilePath , JSON . stringify ( airbyteConfig . dst . config ?? { } ) ) ;
236
282
logger . debug ( `Airbyte config files written to: ${ srcConfigFilePath } , ${ dstConfigFilePath } ` ) ;
237
283
logger . debug ( airbyteConfig . src . config ?? { } , `Source config: ` ) ;
238
284
logger . debug ( airbyteConfig . dst . config ?? { } , `Destination config: ` ) ;
@@ -265,8 +311,8 @@ export async function writeCatalog(tmpDir: string, config: FarosConfig): Promise
265
311
} ) ;
266
312
267
313
logger . debug ( `Writing Airbyte catalog to files...` ) ;
268
- writeFileSync ( srcCatalogFilePath , JSON . stringify ( srcCatalog , null , 2 ) ) ;
269
- writeFileSync ( dstCatalogFilePath , JSON . stringify ( dstCatalog , null , 2 ) ) ;
314
+ writeFileSync ( srcCatalogFilePath , JSON . stringify ( srcCatalog ) ) ;
315
+ writeFileSync ( dstCatalogFilePath , JSON . stringify ( dstCatalog ) ) ;
270
316
logger . debug ( `Airbyte catalog files written to: ${ srcCatalogFilePath } , ${ dstCatalogFilePath } ` ) ;
271
317
logger . debug ( srcCatalog , `Source catalog: ` ) ;
272
318
logger . debug ( dstCatalog , `Destination catalog: ` ) ;
0 commit comments