-
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.
- Loading branch information
Showing
28 changed files
with
1,428 additions
and
46 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
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
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,68 @@ | ||
# (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='Invoke the Agent', context_settings={'ignore_unknown_options': True}) | ||
@click.argument('intg_name', metavar='INTEGRATION') | ||
@click.argument('environment') | ||
@click.argument('args', required=True, nargs=-1) | ||
@click.option('--config-file', hidden=True) | ||
@click.pass_obj | ||
def agent(app: Application, *, intg_name: str, environment: str, args: tuple[str, ...], config_file: str | None): | ||
""" | ||
Invoke the Agent. | ||
""" | ||
import subprocess | ||
|
||
from ddev.e2e.agent import get_agent_interface | ||
from ddev.e2e.config import EnvDataStorage | ||
from ddev.utils.fs import Path | ||
|
||
integration = app.repo.integrations.get(intg_name) | ||
env_data = EnvDataStorage(app.data_dir).get(integration.name, environment) | ||
|
||
if not env_data.exists(): | ||
app.abort(f'Environment `{environment}` for integration `{integration.name}` is not running') | ||
|
||
metadata = env_data.read_metadata() | ||
agent_type = metadata['env_type'] | ||
agent = get_agent_interface(agent_type)(app.platform, integration, environment, metadata, env_data.config_file) | ||
|
||
full_args = list(args) | ||
trigger_run = False | ||
if full_args[0] == 'check': | ||
trigger_run = True | ||
|
||
# TODO: remove this when all invocations migrate to the actual command | ||
if len(full_args) > 2 and full_args[1] == '--jmx-list': | ||
full_args = ['jmx', 'list', full_args[2]] | ||
# Automatically inject the integration name if not passed | ||
elif len(full_args) == 1 or full_args[1].startswith('-'): | ||
full_args.insert(1, intg_name) | ||
|
||
if config_file is None or not trigger_run: | ||
try: | ||
agent.invoke(full_args) | ||
except subprocess.CalledProcessError as e: | ||
app.abort(code=e.returncode) | ||
|
||
return | ||
|
||
import json | ||
|
||
temp_config_file = env_data.config_file.parent / f'{env_data.config_file.name}.bak.example' | ||
env_data.config_file.replace(temp_config_file) | ||
try: | ||
env_data.write_config(json.loads(Path(config_file).read_text())) | ||
agent.invoke(full_args) | ||
finally: | ||
temp_config_file.replace(env_data.config_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,18 @@ | ||
# (C) Datadog, Inc. 2023-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from __future__ import annotations | ||
|
||
import click | ||
|
||
|
||
@click.command(context_settings={'ignore_unknown_options': True}, hidden=True) | ||
@click.argument('intg_name') | ||
@click.argument('environment') | ||
@click.argument('args', nargs=-1) | ||
@click.option('--config') | ||
@click.pass_context | ||
def check(ctx: click.Context, *, intg_name: str, environment: str, args: tuple[str, ...], config: str | None): | ||
from ddev.cli.env.agent import agent | ||
|
||
ctx.invoke(agent, intg_name=intg_name, environment=environment, args=('check', *args), config_file=config) |
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,95 @@ | ||
# (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.group(short_help='Manage the config file') | ||
def config(): | ||
pass | ||
|
||
|
||
@config.command(short_help='Edit the config file with your default editor') | ||
@click.argument('intg_name', metavar='INTEGRATION') | ||
@click.argument('environment') | ||
@click.pass_obj | ||
def edit(app: Application, *, intg_name: str, environment: str): | ||
""" | ||
Edit the config file with your default editor. | ||
""" | ||
from ddev.e2e.config import EnvDataStorage | ||
|
||
integration = app.repo.integrations.get(intg_name) | ||
env_data = EnvDataStorage(app.data_dir).get(integration.name, environment) | ||
|
||
if not env_data.exists(): | ||
app.abort(f'Environment `{environment}` for integration `{integration.name}` is not running') | ||
|
||
click.edit(filename=str(env_data.config_file)) | ||
|
||
|
||
@config.command(short_help='Open the config location in your file manager') | ||
@click.argument('intg_name', metavar='INTEGRATION') | ||
@click.argument('environment') | ||
@click.pass_obj | ||
def explore(app: Application, *, intg_name: str, environment: str): | ||
""" | ||
Open the config location in your file manager. | ||
""" | ||
from ddev.e2e.config import EnvDataStorage | ||
|
||
integration = app.repo.integrations.get(intg_name) | ||
env_data = EnvDataStorage(app.data_dir).get(integration.name, environment) | ||
|
||
if not env_data.exists(): | ||
app.abort(f'Environment `{environment}` for integration `{integration.name}` is not running') | ||
|
||
click.launch(str(env_data.config_file), locate=True) | ||
|
||
|
||
@config.command(short_help='Show the location of the config file') | ||
@click.argument('intg_name', metavar='INTEGRATION') | ||
@click.argument('environment') | ||
@click.pass_obj | ||
def find(app: Application, *, intg_name: str, environment: str): | ||
""" | ||
Show the location of the config file. | ||
""" | ||
from ddev.e2e.config import EnvDataStorage | ||
|
||
integration = app.repo.integrations.get(intg_name) | ||
env_data = EnvDataStorage(app.data_dir).get(integration.name, environment) | ||
|
||
if not env_data.exists(): | ||
app.abort(f'Environment `{environment}` for integration `{integration.name}` is not running') | ||
|
||
app.output(f'[link={env_data.config_file}]{env_data.config_file}[/]') | ||
|
||
|
||
@config.command(short_help='Show the contents of the config file') | ||
@click.argument('intg_name', metavar='INTEGRATION') | ||
@click.argument('environment') | ||
@click.pass_obj | ||
def show(app: Application, *, intg_name: str, environment: str): | ||
""" | ||
Show the contents of the config file. | ||
""" | ||
from ddev.e2e.config import EnvDataStorage | ||
|
||
integration = app.repo.integrations.get(intg_name) | ||
env_data = EnvDataStorage(app.data_dir).get(integration.name, environment) | ||
|
||
if not env_data.exists(): | ||
app.abort(f'Environment `{environment}` for integration `{integration.name}` is not running') | ||
|
||
from rich.syntax import Syntax | ||
|
||
text = env_data.config_file.read_text().rstrip() | ||
app.output(Syntax(text, 'yaml', background_color='default')) |
Oops, something went wrong.