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 #21 from lacework-dev/add-polygraph-image
add capability to embed images from filesystem + add polygraph image to csa report
- Loading branch information
Showing
10 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 @@ | ||
def bytes_to_image_tag(img_bytes,format): | ||
import base64 | ||
b64content = base64.b64encode(img_bytes).decode('utf-8') | ||
return f"<img src='data:image/{format};base64,{b64content}'/>" |
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 |
---|---|---|
@@ -1,6 +1 @@ | ||
from .host_vulns_by_severity_bar import host_vulns_by_severity_bar | ||
|
||
def bytes_to_image_tag(img_bytes): | ||
import base64 | ||
b64content = base64.b64encode(img_bytes).decode('utf-8') | ||
return f"<img src='data:image/svg+xml;base64,{b64content}'/>" |
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 @@ | ||
from .local_file import local_file |
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,4 @@ | ||
def local_file(path): | ||
with open(path, "rb") as in_file: | ||
file_bytes = in_file.read() | ||
return file_bytes |
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
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,28 @@ | ||
import json | ||
import os | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
def generate_report(_shared, report_save_path, use_cached_data): | ||
import jinja2 | ||
|
||
graphic_bytes = _shared.p_local_asset.local_file(os.path.join(os.getcwd(), 'assets/lacework/images/polygraph-info.png')) | ||
graphic_html = _shared.common.bytes_to_image_tag(graphic_bytes,'png') | ||
|
||
data = { | ||
'graphic': graphic_html | ||
} | ||
|
||
templateLoader = jinja2.FileSystemLoader(searchpath=os.path.dirname(__file__)) | ||
templateEnv = jinja2.Environment(loader=templateLoader, autoescape=True, trim_blocks=True, lstrip_blocks=True) | ||
TEMPLATE_FILE = "template.html" | ||
template = templateEnv.get_template(TEMPLATE_FILE) | ||
html = template.render( | ||
data = data | ||
) | ||
|
||
logger.info('Saving report to: ' + report_save_path) | ||
|
||
with open(report_save_path, 'w') as file: | ||
file.write(html) |