<!DOCTYPE html>
<html lang="en">
{% include "base.html" %}
<body>
{% set run = runs[-1] %}
{% set invocation = run.invocations[-1] %}
{% set results = run.results %}
{% set tool = run.tool %}
{% set rules = tool.driver.rules %}
{% set isError = True if metrics.critical > 0 or metrics.high > 0 or metrics.medium > 5 else False %}
{% set versionControlProvenance = run.versionControlProvenance[-1] if run.versionControlProvenance else {} %}
<div class="container grid-xl" style="min-height: 90vh;">
  {% include "header.html" %}
  <div class="columns">
    <div class="column col-12">
      <div class="hero hero-sm">
        <div class="hero-body">
          <h1>SAST Scan Status <button class="btn btn-{% if isError %}error{% else %}success{% endif %} btn-action"><span class="tooltip tooltip-top" data-tooltip="{% if isError %}Issues were found in this run{% else %}No major issues were found{% endif %}"><i class="icon icon-{% if isError %}cross{% else %}check{% endif %}"></i></span></button></h1>
          <p>Report from the scan performed on <span class="text-dark chip"><i class="icon icon-time"> </i>&nbsp; {{ invocation.endTimeUtc|replace("T", " at ")|replace("Z", "") }}</span> for <span class="text-dark chip"><i class="icon icon-link"> </i>&nbsp; <a href="{{ versionControlProvenance.repositoryUri
          }}">{{ versionControlProvenance.repositoryUri|default('local')}}</a></span>
          </p>
        </div>
      </div>
    </div>
  </div>
  <div class="columns col-gapless bg-sl">
    <div class="column col-6">
      <div class="card">
        <div class="card-header">
          <div class="card-title h4">Repository Details</div>
          <div class="card-subtitle text-gray">{{ versionControlProvenance.repositoryUri|default('local') }}</div>
        </div>
        <div class="card-body">
          <div class=""><strong>Branch</strong> <span>{{ versionControlProvenance.branch }}</span></div>
          <div class=""><strong>Commit</strong> <span>{{ versionControlProvenance.revisionId }}</span></div>
        </div>
      </div>
    </div>
    <div class="column col-6">
      <div class="card">
        <div class="card-header">
          <div class="card-title h4">Invocation Details</div>
          <div class="card-subtitle text-gray">{{ tool.driver.name }}</div>
        </div>
        <div class="card-body">
          <div class=""><strong>Run Id</strong> <span>{{ inlineExternalProperties[-1].runGuid }}</span></div>
          <div class=""><strong>{% if invocation.workingDirectory.uri.startswith("http") %}URL{% else %}Directory{% endif %}</strong> <span>{{ invocation.workingDirectory.uri }}</span></div>
        </div>
      </div>
    </div>
  </div>
  <!-- <div class="divider text-center" data-content="Summary"></div> -->
  <section id="#summary"></section>
  <details class="accordion" open>
    <summary class="accordion-header">
        <h3>
          <i class="icon icon-arrow-right mr-1"></i>
          Executive Summary
        </h3>
    </summary>
    <div class="accordion-body columns col-gapless">
    <div class="column col-12">
        <p>This report was generated by ShiftLeft from the SAST Scan invocation on {{ invocation.endTimeUtc|replace("T", " at ")|replace("Z", "") }}. The scan used the tool <span class="text-bold"> {{ tool.driver.name }}</span> to scan the source code repository {{ versionControlProvenance.repositoryUri|default('local')|urlize(None, target='_blank') }}.
        </p>
        {% if metrics.total %}
        <p>
        Below is a summary of the issues identified:
        </p>
        <div class="container">
          <div class="columns col-12">
            <div class="column col-5">
              <table class="table" id="severity-table">
                <thead>
                <tr>
                  <th>Severity</th>
                  <th>Count</th>
                </tr>
                </thead>
                <tbody>
                {% for sev in ["critical", "high", "medium", "low", "total"] -%}
                <tr>
                  <td><span class="bg-{{ sev|auto_colourize }} chip">{{ sev|upper }}</span></td>
                  <td>{{ metrics.get(sev)|default('NA') }}</td>
                </tr>
                {%- endfor %}
                </tbody>
              </table>
            </div>
            <div class="column col-6">
              <canvas id="severity-chart" width="300" height="300"></canvas>
            </div>
          </div>
        </div>
        {% endif %}
      {% if isError %}
      <p>&nbsp;</p>
      <p><i class="icon icon-flag icon-2x text-warning"></i>&nbsp; ShiftLeft recommends immediate remediation of the key issues identified before using this application in a live environment.</p>
      {% else %}
      <p>&nbsp;</p>
      <p><i class="icon icon-check icon-2x text-success"></i>&nbsp; Based on this report, the application is certified as ready for deployment to test and production environments. Please refer to the dependency and container scan reports (if available) for additional context.</p>
      {% endif %}
    </div>
  </div>
  </details>
  {% if key_issues|length %}
  <!-- <div class="divider text-center" data-content="Requires attention"></div> -->
  <section id="#key_issues"></section>
  <details class="accordion" open>
    <summary class="accordion-header">
    <h3>
    <i class="icon icon-arrow-right mr-1"></i>
      {% if metrics.critical %}
      Key Issues <span class="text-bold">{{ key_issues|length }} / {{ metrics.critical }}</span>
      {% elif metrics.high %}
      Top High Vulnerabilities <span class="text-bold">{{ key_issues|length }} / {{ metrics.high }}</span>
      {% elif metrics.medium %}
      Top Medium Vulnerabilities <span class="text-bold">{{ key_issues|length }} / {{ metrics.medium }}</span>
      {% endif %}
    </h3>
    </summary>
    <div class="accordion-body columns col-gapless flex-row flex-wrap">
    {% for result in key_issues -%}
    {% set result_index = loop.index %}
    <div class="column col-6 flex-column flex-50 flex-grow">
      <div class="panel flex-column flex-100">
        <div class="panel-body flex-column flex-100" style="padding: .8rem;">
          {% for location in result.locations -%}
          <div class="tile flex-column">
            <div class="tile-icon flex-row">
              <div class="flex-column">
                <figure class="bg-{{ result.level }} avatar avatar-lg mr-2" data-initial="{{ result_index }}"></figure>
              </div>
              <div class="flex-column"> <h3>{{ result.ruleId|default('') }}</h3> </div>
            </div>
            <div class="tile-content flex-column flex-grow">
              <span><a target="_blank" href="{{ location.physicalLocation.artifactLocation.uri }}">{{ location.physicalLocation.artifactLocation.uri|basename }}</a></span>
              <p class="tile-subtitle"><div class=""><p>{%  if result.message.markdown %}{{ result.message.markdown|remove_end_period|markdown }}{%  else %}{{ result.message.text|auto_text_highlight|safe }}{%  endif %}</p></div></p>
{% set contextRegion = location.physicalLocation.contextRegion if location.physicalLocation.contextRegion else location.physicalLocation.region  %}
{% set allLines = contextRegion.snippet.text %}
{% set line_count = allLines.split("\n") %}
{% set firstLine = allLines.split("\n")[0].strip() %}
{% set remLines = "<br/>".join(allLines.split("\n")[1:]) %}
{% if line_count|length and allLines != "" %}
<pre class="code"><code><a target="_blank" class="btn" href="{{ location.physicalLocation.artifactLocation.uri }}#L{{ contextRegion.startLine }}"><i class="icon icon-location"></i> {{ contextRegion.startLine }}:</a> {{ firstLine|safe }}<br/>        {{ remLines|safe }}
</code>
</pre>
{% endif %}
            </div>
          </div>
          {%- endfor %}
        </div>
      </div>
    </div>
    {%- endfor %}
  </div>
  </details>
  {% endif %}
  <!-- <div class="divider text-center" data-content="All"></div> -->
  <section id="#all_issues"></section>
  <div class="columns col-gapless" style="margin-top: 2em;">
    <div class="column col-12">
      <h3><i class="icon icon-link"></i> All Issues <span class="text-bold">({{ metrics.total }})</span></h3>
    </div>
    <div class="column col-12">
      <div class="filter">
        <input type="radio" id="tag-0" class="filter-tag" name="filter-radio" hidden checked>
        <input type="radio" id="tag-1" class="filter-tag" name="filter-radio" hidden>
        <input type="radio" id="tag-2" class="filter-tag" name="filter-radio" hidden>
        <input type="radio" id="tag-3" class="filter-tag" name="filter-radio" hidden>
        <input type="radio" id="tag-4" class="filter-tag" name="filter-radio" hidden>

        <div class="filter-nav">
          <label class="chip" for="tag-0">All ({{ metrics.total }})</label>
          <label class="chip" for="tag-1">Critical ({{ metrics.critical }})</label>
          <label class="chip" for="tag-2">High ({{ metrics.high }})</label>
          <label class="chip" for="tag-3">Medium ({{ metrics.medium }})</label>
          <label class="chip" for="tag-4">Low ({{ metrics.low }})</label>
        </div>
        <div class="filter-body">
          <div class="data-table">
            <div class="table-head">
              <div class="table-header-row">
                <div>Rule</div>
                <div>Severity</div>
                <div>Source location</div>
                <div>Message</div>
              </div>
            </div>
            <div class="table-body">
          {% for result in results|sort(attribute="properties.issue_severity") -%}
          {% set result_index = loop.index %}
          {% for location in result.locations -%}
          {% set contextRegion = location.physicalLocation.contextRegion if location.physicalLocation.contextRegion else location.physicalLocation.region  %}
          {% set allLines = contextRegion.snippet.text %}
{% set line_count = allLines.split("\n") %}
{% set firstLine = allLines.split("\n")[0].strip() %}
{% set remLines = "<br/>".join(allLines.split("\n")[1:]) %}
          <div class="filter-item table-data-row" data-tag="tag-{{ result.properties.issue_severity|replace('CRITICAL', '1')|replace('HIGH', '2')|replace('MEDIUM', '3')|replace('LOW', '4') }}">
            <div class="table-cell">{{ result.ruleId|default('')|linkify_rule(rules)|safe }}</div>
            <div class="table-cell"><span class="chip bg-{{ result.properties.issue_severity|auto_colourize }}">{{ result.properties.issue_severity }}</span></div>
            <div class="table-cell"><a target="_blank" class="btn btn-link" href="{{ location.physicalLocation.artifactLocation.uri }}#L{{ contextRegion.startLine }}"><i class="icon icon-link"></i> {{ location.physicalLocation.artifactLocation.uri|basename }}</a></div>
            <div class="table-cell">
              <span>{%  if result.message.markdown %}{{ result.message.markdown|remove_end_period|markdown }}{%  else %}{{ result.message.text|auto_text_highlight|safe }}{% endif %}</span>
{% if line_count|length and allLines != "" %}
              <pre class="code"><code>{{ firstLine|safe }}<br/>{{ remLines|safe }}</code></pre>
{% endif %}
            </div>
          </div>
          {%- endfor %}
          {%- endfor %}
        </div>
      </div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="container grid-xl" style="height: 3rem; margin-top: 0.8rem; color: #bcc3ce;">
  <p>Thank you for using <a href="https://shiftleft.io" target="_blank">ShiftLeft</a>. Looking for a more detailed analysis? Check out ShiftLeft <a href="https://www.shiftleft.io/" target="_blank">NextGen SAST</a> or login to your <a href="https://www.shiftleft.io/dashboard" target="_blank">dashboard</a>.</p>
</div>
{% include "chart.html" %}
</body>
</html>
