Skip to content

Commit

Permalink
feat: OpenAPI allow list
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Dec 4, 2024
1 parent 4f01bb3 commit 0092f02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
20 changes: 10 additions & 10 deletions data-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,50 @@ const parseConfig = (connector: any) => {

if (connector.type === "postgres") {
const postgresClient = new PostgresClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
maxResultLength: Number(config.maxResultLength),
...connector,
});
await postgresClient.initialize();
const service = postgresClient.createService(client);
services.push(service);
} else if (connector.type === "open-api") {
const openAPIClient = new OpenAPIClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
maxResultLength: Number(config.maxResultLength),
...connector,
});
await openAPIClient.initialize();
const service = openAPIClient.createService(client);
services.push(service);
} else if (connector.type === "graphql") {
const graphQLClient = new GraphQLClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
maxResultLength: Number(config.maxResultLength),
...connector,
});
await graphQLClient.initialize();
const service = graphQLClient.createService(client);
services.push(service);
} else if (connector.type === "mysql") {
const mysqlClient = new MySQLClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
maxResultLength: Number(config.maxResultLength),
...connector,
});
await mysqlClient.initialize();
const service = mysqlClient.createService(client);
services.push(service);
} else if (connector.type === "sqlite") {
const sqliteClient = new SQLiteClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
maxResultLength: Number(config.maxResultLength),
...connector,
});
await sqliteClient.initialize();
const service = sqliteClient.createService(client);
Expand Down
15 changes: 15 additions & 0 deletions data-connector/src/open-api/open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class OpenAPIClient implements DataConnector {
name?: string;
specUrl: string;
endpoint?: string;
allowedOperations?: string[];
maxResultLength: number;
defaultHeaders?: Record<string, string>;
privacyMode: boolean;
Expand All @@ -34,6 +35,15 @@ export class OpenAPIClient implements DataConnector {
`OpenAPI spec loaded successfully from ${this.params.specUrl}`,
);

if (this.params.allowedOperations) {
console.log(
"Filtering operations based on allowedOperations.",
{
allowedOpperations: this.params.allowedOperations,
},
)
}

// Convert paths and their operations into functions
for (const [path, pathItem] of Object.entries(this.spec.paths)) {
if (!pathItem) continue;
Expand All @@ -44,6 +54,11 @@ export class OpenAPIClient implements DataConnector {
const operation = pathItem[method];
if (!operation || !operation.operationId) continue;

if (this.params.allowedOperations && !this.params.allowedOperations.includes(operation.operationId)) {
continue;
}


const inferableFunction = this.openApiOperationToInferableFunction(
operation,
path,
Expand Down

0 comments on commit 0092f02

Please sign in to comment.