Skip to content

Commit 05c186f

Browse files
Merge pull request #12 from advanced-security/nicolaswill/additional-files-and-certs
Add support for additional files and certificates
2 parents a1a7d1c + b3f626f commit 05c186f

File tree

5 files changed

+642
-127
lines changed

5 files changed

+642
-127
lines changed

codeql_bundle/cli.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import List, Optional
1515
import sys
1616
import logging
17+
import os
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -40,6 +41,9 @@
4041
type=click.Path(exists=True, path_type=Path),
4142
default=Path.cwd(),
4243
)
44+
@click.option(
45+
"--no-precompile", "-nc", is_flag=True, help="Do not pre-compile the bundle."
46+
)
4347
@click.option(
4448
"-l",
4549
"--log",
@@ -49,16 +53,35 @@
4953
),
5054
default="WARNING",
5155
)
52-
@click.option("-p", "--platform", multiple=True, type=click.Choice(["linux64", "osx64", "win64"], case_sensitive=False), help="Target platform for the bundle")
53-
@click.option("-c", "--code-scanning-config", type=click.Path(exists=True, path_type=Path), help="Path to a Code Scanning configuration file that will be the default for the bundle")
56+
@click.option(
57+
"-p",
58+
"--platform",
59+
multiple=True,
60+
type=click.Choice(["linux64", "osx64", "win64"], case_sensitive=False),
61+
help="Target platform for the bundle",
62+
)
63+
@click.option(
64+
"-c",
65+
"--code-scanning-config",
66+
type=click.Path(exists=True, path_type=Path),
67+
help="Path to a Code Scanning configuration file that will be the default for the bundle",
68+
)
69+
@click.option(
70+
"-a",
71+
"--additional-data-config",
72+
type=click.Path(exists=True, path_type=Path),
73+
help="Path to a JSON file specifying additional data to install into the bundle",
74+
)
5475
@click.argument("packs", nargs=-1, required=True)
5576
def main(
5677
bundle_path: Path,
5778
output: Path,
5879
workspace: Path,
80+
no_precompile: bool,
5981
loglevel: str,
6082
platform: List[str],
6183
code_scanning_config: Optional[Path],
84+
additional_data_config: Optional[Path],
6285
packs: List[str],
6386
) -> None:
6487

@@ -73,6 +96,8 @@ def main(
7396
level=getattr(logging, loglevel.upper()),
7497
)
7598

99+
workspace = Path(os.path.abspath(workspace))
100+
76101
if workspace.name == "codeql-workspace.yml":
77102
workspace = workspace.parent
78103

@@ -82,8 +107,15 @@ def main(
82107

83108
try:
84109
bundle = CustomBundle(bundle_path, workspace)
110+
# options for custom bundle
111+
bundle.disable_precompilation = no_precompile
85112

86-
unsupported_platforms = list(filter(lambda p: not bundle.supports_platform(BundlePlatform.from_string(p)), platform))
113+
unsupported_platforms = list(
114+
filter(
115+
lambda p: not bundle.supports_platform(BundlePlatform.from_string(p)),
116+
platform,
117+
)
118+
)
87119
if len(unsupported_platforms) > 0:
88120
logger.fatal(
89121
f"The provided bundle supports the platform(s) {', '.join(map(str, bundle.platforms))}, but doesn't support the following platform(s): {', '.join(unsupported_platforms)}"
@@ -109,7 +141,6 @@ def main(
109141
else:
110142
selected_packs = packs_in_workspace
111143

112-
113144
missing_packs = set(packs) - {pack.config.name for pack in selected_packs}
114145
if len(missing_packs) > 0:
115146
logger.fatal(
@@ -121,8 +152,15 @@ def main(
121152
f"Adding the pack(s) {','.join(map(lambda p: p.config.name, selected_packs))} and its workspace dependencies to the custom bundle."
122153
)
123154
bundle.add_packs(*selected_packs)
155+
if additional_data_config:
156+
logger.info(
157+
f"Installing additions specified in the config file {additional_data_config} to the custom bundle."
158+
)
159+
bundle.add_files_and_certs(additional_data_config, workspace)
124160
if code_scanning_config:
125-
logger.info(f"Adding the Code Scanning configuration file {code_scanning_config} to the custom bundle.")
161+
logger.info(
162+
f"Adding the Code Scanning configuration file {code_scanning_config} to the custom bundle."
163+
)
126164
bundle.add_code_scanning_config(code_scanning_config)
127165
logger.info(f"Bundling custom bundle(s) at {output}")
128166
platforms = set(map(BundlePlatform.from_string, platform))

0 commit comments

Comments
 (0)