Skip to content

Commit

Permalink
redid cloud datasorte bucket copy branch (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grashalmbeisser authored Nov 8, 2024
1 parent e7346b5 commit db3de2d
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions src/viur_cli/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,53 @@ def cloud():
"""This method defines a command group for working with cloud resources."""


@cloud.command(context_settings={"ignore_unknown_options": True})
@click.argument("action", type=click.Choice(["bucket2bucket", "bucket2local", "local2bucket"]))
@click.argument("profile", default="default")
def copy(action, profile):
if action == "bucket2bucket":
if user_check_login():
storage_copy()

if action == "bucket2local":
if user_check_login():
datastore_import(profile)

if action == "local2bucket":
if user_check_login():
datastore_export(profile)


def user_check_login():
return click.confirm("Are you logged in with your gcloud admin account?", default=False, show_default=True)


def storage_copy():
# https://console.cloud.google.com/transfer/jobs
source = click.prompt('Source bucketname')
target = click.prompt('Target bucketname')
if not click.confirm(text=f"Copy from {source} to {target}", default=True):
print("Abort ...")
return 0
print(f"gsutil -m cp -r gs://{source}/ gs://{target}/")
os.system(f"gsutil -m cp -r gs://{source} gs://{target}")


def datastore_import(profile):
conf = config.get_profile(profile)
target = click.prompt('path to overall_export_metadata')
os.system(f"gcloud datastore import gs://{target} --project={conf['application_name']}")


def datastore_export(profile):
conf = config.get_profile(profile)
target = click.prompt('bucketname')
timestamp = f'{datetime.now().strftime("%Y%m%d-%H%M%S")}-manual'
format = "default"
os.system(
f"gcloud datastore export gs://{target}/{timestamp}-{format} --format={format} --project={conf['application_name']} ")


@cloud.command(context_settings={"ignore_unknown_options": True})
@click.argument("action", type=click.Choice(["backup"]))
def enable(action):
Expand Down Expand Up @@ -635,7 +682,6 @@ def deploy(action, profile, name, ext, yes, skip_checks: bool, additional_args):
f'gcloud app deploy --project={conf["application_name"]} {" ".join(additional_args)} {yaml_file} {"-q" if yes else ""}')



def build_deploy_command(name, conf):
"""
Expand Down Expand Up @@ -668,7 +714,6 @@ def build_deploy_command(name, conf):
echo_fatal(f"The cloudfunction {name} was not found your project.json\n "
f"You can create a cloudfunction entry by calling 'viur cloud create function'")


command = (
f"gcloud functions deploy "
f"{name} "
Expand Down Expand Up @@ -717,10 +762,10 @@ def create(profile, action, gen, source, name, entrypoint, env_vars_file, memory
function_dict = conf["gcloud"]["functions"].get(function_name, {})

function_dict["gen"] = function_dict.get("gen",
gen if gen else click.prompt(
"Please enter your cloud function generation",
default="2")
)
gen if gen else click.prompt(
"Please enter your cloud function generation",
default="2")
)

function_dict["entry-point"] = function_dict.get("entry-point",
entrypoint if entrypoint else click.prompt(
Expand Down

0 comments on commit db3de2d

Please sign in to comment.