-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f69262d
commit 0a1e19a
Showing
10 changed files
with
165 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { OpenAIModels } from '@slauth.io/langchain-wrapper'; | ||
|
||
export default interface ScannerStrategy { | ||
scan( | ||
codeSnippets: string[], | ||
modelName?: keyof typeof OpenAIModels | ||
): Promise<unknown[] | undefined>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { OpenAIModels, Services } from '@slauth.io/langchain-wrapper'; | ||
import ScannerStrategy from '../../types/scanner-strategy'; | ||
import showAsyncSpinner from '../show-async-spinner'; | ||
import spinners from 'cli-spinners'; | ||
import { yellow } from '../colors'; | ||
|
||
export default class AWSScanner implements ScannerStrategy { | ||
async scan(codeSnippets: string[], modelName: keyof typeof OpenAIModels) { | ||
const statementsPromises = Promise.all( | ||
codeSnippets.map(async snippet => { | ||
return await Services.aws.getStatementsFromCode(snippet, modelName); | ||
}) | ||
); | ||
|
||
await showAsyncSpinner( | ||
{ | ||
spinner: spinners.dots, | ||
text: yellow( | ||
'Scanning for aws-sdk calls (this process might take a few minutes)' | ||
), | ||
}, | ||
statementsPromises | ||
); | ||
|
||
const statements = (await statementsPromises).flat(); | ||
|
||
const policiesPromise = Services.aws.getPoliciesFromStatements( | ||
statements, | ||
modelName | ||
); | ||
|
||
await showAsyncSpinner( | ||
{ | ||
spinner: spinners.dots, | ||
text: yellow( | ||
'Generating policies (this process might take a few minutes)' | ||
), | ||
}, | ||
policiesPromise | ||
); | ||
|
||
return await policiesPromise; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { OpenAIModels, Services } from '@slauth.io/langchain-wrapper'; | ||
import ScannerStrategy from '../../types/scanner-strategy'; | ||
import showAsyncSpinner from '../show-async-spinner'; | ||
import spinners from 'cli-spinners'; | ||
import { yellow } from '../colors'; | ||
|
||
export default class GCPScanner implements ScannerStrategy { | ||
async scan(codeSnippets: string[], modelName: keyof typeof OpenAIModels) { | ||
const permissionsPromise = Promise.all( | ||
codeSnippets.map(async snippet => { | ||
return await Services.gcp.getPermissionsFromCode(snippet, modelName); | ||
}) | ||
); | ||
|
||
await showAsyncSpinner( | ||
{ | ||
spinner: spinners.dots, | ||
text: yellow( | ||
'Scanning for google-cloud sdk calls (this process might take a few minutes)' | ||
), | ||
}, | ||
permissionsPromise | ||
); | ||
|
||
const permissions = (await permissionsPromise).flat(); | ||
|
||
return permissions.length ? permissions : undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import GCPScanner from './gcp'; | ||
import AWSScanner from './aws'; | ||
import { CloudProviders } from '@slauth.io/langchain-wrapper'; | ||
import ScannerStrategy from '../../types/scanner-strategy'; | ||
|
||
type ScannerStrategiesType = { | ||
[k in CloudProviders]: ScannerStrategy; | ||
}; | ||
|
||
const ScannerStrategies: ScannerStrategiesType = { | ||
gcp: new GCPScanner(), | ||
aws: new AWSScanner(), | ||
}; | ||
|
||
export default ScannerStrategies; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { OpenAIModels } from '@slauth.io/langchain-wrapper'; | ||
import ScannerStrategy from '../types/scanner-strategy'; | ||
|
||
export default class Scanner { | ||
private strategy: ScannerStrategy; | ||
|
||
constructor(strategy: ScannerStrategy) { | ||
this.strategy = strategy; | ||
} | ||
|
||
public async scan( | ||
codeSnippets: string[], | ||
modelName?: keyof typeof OpenAIModels | ||
) { | ||
return await this.strategy.scan(codeSnippets, modelName); | ||
} | ||
} |