-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from flipkart-incubator/dev
CI/CD integration support
- Loading branch information
Showing
7 changed files
with
335 additions
and
56 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
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,25 @@ | ||
import os | ||
|
||
from pymongo import MongoClient | ||
from pymongo.errors import ServerSelectionTimeoutError | ||
|
||
|
||
# Mongo DB connection | ||
def db_connect(): | ||
maxSevSelDelay = 1 | ||
try: | ||
mongo_host = 'localhost' | ||
mongo_port = 27017 | ||
|
||
if 'MONGO_PORT_27017_TCP_ADDR' in os.environ : | ||
mongo_host = os.environ['MONGO_PORT_27017_TCP_ADDR'] | ||
|
||
if 'MONGO_PORT_27017_TCP_PORT' in os.environ: | ||
mongo_port = int(os.environ['MONGO_PORT_27017_TCP_PORT']) | ||
|
||
client = MongoClient(mongo_host, mongo_port, serverSelectionTimeoutMS=maxSevSelDelay) | ||
client.server_info() | ||
return client | ||
|
||
except ServerSelectionTimeoutError as err: | ||
exit("Failed to connect to MongoDB.") |
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 ast | ||
import json | ||
|
||
from dbconnection import db_connect | ||
|
||
db_object = db_connect() | ||
global db | ||
db = db_object.apiscan | ||
|
||
def check_scan_status(data): | ||
# Return the Scan status | ||
total_scan = data['total_scan'] | ||
count = 0 | ||
for key,value in data.items(): | ||
if value == 'Y' or value == 'y': | ||
count += 1 | ||
|
||
if total_scan == count: | ||
return "Completed" | ||
else: | ||
return "In progress" | ||
|
||
def scan_status(scan_id): | ||
# Return scan status based on scan id | ||
data = db.scanids.find({"scanid": scan_id}) | ||
data = data[0] | ||
data.pop('_id') | ||
scan_result = check_scan_status(ast.literal_eval(json.dumps(data))) | ||
return scan_result |
Oops, something went wrong.