Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixline numberissue #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion xgitguard/github-enterprise/enterprise_cred_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
from ml_training.model import xgg_train_model
from utilities.common_utilities import mask_data
from utilities.file_utilities import write_to_csv_file
from utilities.common_utilities import check_github_token_env
from utilities.common_utilities import check_github_token_env,findLineNumber

file_prefix = "xgg_"

Expand Down Expand Up @@ -224,6 +224,8 @@ def format_detection(skeyword, org_url, url, code_content, secrets, skeyword_cou
else:
# Mask the current secret
masked_secret = mask_data(code_line, secret)
linenumber=findLineNumber(code_content.split("\n"),code_line)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename variable since it is is not the line number, rather a list of code lines, Also we can move this line to the utility function.

valid_secret_row.append(linenumber)
valid_secret_row.append(masked_secret)

valid_secret_row.append(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Expand Down
4 changes: 3 additions & 1 deletion xgitguard/github-enterprise/enterprise_key_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
from ml_training.model import xgg_train_model
from utilities.common_utilities import mask_data
from utilities.file_utilities import write_to_csv_file
from utilities.common_utilities import check_github_token_env
from utilities.common_utilities import check_github_token_env,findLineNumber

file_prefix = "xgg_"

Expand Down Expand Up @@ -209,6 +209,8 @@ def format_detection(skeyword, org_url, url, code_content, secrets, skeyword_cou
else:
# Mask the current secret
masked_secret = mask_data(code_line, secret)
linenumber=findLineNumber(code_content.split("\n"),code_line)
valid_secret_row.append(linenumber)
valid_secret_row.append(masked_secret)

valid_secret_row.append(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Expand Down
5 changes: 4 additions & 1 deletion xgitguard/github-public/public_cred_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import pandas as pd
from urlextract import URLExtract


MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
parent_dir = os.path.dirname(MODULE_DIR)
sys.path.insert(0, parent_dir)
Expand All @@ -81,7 +82,7 @@
from ml_training.model import xgg_train_model
from utilities.common_utilities import mask_data
from utilities.file_utilities import write_to_csv_file
from utilities.common_utilities import check_github_token_env
from utilities.common_utilities import check_github_token_env,findLineNumber

file_prefix = "xgg_"

Expand Down Expand Up @@ -226,6 +227,8 @@ def format_detection(pkeyword, skeyword, url, code_content, secrets, keyword_cou
else:
# Mask the current secret
masked_secret = mask_data(code_line, secret)
linenumber=findLineNumber(code_content.split("\n"),code_line)
valid_secret_row.append(linenumber)
valid_secret_row.append(masked_secret)
valid_secret_row.append(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
valid_secret_row.append(confidence_score[0])
Expand Down
4 changes: 3 additions & 1 deletion xgitguard/github-public/public_key_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
from ml_training.model import xgg_train_model
from utilities.common_utilities import mask_data
from utilities.file_utilities import write_to_csv_file
from utilities.common_utilities import check_github_token_env
from utilities.common_utilities import check_github_token_env,findLineNumber

file_prefix = "xgg_"

Expand Down Expand Up @@ -208,6 +208,8 @@ def format_detection(pkeyword, skeyword, url, code_content, secrets, keyword_cou
else:
# Mask the current secret
masked_secret = mask_data(code_line, secret)
linenumber=findLineNumber(code_content.split("\n"),code_line)
valid_secret_row.append(linenumber)
valid_secret_row.append(masked_secret)
valid_secret_row.append(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
valid_secret_row.append(confidence_score[0])
Expand Down
6 changes: 6 additions & 0 deletions xgitguard/utilities/file_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

logger = logging.getLogger("xgg_logger")

def findLineNumber(code_content,code_line):
for index,line in enumerate(code_content):
if(code_line in line or code_line == line):
return index+1
return -1


def read_text_file(file_path):
"""
Expand Down