Skip to content

Conversation

@tommyg-cld
Copy link
Contributor

Brief Summary of Changes

What does this PR address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are tests included?

  • Yes
  • No

Reviewer, please note:

  • Updates made to sync module to accommodate this new module as well changes to functions on api_utils which is used by other modules so need to pay extra attention here.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all the tests pass.

if verbose:
print_json(result)
uploaded[file_path] = {"path": asset_source(result), "display_path": disp_path}
if "async" not in options:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good catch!

I would change line 127 to:

        if "batch_id" in result:
            disp_str = f"asynchnously with batch_id: {result['batch_id']}"
        else:
            disp_str = f"as {result['public_id']}" if not disp_path \
                else f"as {disp_path} with public_id: {result['public_id']}"

then you can remove this line (if "async" not in options:)

and in
def asset_source(asset_details):

change to

  base_name = asset_details.get('public_id', '')

    if not base_name:
        return base_name

Copy link
Contributor Author

@tommyg-cld tommyg-cld Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done.

I had to also update the last line to asset_details.get('format', '') as non-raw files still get the public_id as we specify them so this will prevent no format error as the response won't contain the format

Finally, I updated the display message to say it's processing when uploading asynchronously as well.

You need to specify the target cloud via `-t` or `-T` (not both)
e.g. cld clone -t cloudinary://<api_key>:<api_secret>@<cloudname> -f tags,context -O
""")
@option("-T", "--target_saved",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can combine -Tand -t into one. it's easy to check if it's a saved config, or a cloudinary url or not both.

help="Tell the CLI the target environemnt to run the command on by specifying a saved configuration - see `config` command.")
@option("-t", "--target",
help="Tell the CLI the target environemnt to run the command on by specifying an environment variable.")
@option("-A", "--auto_paginate", is_flag=True, default=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

@option("-F", "--force", is_flag=True,
help="Skip confirmation.")
@option("-O", "--overwrite", is_flag=True, default=False,
help="Skip confirmation.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc string seems to be invalid

print_help_and_exit()

base_cloudname_url = os.environ.get('CLOUDINARY_URL')
base_cloudname = cloudinary.config().cloud_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename base_cloudname to source_cloud_name

logger.info("Target environment cannot be the "
"same as source environment.")
return True
refresh_config(base_cloudname_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of loading target, and then resetting, you can just create a new instance of cloudinary.Config() class and use it.

'secure_url', 'display_name'])
search.max_results(DEFAULT_MAX_RESULTS)
res = execute_single_request(search, fields_to_keep="")
if auto_paginate:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto paginate looks redundant

Copy link
Collaborator

@carlevison carlevison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions and some typo fixes.

Cloning restricted assets is also not supported currently.
Format: cld clone -T <target_environment> <command options>
`<target_environment>` can be a CLOUDINARY_URL or a saved config (see `config` command)
e.g. cld clone -T cloudinary://<api_key>:<api_secret>@<cloudname> -f tags,context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the -f be -fi? It's related to the tag,context fields, right?

target_config = get_cloudinary_config(target)
if not target_config:
logger.error("The specified config does not exist or the CLOUDINARY_URL scheme provided is invalid"
" (expecting to start with 'cloudinary://').")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this allow for a saved config?

help="Specify whether to overwrite existing assets.")
@option("-w", "--concurrent_workers", type=int, default=30,
help="Specify the number of concurrent network threads.")
@option("-fi", "--fields", multiple=True,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to show an example, or state the valid options.

Clone assets from one product environment to another with/without tags and/or context (structured metadata is not currently supported).
Source will be your `CLOUDINARY_URL` environemnt variable but you also can specify a different source using `-c/-C` option.
Cloning restricted assets is also not supported currently.
Format: cld clone -T <target_environment> <command options>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the -T really necessary? You're always going to have to specify a target environment. If you look at the sync command, for example, local_folder and cloudinary_folder are mandatory (no option letter).

help="Tell the CLI the target environemnt to run the command on.")
@option("-f", "--force", is_flag=True,
help="Skip confirmation.")
@option("-o", "--overwrite", is_flag=True, default=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't -o conflict with the way you specify optional parameters?

tommyg-cld and others added 5 commits January 16, 2025 14:12
Co-authored-by: carlevison <54800761+carlevison@users.noreply.github.com>
Co-authored-by: carlevison <54800761+carlevison@users.noreply.github.com>
Co-authored-by: carlevison <54800761+carlevison@users.noreply.github.com>
Co-authored-by: carlevison <54800761+carlevison@users.noreply.github.com>
@const-cloudinary const-cloudinary merged commit cf3e0f2 into master Jan 20, 2025
12 checks passed
@const-cloudinary const-cloudinary deleted the feature/add-new-copy-module branch January 20, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants