Skip to content

Commit ab0dd3e

Browse files
authored
docs: add tutorial for find source command (#920)
Signed-off-by: Ben Selwyn-Smith <[email protected]>
1 parent 16e28e6 commit ab0dd3e

File tree

7 files changed

+161
-0
lines changed

7 files changed

+161
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. Copyright (c) 2023 - 2023, Oracle and/or its affiliates. All rights reserved.
2+
.. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
3+
4+
.. _find-source-command-cli:
5+
6+
===========
7+
Find Source
8+
===========
9+
10+
-----------
11+
Description
12+
-----------
13+
14+
Find the source commit, and optionally source repository, of a target artifact.
15+
16+
-----
17+
Usage
18+
-----
19+
20+
.. code-block:: shell
21+
22+
usage: ./run_macaron.sh find-source -purl PURL [-rp REPO_PATH]
23+
24+
-------
25+
Options
26+
-------
27+
28+
.. option:: -h, --help
29+
30+
Show this help message and exit
31+
32+
.. option:: -purl PACKAGE_URL, --package-url PACKAGE_URL
33+
34+
The PURL string used to uniquely identify the artifact.
35+
36+
.. option:: -rp REPO_PATH, --repo-path REPO_PATH
37+
38+
The path to the repository.

docs/source/pages/developers_guide/apidoc/macaron.repo_finder.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ macaron.repo\_finder.repo\_finder\_java module
6565
:undoc-members:
6666
:show-inheritance:
6767

68+
macaron.repo\_finder.repo\_utils module
69+
---------------------------------------
70+
71+
.. automodule:: macaron.repo_finder.repo_utils
72+
:members:
73+
:undoc-members:
74+
:show-inheritance:
75+
6876
macaron.repo\_finder.repo\_validator module
6977
-------------------------------------------
7078

docs/source/pages/developers_guide/apidoc/macaron.slsa_analyzer.checks.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ macaron.slsa\_analyzer.checks.build\_service\_check module
4141
:undoc-members:
4242
:show-inheritance:
4343

44+
macaron.slsa\_analyzer.checks.build\_tool\_check module
45+
-------------------------------------------------------
46+
47+
.. automodule:: macaron.slsa_analyzer.checks.build_tool_check
48+
:members:
49+
:undoc-members:
50+
:show-inheritance:
51+
4452
macaron.slsa\_analyzer.checks.check\_result module
4553
--------------------------------------------------
4654

docs/source/pages/tutorials/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ For the full list of supported technologies, such as CI services, registries, an
2424
generate_verification_summary_attestation
2525
use_verification_summary_attestation
2626
exclude_include_checks
27+
source_finder
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.. Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
2+
.. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
3+
4+
-------------
5+
Source Finder
6+
-------------
7+
8+
This tutorial demonstrates how Macaron can find the source commit of a given artifact, and optionally the source repository, while performing no analyses. This operation exists as a standalone feature, using the ``find-source`` command, for users that wish to utilise only these features of Macaron without spending time performing additional unnecessary steps.
9+
10+
Unlike the integrated commit finder (demonstrated in another tutorial :doc:`here </pages/tutorials/source_finder>`), the ``find-source`` command does not require cloning the target repository, thereby saving time in many cases, and disk space in all cases. For those who still wish to clone the repository as part of the process, a configuration option exists and will be explained below.
11+
12+
******************************
13+
Installation and Prerequisites
14+
******************************
15+
16+
Skip this section if you already know how to install Macaron.
17+
18+
.. toggle::
19+
20+
Please follow the instructions :ref:`here <installation-guide>`. In summary, you need:
21+
22+
* Docker
23+
* the ``run_macaron.sh`` script to run the Macaron image.
24+
25+
.. note:: At the moment, Docker alternatives (e.g. podman) are not supported.
26+
27+
28+
You also need to provide Macaron with a GitHub token through the ``GITHUB_TOKEN`` environment variable.
29+
30+
To obtain a GitHub Token:
31+
32+
* Go to ``GitHub settings`` → ``Developer Settings`` (at the bottom of the left side pane) → ``Personal Access Tokens`` → ``Fine-grained personal access tokens`` → ``Generate new token``. Give your token a name and an expiry period.
33+
* Under ``"Repository access"``, choosing ``"Public Repositories (read-only)"`` should be good enough in most cases.
34+
35+
Now you should be good to run Macaron. For more details, see the documentation :ref:`here <prepare-github-token>`.
36+
37+
*********
38+
Execution
39+
*********
40+
41+
To use the ``find-source`` command and find the repository and commit for an artifact, Macaron can be run with the following command:
42+
43+
.. code-block:: shell
44+
45+
./run_macaron.sh find-source -purl pkg:npm/[email protected]
46+
47+
The output of the command will be written to the command line, and to a report file in the JSON format. The report can be found within the ``output`` folder under the respective path of the artifact that was passed to the command. (See :ref:`Output Files Guide <output_files_guide>`). In this case, Macaron created a report file: ``output/reports/npm/semver/semver.source.json``, which contains the repository and commit that was found.
48+
49+
To open the report and view the contents, you can use the following:
50+
51+
.. code-block:: shell
52+
53+
open output/reports/npm/semver/semver.source.json
54+
55+
Inside you will find the ``repo`` and ``commit`` properties have been populated with ``https://github.com/npm/node-semver`` and ``eb1380b1ecd74f6572831294d55ef4537dfe1a2a`` respectively. As this is a GitHub repository, Macaron also creates a URL that leads directly to the reported commit, found under the ``url`` property.
56+
57+
If the repository for an artifact is already known, the ``find-source`` command can be given it to save looking it up again. To do this, the command changes to:
58+
59+
.. code-block:: shell
60+
61+
./run_macaron.sh find-source -purl pkg:npm/[email protected] -rp https://github.com/npm/node-semver
62+
63+
.. note:: If you are unfamiliar with PackageURLs (purl), see this link: `PURLs <https://github.com/package-url/purl-spec>`_.
64+
65+
********************
66+
Execution with Clone
67+
********************
68+
69+
For the case where cloning the repository is desirable, perhaps because further use of the contents are planned, Macaron requires this to be specified in a custom ``ini`` configuration file that is passed as input. See `How to change the default configuration </pages/using#change-config>`_ for more details. Within the configuration file the following option should be set:
70+
71+
.. code-block:: ini
72+
73+
[repofinder]
74+
find_source_should_clone = True
75+
76+
Then Macaron can be run with:
77+
78+
.. code-block:: shell
79+
80+
./run_macaron.sh -dp <path-to-modified-default.ini> find-source -purl pkg:npm/[email protected]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
4+
5+
[[ "$(jq -r '.commit' output/reports/npm/semver/semver.source.json)" = "eb1380b1ecd74f6572831294d55ef4537dfe1a2a" ]] &&
6+
[[ "$(jq -r '.repo' output/reports/npm/semver/semver.source.json)" = "https://github.com/npm/node-semver" ]]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
3+
4+
description: |
5+
Performing the examples provided within the related tutorial.
6+
7+
tags:
8+
- tutorial
9+
10+
steps:
11+
- name: Run macaron find source
12+
kind: find-source
13+
options:
14+
command_args:
15+
- -purl
16+
17+
- name: Check the report contents
18+
kind: shell
19+
options:
20+
cmd: ./check_output.sh

0 commit comments

Comments
 (0)