Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions newsfragments/1483.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add a ``show-model-target-web-api-details`` command, which creates and
shows Model Target Web API credentials, in YAML or in
``--env-var-format``.
56 changes: 56 additions & 0 deletions src/vws_web_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,61 @@ def delete_model_target_web_api_credentials(
driver.quit()


@click.command(name="show-model-target-web-api-details")
@click.option("--email-address", envvar="VWS_EMAIL_ADDRESS", required=True)
@click.option("--password", envvar="VWS_PASSWORD", required=True)
@click.option(
"--advanced-scopes",
is_flag=True,
help=(
"Also request the advanced Model Target scope. "
"This requires a Vuforia Enterprise developer account."
),
)
@click.option("--env-var-format", is_flag=True)
@beartype
def show_model_target_web_api_details(
*,
email_address: str,
password: str,
advanced_scopes: bool,
env_var_format: bool,
) -> None:
"""Create and show Model Target Web API credentials.

The created OAuth2 client credential is left on the Vuforia
account so that it can be used.
"""
scopes = (
MODEL_TARGET_WEB_API_ADVANCED_SCOPES
if advanced_scopes
else MODEL_TARGET_WEB_API_STANDARD_SCOPES
)
driver = create_chrome_driver()
try:
log_in(
driver=driver,
email_address=email_address,
password=password,
)
details = get_model_target_web_api_details(
driver=driver,
scopes=scopes,
)
finally:
driver.quit()
if env_var_format:
env_var_format_details = {
"MODEL_TARGET_VUFORIA_CLIENT_ID": details["client_id"],
"MODEL_TARGET_VUFORIA_CLIENT_SECRET": details["client_secret"],
"MODEL_TARGET_VUFORIA_CAD_DATA_URL": details["cad_data_url"],
}
for key, value in env_var_format_details.items():
click.echo(message=f"{key}={value}")
else:
click.echo(message=yaml.dump(data=details), nl=False)


@click.command()
@click.option("--license-name", required=True)
@click.option("--email-address", envvar="VWS_EMAIL_ADDRESS", required=True)
Expand Down Expand Up @@ -1947,6 +2002,7 @@ def show_license_details(
vws_web_tools_group.add_command(cmd=get_vumark_instance_id)
vws_web_tools_group.add_command(cmd=show_database_details)
vws_web_tools_group.add_command(cmd=show_license_details)
vws_web_tools_group.add_command(cmd=show_model_target_web_api_details)
vws_web_tools_group.add_command(cmd=show_vumark_database_details)
vws_web_tools_group.add_command(cmd=upload_vumark_template_to_database)
vws_web_tools_group.add_command(cmd=wait_for_vumark_instance_id)
60 changes: 60 additions & 0 deletions tests/test_create_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,66 @@ def test_delete_model_target_web_api_credentials_cli(
assert result.exit_code == 0


def test_show_model_target_web_api_details_cli(
*,
vws_credentials: VWSCredentials,
logged_in_chrome_driver: WebDriver,
) -> None:
"""Test showing Model Target Web API details via the CLI."""
email_address = vws_credentials.email_address
password = vws_credentials.password
runner = CliRunner()
client_ids: list[str] = []

try:
result = runner.invoke(
cli=vws_web_tools_group,
args=[
"show-model-target-web-api-details",
"--email-address",
email_address,
"--password",
password,
],
catch_exceptions=False,
)
assert result.exit_code == 0
details = yaml.safe_load(stream=result.output)
client_ids.append(details["client_id"])
assert details["client_secret"]
assert details["cad_data_url"]

result = runner.invoke(
cli=vws_web_tools_group,
args=[
"show-model-target-web-api-details",
"--email-address",
email_address,
"--password",
password,
"--env-var-format",
],
catch_exceptions=False,
)
assert result.exit_code == 0
env_vars: dict[str, str] = dict(
line.split(sep="=", maxsplit=1)
for line in result.output.strip().split(sep="\n")
)
client_ids.append(env_vars["MODEL_TARGET_VUFORIA_CLIENT_ID"])
assert env_vars["MODEL_TARGET_VUFORIA_CLIENT_SECRET"]
assert (
env_vars["MODEL_TARGET_VUFORIA_CAD_DATA_URL"]
== (details["cad_data_url"])
)
finally:
for client_id in client_ids:
vws_web_tools.delete_model_target_web_api_client_credentials(
driver=logged_in_chrome_driver,
client_id=client_id,
)


def test_show_license_details_cli(
*,
vws_credentials: VWSCredentials,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_help/test_vws_command_help____.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Commands:
get-vumark-instance-id Get the VuMark instance ID for a...
show-database-details Show the details of a database.
show-license-details Show the details of a license.
show-model-target-web-api-details
Create and show Model Target Web...
show-vumark-database-details Show the details of a VuMark...
upload-vumark-template Upload a VuMark SVG template to...
wait-for-vumark-instance-id Wait for and get the VuMark...
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Usage: vws-web show-model-target-web-api-details [OPTIONS]

Create and show Model Target Web API credentials.

The created OAuth2 client credential is left on the Vuforia account so that it
can be used.

Options:
--email-address TEXT [required]
--password TEXT [required]
--advanced-scopes Also request the advanced Model Target scope. This
requires a Vuforia Enterprise developer account.
--env-var-format
--help Show this message and exit.