working PoC Checkov integration
MODIFY
checkov/common/runners/runner_registry.py
checkov/common/runners/runner_registry.py
@@ -12,6 +12,9 @@ from termcolor import colored
from git import Repo
import re
from checkov.common.bridgecrew.platform_integration import BcPlatformIntegration
+import requests
+import time
+
class RunnerRegistry(object):
runners = []
@@ -70,9 +73,31 @@ class RunnerRegistry(object):
if reply[:1] == 'y':
print(Style.BRIGHT + colored("\nEmail Address? \n", 'blue', attrs=['bold']) + colored("Last prompt, promise, well automate the rest, and redirect you to your visualizations! ", 'yellow') + Style.RESET_ALL)
reply = str(input('E-Mail:')).lower().strip()
- #Ignoring the e-mail for now, we have a dummy account
- # TODO: Integrate with lambda for user creation
- bc_poc_api_token="be9a013d-7879-56b7-a33d-3a9d24b11c98"
+ print(Style.BRIGHT + colored("\nCreating Bridgecrew account & configuring Checkov ... \n", 'green', attrs=['bold']) + Style.RESET_ALL)
+ bc_poc_api = environ["BC_POC_API"]
+
+ pocApiPayload = {
+ "email": reply
+ }
+
+ signupHeaders = {
+ 'Accept': 'application/json',
+ 'User-Agent': 'Mozilla/5.0 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
+ 'Content-Type': 'application/json;charset=UTF-8'
+ }
+
+ pocApiResponse = requests.request("POST", bc_poc_api, headers=signupHeaders, json=pocApiPayload)
+
+ # DONE: Integrate with lambda for user creation
+ if pocApiResponse.status_code == 200:
+ bc_poc_api_token = pocApiResponse.json()["userApiToken"]
+ print(Style.BRIGHT + colored("Account Created! \n", 'green', attrs=['bold']) + Style.RESET_ALL)
+ print(Style.BRIGHT + colored("Using API Token: {} \n".format(bc_poc_api_token), 'green', attrs=['bold']) + Style.RESET_ALL)
+ #bc_poc_api_token="f4c08644-6a2f-514d-9ccf-a9b0fbe92e16"
+
+ print(Style.BRIGHT + colored("POC!! Sleeping for 3 mins waiting for upload-files-to-scanners-bucket to be created! \n", 'red', attrs=['bold']) + Style.RESET_ALL)
+ time.sleep(180)
+
if args.file:
#Work out git repo name for BC --repo-id from dir at path of --file (files var)
#TODO: DIR happy path first
@@ -88,7 +113,6 @@ class RunnerRegistry(object):
try:
repo = Repo(dir)
git_remote_uri = repo.remotes.origin.url
- #regex_repo_id = re.compile(r'^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$')
git_repo_dict = re.match(r'(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git', git_remote_uri).group(4,5)
repo_id = git_repo_dict[0] + "/" + git_repo_dict[1]
valid_repos +=1
@@ -98,6 +122,8 @@ class RunnerRegistry(object):
#No pushed repo (so no org/repo path)
repo_id = "bridgecrewuserrepo/" + path.basename(args.directory[0])
print(repo_id)
+
+
bc_integration = BcPlatformIntegration()
bc_integration.setup_bridgecrew_credentials(bc_api_key=bc_poc_api_token, repo_id=repo_id)
if bc_integration.is_integration_configured():
@@ -107,7 +133,10 @@ class RunnerRegistry(object):
bc_integration.persist_scan_results(scan_reports)
print(Style.BRIGHT + colored("Checkov report upload complete", 'green', attrs=['bold']) + Style.RESET_ALL)
bc_integration.commit_repository(args.branch)
+ print(Style.BRIGHT + colored("COMPLETE! Your Bridgecrew dashboard is available here: \n {} \n Username: {} \n Pasword: {}".format(pocApiResponse.json()["dashboardURL"],pocApiResponse.json()["userEmail"],pocApiResponse.json()["userPassword"]), 'blue', attrs=['bold']) + Style.RESET_ALL)
+ else:
+ print(Style.BRIGHT + colored("\nCould not create account, please try again on your next scan! \n", 'red', attrs=['bold']) + Style.RESET_ALL)
exit_code = 1 if 1 in exit_codes else 0

MODIFY
poc-functions/signup.py
poc-functions/signup.py
@@ -98,7 +98,7 @@ def signup(event, context):
"dashboardURL": bc_dashboard_url
}
- print(json.dumps(returnUserDetails))
+ print(json.dumps(returnUserDetails)):
response = {
"statusCode": 200,

working PoC Checkov integration