Skip to content

Commit

Permalink
Merge pull request #540 from mapswipe/change-api-key
Browse files Browse the repository at this point in the history
add command to update tileserver api key for a project
  • Loading branch information
Hagellach37 committed Jun 8, 2022
2 parents 46d598d + 74ac7e8 commit fd15341
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,14 @@ def set_contributor_count_in_firebase(project_id: str):
logger.info(
f"set contributorCount attribute for project {project_id}: {contributor_count}"
)


def set_tileserver_api_key(project_id: str, api_key: str) -> None:
"""Set the tileserver api key value in Firebase."""

fb_db = auth.firebaseDB()
project_progress_ref = fb_db.reference(
f"v2/projects/{project_id}/tileServer/apiKey"
)
project_progress_ref.set(api_key)
logger.info(f"set tileServer/apiKey attribute for project: {project_id}")
35 changes: 34 additions & 1 deletion mapswipe_workers/mapswipe_workers/mapswipe_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ast
import time
from typing import List, Optional

import click
import schedule as sched
Expand Down Expand Up @@ -364,7 +365,7 @@ def run_archive_project(project_id, project_ids):
@click.option(
"--project-id",
"-i",
help=("Delete project with giving project id"),
help="Delete project with given project id.",
type=str,
)
@click.option(
Expand Down Expand Up @@ -406,6 +407,38 @@ def run_delete_project(project_id, project_ids):
click.echo("Invalid input")


@cli.command("set-tileserver-api-key")
@click.option(
"--project-id",
"-i",
help="Set api key for project with given project id",
type=str,
)
@click.option(
"--project-ids",
cls=PythonLiteralOption,
default="[]",
help=(
"Set api key for multiple projects. "
"Provide project id strings as a list: "
"""'["project_a", "project_b"]'"""
),
)
@click.option("--api-key", help="the new api key to use", type=str, required=True)
def run_set_tileserver_api_key(
project_id: str, project_ids: Optional[List[str]], api_key: str
) -> None:
"""Change the imagery API key for a project in Firebase."""
if not project_ids and not project_id:
click.echo("Missing argument")
return None
elif not project_ids:
project_ids = [project_id]

for project_id in project_ids:
update_data.set_tileserver_api_key(project_id, api_key)


@cli.command("run")
@click.option(
"--analysis_type",
Expand Down

0 comments on commit fd15341

Please sign in to comment.