Skip to content

Commit fd761b4

Browse files
Merge pull request #1526 from VWS-Python/adamtheturtle/vws-web-tools-issue-1483
Add a show-model-target-web-api-details command
2 parents d9f0d5f + 778a627 commit fd761b4

5 files changed

Lines changed: 135 additions & 0 deletions

File tree

newsfragments/1483.change.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add a ``show-model-target-web-api-details`` command, which creates and
2+
shows Model Target Web API credentials, in YAML or in
3+
``--env-var-format``.

src/vws_web_tools/__init__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,61 @@ def delete_model_target_web_api_credentials(
19251925
driver.quit()
19261926

19271927

1928+
@click.command(name="show-model-target-web-api-details")
1929+
@click.option("--email-address", envvar="VWS_EMAIL_ADDRESS", required=True)
1930+
@click.option("--password", envvar="VWS_PASSWORD", required=True)
1931+
@click.option(
1932+
"--advanced-scopes",
1933+
is_flag=True,
1934+
help=(
1935+
"Also request the advanced Model Target scope. "
1936+
"This requires a Vuforia Enterprise developer account."
1937+
),
1938+
)
1939+
@click.option("--env-var-format", is_flag=True)
1940+
@beartype
1941+
def show_model_target_web_api_details(
1942+
*,
1943+
email_address: str,
1944+
password: str,
1945+
advanced_scopes: bool,
1946+
env_var_format: bool,
1947+
) -> None:
1948+
"""Create and show Model Target Web API credentials.
1949+
1950+
The created OAuth2 client credential is left on the Vuforia
1951+
account so that it can be used.
1952+
"""
1953+
scopes = (
1954+
MODEL_TARGET_WEB_API_ADVANCED_SCOPES
1955+
if advanced_scopes
1956+
else MODEL_TARGET_WEB_API_STANDARD_SCOPES
1957+
)
1958+
driver = create_chrome_driver()
1959+
try:
1960+
log_in(
1961+
driver=driver,
1962+
email_address=email_address,
1963+
password=password,
1964+
)
1965+
details = get_model_target_web_api_details(
1966+
driver=driver,
1967+
scopes=scopes,
1968+
)
1969+
finally:
1970+
driver.quit()
1971+
if env_var_format:
1972+
env_var_format_details = {
1973+
"MODEL_TARGET_VUFORIA_CLIENT_ID": details["client_id"],
1974+
"MODEL_TARGET_VUFORIA_CLIENT_SECRET": details["client_secret"],
1975+
"MODEL_TARGET_VUFORIA_CAD_DATA_URL": details["cad_data_url"],
1976+
}
1977+
for key, value in env_var_format_details.items():
1978+
click.echo(message=f"{key}={value}")
1979+
else:
1980+
click.echo(message=yaml.dump(data=details), nl=False)
1981+
1982+
19281983
@click.command()
19291984
@click.option("--license-name", required=True)
19301985
@click.option("--email-address", envvar="VWS_EMAIL_ADDRESS", required=True)
@@ -1971,6 +2026,7 @@ def show_license_details(
19712026
vws_web_tools_group.add_command(cmd=get_vumark_instance_id)
19722027
vws_web_tools_group.add_command(cmd=show_database_details)
19732028
vws_web_tools_group.add_command(cmd=show_license_details)
2029+
vws_web_tools_group.add_command(cmd=show_model_target_web_api_details)
19742030
vws_web_tools_group.add_command(cmd=show_vumark_database_details)
19752031
vws_web_tools_group.add_command(cmd=upload_vumark_template_to_database)
19762032
vws_web_tools_group.add_command(cmd=wait_for_vumark_instance_id)

tests/test_create_database.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,66 @@ def test_delete_model_target_web_api_credentials_cli(
570570
assert result.exit_code == 0
571571

572572

573+
def test_show_model_target_web_api_details_cli(
574+
*,
575+
vws_credentials: VWSCredentials,
576+
logged_in_chrome_driver: WebDriver,
577+
) -> None:
578+
"""Test showing Model Target Web API details via the CLI."""
579+
email_address = vws_credentials.email_address
580+
password = vws_credentials.password
581+
runner = CliRunner()
582+
client_ids: list[str] = []
583+
584+
try:
585+
result = runner.invoke(
586+
cli=vws_web_tools_group,
587+
args=[
588+
"show-model-target-web-api-details",
589+
"--email-address",
590+
email_address,
591+
"--password",
592+
password,
593+
],
594+
catch_exceptions=False,
595+
)
596+
assert result.exit_code == 0
597+
details = yaml.safe_load(stream=result.output)
598+
client_ids.append(details["client_id"])
599+
assert details["client_secret"]
600+
assert details["cad_data_url"]
601+
602+
result = runner.invoke(
603+
cli=vws_web_tools_group,
604+
args=[
605+
"show-model-target-web-api-details",
606+
"--email-address",
607+
email_address,
608+
"--password",
609+
password,
610+
"--env-var-format",
611+
],
612+
catch_exceptions=False,
613+
)
614+
assert result.exit_code == 0
615+
env_vars: dict[str, str] = dict(
616+
line.split(sep="=", maxsplit=1)
617+
for line in result.output.strip().split(sep="\n")
618+
)
619+
client_ids.append(env_vars["MODEL_TARGET_VUFORIA_CLIENT_ID"])
620+
assert env_vars["MODEL_TARGET_VUFORIA_CLIENT_SECRET"]
621+
assert (
622+
env_vars["MODEL_TARGET_VUFORIA_CAD_DATA_URL"]
623+
== (details["cad_data_url"])
624+
)
625+
finally:
626+
for client_id in client_ids:
627+
vws_web_tools.delete_model_target_web_api_client_credentials(
628+
driver=logged_in_chrome_driver,
629+
client_id=client_id,
630+
)
631+
632+
573633
def test_show_license_details_cli(
574634
*,
575635
vws_credentials: VWSCredentials,

tests/test_help/test_vws_command_help____.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Commands:
1515
get-vumark-instance-id Get the VuMark instance ID for a...
1616
show-database-details Show the details of a database.
1717
show-license-details Show the details of a license.
18+
show-model-target-web-api-details
19+
Create and show Model Target Web...
1820
show-vumark-database-details Show the details of a VuMark...
1921
upload-vumark-template Upload a VuMark SVG template to...
2022
wait-for-vumark-instance-id Wait for and get the VuMark...
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Usage: vws-web show-model-target-web-api-details [OPTIONS]
2+
3+
Create and show Model Target Web API credentials.
4+
5+
The created OAuth2 client credential is left on the Vuforia account so that it
6+
can be used.
7+
8+
Options:
9+
--email-address TEXT [required]
10+
--password TEXT [required]
11+
--advanced-scopes Also request the advanced Model Target scope. This
12+
requires a Vuforia Enterprise developer account.
13+
--env-var-format
14+
--help Show this message and exit.

0 commit comments

Comments
 (0)