-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validations for removed dependencies (#14556)
* Map out new licenses validation * Implement validations for extra licenses * Add constants to config.toml * Implement license validation * Uncomment legacy licenses validation * Keep license command addition in same place * Small style change * Update config.toml override values * Refactor * Fix style * Apply suggestions from code review Co-authored-by: Ofek Lev <[email protected]> * Update suggestions * Require CI for license validation tests and update to use empty envvars * Fix permission for file * Add windows version of setting github env vars * Fix windows file * Change to powershell script * Output GITHUB_ENV on windows CI * Convert entirely to powershell * Change back to bat file * Test DD_GITHUB_USER value * Print github user in license test * Manually set Github user and token in test * Fix config_file * Print github user * Check if tokens are the same * Remove additional space in bat script * Fix style and remove test code * Change order of scripts * Try commenting out model.github override * Revert previous commit * Change to threads instead of async * Switch out async request to requests * Clean up * Fix style --------- Co-authored-by: Ofek Lev <[email protected]>
- Loading branch information
Showing
12 changed files
with
223 additions
and
17 deletions.
There are no files selected for viewing
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,9 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
set +x | ||
|
||
echo "DD_GITHUB_USER=$DD_GITHUB_USER" >> "$GITHUB_ENV" | ||
echo "DD_GITHUB_TOKEN=$DD_GITHUB_TOKEN" >> "$GITHUB_ENV" | ||
|
||
set -x |
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,2 @@ | ||
echo DD_GITHUB_USER=%DD_GITHUB_USER%>> %GITHUB_ENV% | ||
echo DD_GITHUB_TOKEN=%DD_GITHUB_TOKEN%>> %GITHUB_ENV% |
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
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,55 @@ | ||
# (C) Datadog, Inc. 2023-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import click | ||
|
||
if TYPE_CHECKING: | ||
from ddev.cli.application import Application | ||
|
||
|
||
@click.command(short_help='Validate third-party license list') | ||
@click.option('--sync', '-s', is_flag=True, help='Generate the `LICENSE-3rdparty.csv` file') | ||
@click.pass_context | ||
def licenses(ctx: click.Context, sync): | ||
app: Application = ctx.obj | ||
|
||
if app.repo.name != 'core': | ||
app.display_info(f"License validation is only available for repo `core`, skipping for repo `{app.repo.name}`") | ||
app.abort() | ||
|
||
from packaging.requirements import Requirement | ||
|
||
validation_tracker = app.create_validation_tracker('Licenses') | ||
|
||
# Validate that all values in the constants (EXPLICIT_LICENSES and | ||
# PACKAGE_REPO_OVERRIDES) appear in agent_requirements.in file | ||
|
||
agent_requirements_path = app.repo.agent_requirements | ||
|
||
packages_set = set() | ||
with open(agent_requirements_path, 'r', encoding='utf-8') as f: | ||
for _i, line in enumerate(f.readlines()): | ||
requirement = Requirement(line.strip()) | ||
packages_set.add(requirement.name) | ||
|
||
for dependency_override, constant_name in [('licenses', 'EXPLICIT_LICENSES'), ('repo', 'PACKAGE_REPO_OVERRIDES')]: | ||
for name in app.repo.config.get(f'/overrides/dependencies/{dependency_override}', {}): | ||
if name.lower() not in packages_set: | ||
validation_tracker.error( | ||
(constant_name, name), | ||
message=f"{constant_name} contains additional package not in agent requirements: {name}", | ||
) | ||
|
||
if validation_tracker.errors: | ||
validation_tracker.display() | ||
app.abort() | ||
|
||
# Call legacy licenses validation | ||
from datadog_checks.dev.tooling.commands.validate.licenses import licenses as legacy_licenses_validation | ||
|
||
ctx.invoke(legacy_licenses_validation, sync=sync) | ||
validation_tracker.display() |
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,63 @@ | ||
# (C) Datadog, Inc. 2023-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
|
||
import pytest | ||
from ddev.utils.toml import dump_toml_data, load_toml_file | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name, contents, expected_error_output", | ||
[ | ||
pytest.param( | ||
"licenses", | ||
{'dummy_package': 'dummy_license'}, | ||
"EXPLICIT_LICENSES contains additional package not in agent", | ||
id="explicit licenses", | ||
), | ||
pytest.param( | ||
"repo", | ||
{'dummy_package': 'https://github.com/dummy_package'}, | ||
"PACKAGE_REPO_OVERRIDES contains additional package not in agent", | ||
id="package repo overrides", | ||
), | ||
], | ||
) | ||
def test_error_extra_dependency(name, contents, expected_error_output, ddev, repository, network_replay, helpers): | ||
network_replay('fixtures/network/license/extra_dependency.yaml', record_mode='none') | ||
ddev_config_path = repository.path / '.ddev' / 'config.toml' | ||
|
||
data = load_toml_file(ddev_config_path) | ||
|
||
data['overrides']['dependencies'] = {name: contents} | ||
|
||
dump_toml_data(data, ddev_config_path) | ||
|
||
result = ddev('validate', 'licenses') | ||
|
||
assert result.exit_code == 1, result.output | ||
|
||
# Check if expected error validation error message is in output | ||
assert expected_error_output in helpers.remove_trailing_spaces(result.output) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"repo, expected_message", | ||
[ | ||
pytest.param("core", "Licenses file is valid!", id="Core integrations"), | ||
pytest.param( | ||
"extras", | ||
"License validation is only available for repo `core`, skipping for repo `extras`", | ||
id="Extras integrations", | ||
), | ||
], | ||
) | ||
@pytest.mark.requires_ci | ||
def test_validate_repo(repo, repository, expected_message, ddev, helpers, config_file): | ||
config_file.model.repo = repo | ||
config_file.save() | ||
|
||
result = ddev("validate", "licenses") | ||
|
||
assert expected_message in helpers.remove_trailing_spaces(result.output) |
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