Skip to content

Commit

Permalink
Merge branch 'main' into int-9820-gzip-request-payload
Browse files Browse the repository at this point in the history
  • Loading branch information
zemberdotnet authored Oct 16, 2023
2 parents 1a5f7e9 + 8444daf commit 0bf5dc6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to

- Gzip request payloads

- Allow loading modules by name (ex. @jupiterone/graph-rumble) in the
`generate-ingestion-sources-config` and `generate-integration-graph-schema`
commands

## 11.0.3

- Moved `vis` dependency to devDependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
StepMetadata,
} from '@jupiterone/integration-sdk-core';
import { createCommand } from 'commander';
import { loadConfigFromTarget } from '../config';
import { loadConfigFromModule, loadConfigFromTarget } from '../config';
import { promises as fs } from 'fs';
import * as log from '../log';

Expand All @@ -26,13 +26,22 @@ export function generateIngestionSourcesConfigCommand() {
'path to integration project directory',
process.cwd(),
)
.option(
'-m, --module-name <module>',
'name of modules to load (ex "@jupiterone/graph-rumble". Will load using require of package rather than filename)',
)
.action(async (options) => {
const { projectPath, outputFile } = options;
const { projectPath, outputFile, moduleName } = options;

log.info(
`Generating ingestion sources config (projectPath=${projectPath}, outputFile=${outputFile})`,
`Generating ingestion sources config (projectPath=${projectPath}, outputFile=${outputFile}, moduleName=${moduleName})`,
);
const config = await loadConfigFromTarget(projectPath);
let config;
if (moduleName) {
config = loadConfigFromModule(moduleName);
} else {
config = await loadConfigFromTarget(projectPath);
}
if (!config.ingestionConfig) {
log.info(
'Skipping the generation of ingestion sources config file as there is no ingestionConfig present.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
StepRelationshipMetadata,
} from '@jupiterone/integration-sdk-core';
import { createCommand } from 'commander';
import { loadConfigFromTarget } from '../config';
import { loadConfigFromModule, loadConfigFromTarget } from '../config';
import { promises as fs } from 'fs';
import * as log from '../log';

Expand All @@ -26,13 +26,22 @@ export function generateIntegrationGraphSchemaCommand() {
'path to integration project directory',
process.cwd(),
)
.option(
'-m, --module-name <module>',
'name of modules to load (ex "@jupiterone/graph-rumble". Will load using require of package rather than filename)',
)
.action(async (options) => {
const { projectPath, outputFile } = options;
const { projectPath, outputFile, moduleName } = options;

log.info(
`Generating integration graph schema (projectPath=${projectPath}, outputFile=${outputFile})`,
`Generating integration graph schema (projectPath=${projectPath}, outputFile=${outputFile}, moduleName=${moduleName})`,
);
const config = await loadConfigFromTarget(projectPath);
let config;
if (moduleName) {
config = loadConfigFromModule(moduleName);
} else {
config = await loadConfigFromTarget(projectPath);
}

const integrationGraphSchema = generateIntegrationGraphSchema(
config.integrationSteps,
Expand Down
15 changes: 15 additions & 0 deletions packages/integration-sdk-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ function loadConfigFromDist(projectPath: string) {
return loadConfig(path.join(projectPath, 'dist'));
}

export function loadConfigFromModule(mod: string) {
let integrationModule: any;

try {
integrationModule = require(mod);
} catch (err) {
throw new IntegrationInvocationConfigLoadError(
`Error loading integration invocation configuration. Ensure "invocationConfig" is exported from "${mod}". Additional details: ` +
err,
);
}

return integrationModule.invocationConfig as IntegrationInvocationConfig;
}

/**
* The way that integration npm packages are distributed has changed over time.
* This function handles different cases where the invocation config has
Expand Down

0 comments on commit 0bf5dc6

Please sign in to comment.