Skip to content

Commit fd15341

Browse files
authored
Merge pull request #540 from mapswipe/change-api-key
add command to update tileserver api key for a project
2 parents 46d598d + 74ac7e8 commit fd15341

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

mapswipe_workers/mapswipe_workers/firebase_to_postgres/update_data.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,14 @@ def set_contributor_count_in_firebase(project_id: str):
303303
logger.info(
304304
f"set contributorCount attribute for project {project_id}: {contributor_count}"
305305
)
306+
307+
308+
def set_tileserver_api_key(project_id: str, api_key: str) -> None:
309+
"""Set the tileserver api key value in Firebase."""
310+
311+
fb_db = auth.firebaseDB()
312+
project_progress_ref = fb_db.reference(
313+
f"v2/projects/{project_id}/tileServer/apiKey"
314+
)
315+
project_progress_ref.set(api_key)
316+
logger.info(f"set tileServer/apiKey attribute for project: {project_id}")

mapswipe_workers/mapswipe_workers/mapswipe_workers.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ast
44
import time
5+
from typing import List, Optional
56

67
import click
78
import schedule as sched
@@ -364,7 +365,7 @@ def run_archive_project(project_id, project_ids):
364365
@click.option(
365366
"--project-id",
366367
"-i",
367-
help=("Delete project with giving project id"),
368+
help="Delete project with given project id.",
368369
type=str,
369370
)
370371
@click.option(
@@ -406,6 +407,38 @@ def run_delete_project(project_id, project_ids):
406407
click.echo("Invalid input")
407408

408409

410+
@cli.command("set-tileserver-api-key")
411+
@click.option(
412+
"--project-id",
413+
"-i",
414+
help="Set api key for project with given project id",
415+
type=str,
416+
)
417+
@click.option(
418+
"--project-ids",
419+
cls=PythonLiteralOption,
420+
default="[]",
421+
help=(
422+
"Set api key for multiple projects. "
423+
"Provide project id strings as a list: "
424+
"""'["project_a", "project_b"]'"""
425+
),
426+
)
427+
@click.option("--api-key", help="the new api key to use", type=str, required=True)
428+
def run_set_tileserver_api_key(
429+
project_id: str, project_ids: Optional[List[str]], api_key: str
430+
) -> None:
431+
"""Change the imagery API key for a project in Firebase."""
432+
if not project_ids and not project_id:
433+
click.echo("Missing argument")
434+
return None
435+
elif not project_ids:
436+
project_ids = [project_id]
437+
438+
for project_id in project_ids:
439+
update_data.set_tileserver_api_key(project_id, api_key)
440+
441+
409442
@cli.command("run")
410443
@click.option(
411444
"--analysis_type",

0 commit comments

Comments
 (0)