2017-02-07 19:18:16 +03:00
|
|
|
# Copyright (c) Microsoft Corporation
|
|
|
|
#
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# MIT License
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
# copy of this software and associated documentation files (the "Software"),
|
|
|
|
# to deal in the Software without restriction, including without limitation
|
|
|
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
# and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
# Software is furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
# DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
# stdlib imports
|
|
|
|
import json
|
|
|
|
import logging
|
2018-04-17 17:47:45 +03:00
|
|
|
import multiprocessing
|
2021-04-12 23:01:48 +03:00
|
|
|
import pathlib
|
2017-02-07 19:18:16 +03:00
|
|
|
# non-stdlib imports
|
|
|
|
import click
|
|
|
|
import ruamel.yaml
|
|
|
|
# blobxfer library imports
|
|
|
|
import blobxfer.api
|
|
|
|
import blobxfer.util
|
|
|
|
# local imports
|
2017-06-01 07:01:37 +03:00
|
|
|
try:
|
2017-08-30 00:47:20 +03:00
|
|
|
import cli.settings as settings
|
2017-06-01 07:01:37 +03:00
|
|
|
except (SystemError, ImportError): # noqa
|
2017-08-30 00:47:20 +03:00
|
|
|
try:
|
|
|
|
from . import settings
|
|
|
|
except (SystemError, ImportError): # noqa
|
|
|
|
# for local testing
|
|
|
|
import settings
|
2017-02-07 19:18:16 +03:00
|
|
|
|
|
|
|
# create logger
|
|
|
|
logger = logging.getLogger('blobxfer')
|
|
|
|
# global defines
|
|
|
|
_CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
|
|
|
|
|
|
|
|
|
|
|
class CliContext(object):
|
|
|
|
"""CliContext class: holds context for CLI commands"""
|
|
|
|
def __init__(self):
|
|
|
|
"""Ctor for CliContext"""
|
2017-09-12 05:14:13 +03:00
|
|
|
self.config = None
|
2017-02-07 19:18:16 +03:00
|
|
|
self.cli_options = {}
|
2017-02-15 01:57:29 +03:00
|
|
|
self.credentials = None
|
|
|
|
self.general_options = None
|
2017-10-05 19:19:57 +03:00
|
|
|
self.show_config = False
|
2017-02-07 19:18:16 +03:00
|
|
|
|
2017-06-02 18:16:46 +03:00
|
|
|
def initialize(self, action):
|
|
|
|
# type: (CliContext, settings.TransferAction) -> None
|
2017-02-07 19:18:16 +03:00
|
|
|
"""Initialize context
|
|
|
|
:param CliContext self: this
|
2017-06-02 18:16:46 +03:00
|
|
|
:param settings.TransferAction action: transfer action
|
2017-02-07 19:18:16 +03:00
|
|
|
"""
|
|
|
|
self._init_config()
|
2017-06-02 18:16:46 +03:00
|
|
|
self.general_options = settings.create_general_options(
|
|
|
|
self.config, action)
|
2017-04-11 00:40:03 +03:00
|
|
|
self.credentials = settings.create_azure_storage_credentials(
|
|
|
|
self.config, self.general_options)
|
2017-02-07 19:18:16 +03:00
|
|
|
|
|
|
|
def _read_yaml_file(self, yaml_file):
|
|
|
|
# type: (CliContext, pathlib.Path) -> None
|
|
|
|
"""Read a yaml file into self.config
|
|
|
|
:param CliContext self: this
|
|
|
|
:param pathlib.Path yaml_file: yaml file to load
|
|
|
|
"""
|
|
|
|
with yaml_file.open('r') as f:
|
|
|
|
if self.config is None:
|
|
|
|
self.config = ruamel.yaml.load(
|
|
|
|
f, Loader=ruamel.yaml.RoundTripLoader)
|
|
|
|
else:
|
|
|
|
self.config = blobxfer.util.merge_dict(
|
2017-06-01 23:55:54 +03:00
|
|
|
ruamel.yaml.load(f, Loader=ruamel.yaml.RoundTripLoader),
|
|
|
|
self.config)
|
2017-02-07 19:18:16 +03:00
|
|
|
|
|
|
|
def _init_config(self):
|
|
|
|
# type: (CliContext) -> None
|
|
|
|
"""Initializes configuration of the context
|
|
|
|
:param CliContext self: this
|
|
|
|
"""
|
|
|
|
# load yaml config file into memory
|
2017-06-01 23:55:54 +03:00
|
|
|
if blobxfer.util.is_not_empty(self.cli_options['yaml_config']):
|
|
|
|
yaml_config = pathlib.Path(self.cli_options['yaml_config'])
|
|
|
|
self._read_yaml_file(yaml_config)
|
2017-10-03 04:09:02 +03:00
|
|
|
if self.config is None:
|
|
|
|
self.config = {}
|
2017-10-13 01:04:20 +03:00
|
|
|
# merge "global" cli options with config
|
|
|
|
settings.merge_global_settings(self.config, self.cli_options)
|
2017-04-08 00:38:57 +03:00
|
|
|
# set log file if specified
|
2017-10-13 17:21:11 +03:00
|
|
|
logfile = self.config['options'].get('log_file', None)
|
|
|
|
blobxfer.util.setup_logger(logger, logfile)
|
|
|
|
# set azure storage logging level
|
2017-10-05 18:08:36 +03:00
|
|
|
azstorage_logger = logging.getLogger('azure.storage')
|
2017-10-13 17:21:11 +03:00
|
|
|
if self.config['options'].get('enable_azure_storage_logger', False):
|
|
|
|
blobxfer.util.setup_logger(azstorage_logger, logfile)
|
|
|
|
azstorage_logger.setLevel(logging.INFO)
|
|
|
|
else:
|
|
|
|
# disable azure storage logging: setting logger level to CRITICAL
|
|
|
|
# effectively disables logging from azure storage
|
|
|
|
azstorage_logger.setLevel(logging.CRITICAL)
|
2018-06-14 22:33:51 +03:00
|
|
|
# set verbose logging
|
|
|
|
if self.config['options'].get('verbose', False):
|
|
|
|
blobxfer.util.set_verbose_logger_handlers()
|
2017-10-13 01:04:20 +03:00
|
|
|
# output mixed config
|
2017-10-05 19:19:57 +03:00
|
|
|
if self.show_config:
|
2017-10-13 01:04:20 +03:00
|
|
|
logger.debug('config: \n{}'.format(
|
|
|
|
json.dumps(self.config, indent=4)))
|
|
|
|
logger.debug('cli config: \n{}'.format(
|
|
|
|
json.dumps(
|
|
|
|
self.cli_options[self.cli_options['_action']],
|
|
|
|
indent=4, sort_keys=True)))
|
2017-10-05 19:19:57 +03:00
|
|
|
del self.show_config
|
2017-02-07 19:18:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
# create a pass decorator for shared context between commands
|
|
|
|
pass_cli_context = click.make_pass_decorator(CliContext, ensure=True)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _access_key_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['access_key'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--storage-account-key',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Storage account access key',
|
|
|
|
envvar='BLOBXFER_STORAGE_ACCOUNT_KEY',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _chunk_size_bytes_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['chunk_size_bytes'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--chunk-size-bytes',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
|
|
|
default=None,
|
|
|
|
help='Block or chunk size in bytes; set to 0 for auto-select '
|
|
|
|
'on upload [0]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-06-01 23:55:54 +03:00
|
|
|
def _config_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['yaml_config'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--config',
|
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-06-01 23:55:54 +03:00
|
|
|
help='YAML configuration file',
|
|
|
|
envvar='BLOBXFER_CONFIG_FILE',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2018-06-14 22:33:51 +03:00
|
|
|
def _connect_timeout_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['connect_timeout'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--connect-timeout',
|
|
|
|
expose_value=False,
|
|
|
|
type=float,
|
|
|
|
default=None,
|
|
|
|
help='Timeout, in seconds, applied to connect operations',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-02-24 01:57:01 +03:00
|
|
|
def _crypto_processes_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['crypto_processes'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--crypto-processes',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-05-25 19:01:57 +03:00
|
|
|
help='Concurrent crypto processes (download only)',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _disk_threads_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['disk_threads'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--disk-threads',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-05-25 19:01:57 +03:00
|
|
|
help='Concurrent disk threads',
|
2017-02-24 01:57:01 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2018-06-15 18:36:46 +03:00
|
|
|
def _dry_run_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['dry_run'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--dry-run',
|
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
|
|
|
default=False,
|
|
|
|
help='Dry run [False]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-10-13 17:21:11 +03:00
|
|
|
def _enable_azure_storage_logger_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['enable_azure_storage_logger'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--enable-azure-storage-logger',
|
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
|
|
|
default=False,
|
|
|
|
help='Enable Azure Storage logger output [False]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _endpoint_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['endpoint'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--endpoint',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Azure Storage endpoint [core.windows.net]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _exclude_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['exclude'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--exclude',
|
|
|
|
expose_value=False,
|
|
|
|
multiple=True,
|
|
|
|
default=None,
|
|
|
|
help='Exclude pattern',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _include_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['include'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--include',
|
|
|
|
expose_value=False,
|
|
|
|
multiple=True,
|
|
|
|
default=None,
|
|
|
|
help='Include pattern',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-04-08 00:38:57 +03:00
|
|
|
def _log_file_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['log_file'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--log-file',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2017-06-02 18:16:46 +03:00
|
|
|
help='Log to file specified; this must be specified for progress '
|
|
|
|
'bar to show',
|
2017-04-08 00:38:57 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-10-26 19:09:20 +03:00
|
|
|
def _max_retries_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['max_retries'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--max-retries',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
|
|
|
default=None,
|
|
|
|
help='Maximum number of retries for a request; negative values are '
|
|
|
|
'unlimited [10]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-02-24 01:57:01 +03:00
|
|
|
def _md5_processes_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['md5_processes'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--md5-processes',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-02-24 01:57:01 +03:00
|
|
|
help='Concurrent MD5 processes',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _mode_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['mode'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--mode',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Transfer mode: auto, append, block, file, page [auto]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _overwrite_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['overwrite'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--overwrite/--no-overwrite',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Overwrite destination if exists. For append blobs, '
|
|
|
|
'--no-overwrite will append to any existing blob. [True]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-02-07 19:18:16 +03:00
|
|
|
def _progress_bar_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['progress_bar'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--progress-bar/--no-progress-bar',
|
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-06-02 18:16:46 +03:00
|
|
|
help='Display progress bar instead of console logs; log file must '
|
|
|
|
'be specified [True]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-10-25 02:52:56 +03:00
|
|
|
def _proxy_host_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['proxy_host'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--proxy-host',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Proxy host in the format of IP:Port',
|
|
|
|
envvar='BLOBXFER_PROXY_HOST',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _proxy_password_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['proxy_password'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--proxy-password',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Proxy password',
|
|
|
|
envvar='BLOBXFER_PROXY_PASSWORD',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _proxy_username_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['proxy_username'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--proxy-username',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Proxy username',
|
|
|
|
envvar='BLOBXFER_PROXY_USERNAME',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _quiet_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['quiet'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'-q', '--quiet',
|
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
|
|
|
default=None,
|
|
|
|
help='Quiet mode',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2018-06-14 22:33:51 +03:00
|
|
|
def _read_timeout_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['read_timeout'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--read-timeout',
|
|
|
|
expose_value=False,
|
|
|
|
type=float,
|
|
|
|
default=None,
|
|
|
|
help='Timeout, in seconds, applied to read operations',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _rename_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['rename'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--rename',
|
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
|
|
|
default=None,
|
|
|
|
help='Rename to specified destination for a single object. '
|
|
|
|
'Automatically enabled with stdin source. [False]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-03-01 00:27:20 +03:00
|
|
|
def _resume_file_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['resume_file'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--resume-file',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Save or use resume file specified',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _sas_option(f):
|
2017-10-05 19:19:57 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['sas'] = value
|
2017-10-05 19:19:57 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--sas',
|
2017-10-05 19:19:57 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
default=None,
|
|
|
|
help='Shared access signature',
|
|
|
|
envvar='BLOBXFER_SAS',
|
2017-10-05 19:19:57 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _show_config_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.show_config = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--show-config',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
is_flag=True,
|
|
|
|
help='Show configuration',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _skip_on_filesize_match_option(f):
|
2017-02-24 01:57:01 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['skip_on_filesize_match'] = value
|
2017-02-24 01:57:01 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--skip-on-filesize-match',
|
2017-02-24 01:57:01 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
is_flag=True,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Skip on equivalent file size [False]',
|
2017-02-24 01:57:01 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _skip_on_lmt_ge_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['skip_on_lmt_ge'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--skip-on-lmt-ge',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Skip on last modified time greater than or equal to [False]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _skip_on_md5_match_option(f):
|
2018-04-16 18:55:20 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['skip_on_md5_match'] = value
|
2018-04-16 18:55:20 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--skip-on-md5-match',
|
2018-04-16 18:55:20 +03:00
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Skip on MD5 match [False]',
|
2018-04-16 18:55:20 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _strip_components_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['strip_components'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
2017-06-01 23:55:54 +03:00
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--strip-components',
|
2017-06-01 23:55:54 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Strip leading file path components: local path for upload, '
|
|
|
|
'remote path for download, or source path for synccopy [0]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _timeout_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['timeout'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
2017-06-01 23:55:54 +03:00
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--timeout',
|
2017-06-01 23:55:54 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
type=float,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='[DEPRECATED] Timeout, in seconds, applied to both connect '
|
|
|
|
'and read operations',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _transfer_threads_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['transfer_threads'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
2017-06-01 23:55:54 +03:00
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--transfer-threads',
|
2017-06-01 23:55:54 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Concurrent transfer threads',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _verbose_option(f):
|
2018-08-07 22:57:03 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['verbose'] = value
|
2018-08-07 22:57:03 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'-v', '--verbose',
|
2018-08-07 22:57:03 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
is_flag=True,
|
2018-08-07 22:57:03 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Verbose output',
|
2018-08-07 22:57:03 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-06-01 23:55:54 +03:00
|
|
|
def common_options(f):
|
|
|
|
f = _verbose_option(f)
|
|
|
|
f = _transfer_threads_option(f)
|
|
|
|
f = _timeout_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _strip_components_option(f)
|
2019-11-01 20:02:44 +03:00
|
|
|
f = _storage_url_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _skip_on_md5_match_option(f)
|
|
|
|
f = _skip_on_lmt_ge_option(f)
|
|
|
|
f = _skip_on_filesize_match_option(f)
|
2017-10-05 19:19:57 +03:00
|
|
|
f = _show_config_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _sas_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _resume_file_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _rename_option(f)
|
2018-06-14 22:33:51 +03:00
|
|
|
f = _read_timeout_option(f)
|
2018-04-16 18:55:20 +03:00
|
|
|
f = _quiet_option(f)
|
2017-10-25 02:52:56 +03:00
|
|
|
f = _proxy_username_option(f)
|
|
|
|
f = _proxy_password_option(f)
|
|
|
|
f = _proxy_host_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _progress_bar_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _overwrite_option(f)
|
|
|
|
f = _mode_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _md5_processes_option(f)
|
2017-10-26 19:09:20 +03:00
|
|
|
f = _max_retries_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _log_file_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _include_option(f)
|
|
|
|
f = _exclude_option(f)
|
|
|
|
f = _endpoint_option(f)
|
2017-10-13 17:21:11 +03:00
|
|
|
f = _enable_azure_storage_logger_option(f)
|
2018-06-15 18:36:46 +03:00
|
|
|
f = _dry_run_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _disk_threads_option(f)
|
2019-07-12 19:58:45 +03:00
|
|
|
f = _delete_option(f)
|
|
|
|
f = _delete_only_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _crypto_processes_option(f)
|
2018-06-14 22:33:51 +03:00
|
|
|
f = _connect_timeout_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _config_option(f)
|
2019-07-22 19:49:44 +03:00
|
|
|
f = _chunk_size_bytes_option(f)
|
|
|
|
f = _access_key_option(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
def _file_attributes(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['file_attributes'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
2017-05-23 06:26:52 +03:00
|
|
|
'--file-attributes/--no-file-attributes',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-02-07 19:18:16 +03:00
|
|
|
help='Store or restore file attributes [False]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _file_md5_option(f):
|
2019-02-26 21:43:55 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['file_md5'] = value
|
2019-02-26 21:43:55 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--file-md5/--no-file-md5',
|
2019-02-26 21:43:55 +03:00
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Compute file MD5 [False]',
|
2019-04-15 19:46:22 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _local_resource_option(f):
|
2019-04-15 19:46:22 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['local_resource'] = value
|
2019-04-15 19:46:22 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--local-path',
|
2019-04-15 19:46:22 +03:00
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Local path; use - for stdin',
|
2019-02-26 21:43:55 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _recursive_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['recursive'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--recursive/--no-recursive',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Recursive [True]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _remote_path_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['remote_path'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--remote-path',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Remote path on Azure Storage',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _rsa_private_key_option(f):
|
2019-01-14 22:15:06 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['rsa_private_key'] = value
|
2019-01-14 22:15:06 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--rsa-private-key',
|
2019-01-14 22:15:06 +03:00
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='RSA private key PEM file',
|
|
|
|
envvar='BLOBXFER_RSA_PRIVATE_KEY',
|
2019-01-14 22:15:06 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _rsa_private_key_passphrase_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['rsa_private_key_passphrase'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--rsa-private-key-passphrase',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='RSA private key passphrase',
|
|
|
|
envvar='BLOBXFER_RSA_PRIVATE_KEY_PASSPHRASE',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _storage_account_option(f):
|
2017-05-17 01:05:58 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['storage_account'] = value
|
2017-05-17 01:05:58 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--storage-account',
|
2017-05-17 01:05:58 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Storage account name',
|
|
|
|
envvar='BLOBXFER_STORAGE_ACCOUNT',
|
2017-05-17 01:05:58 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _storage_url_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['storage_url'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--storage-url',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Azure Storage URL as source or destination (can include SAS)',
|
|
|
|
envvar='BLOBXFER_STORAGE_URL',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def upload_download_options(f):
|
|
|
|
f = _storage_account_option(f)
|
|
|
|
f = _rsa_private_key_passphrase_option(f)
|
|
|
|
f = _rsa_private_key_option(f)
|
|
|
|
f = _remote_path_option(f)
|
|
|
|
f = _recursive_option(f)
|
|
|
|
f = _local_resource_option(f)
|
|
|
|
f = _file_md5_option(f)
|
|
|
|
f = _file_attributes(f)
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
def _access_tier_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['access_tier'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--access-tier',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Access tier to apply to target (block blob only)',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _delete_option(f):
|
2017-05-17 01:05:58 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['delete'] = value
|
2017-05-17 01:05:58 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--delete',
|
2017-05-17 01:05:58 +03:00
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Delete extraneous files on target [False]',
|
2017-05-17 01:05:58 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _delete_only_option(f):
|
2018-08-08 02:48:42 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['delete_only'] = value
|
2018-08-08 02:48:42 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--delete-only',
|
2018-08-08 02:48:42 +03:00
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Do not transfer files, only perform deletion of extraneous '
|
|
|
|
'files on target [False]',
|
2018-08-08 02:48:42 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _distribution_mode(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['distribution_mode'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--distribution-mode',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Vectored IO distribution mode: disabled, replica, '
|
|
|
|
'stripe [disabled]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _file_cache_control_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['file_cache_control'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--file-cache-control',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Store CacheControl value',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _file_content_type_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['file_content_type'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--file-content-type',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Store ContentType value',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _max_single_object_concurrency(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['max_single_object_concurrency'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--max-single-object-concurrency',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Maximum single object concurrency [8]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _one_shot_bytes_option(f):
|
2019-04-30 00:54:27 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['one_shot_bytes'] = value
|
2019-04-30 00:54:27 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--one-shot-bytes',
|
2019-04-30 00:54:27 +03:00
|
|
|
expose_value=False,
|
2019-07-22 19:49:44 +03:00
|
|
|
type=int,
|
2019-04-30 00:54:27 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='File sizes less than or equal to the specified byte threshold '
|
|
|
|
'will be uploaded as one-shot for block blobs; the valid range that '
|
|
|
|
'can be specified is 0 to 256MiB [0]',
|
2019-04-30 00:54:27 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _restore_file_lmt_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['restore_file_lmt'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--restore-file-lmt',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
|
|
|
is_flag=True,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Set last modified time equal to the last modified property '
|
|
|
|
'in Azure Storage [false]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _rsa_public_key_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['rsa_public_key'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--rsa-public-key',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='RSA public key PEM file',
|
|
|
|
envvar='BLOBXFER_RSA_PUBLIC_KEY',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-07-22 19:49:44 +03:00
|
|
|
def _server_side_copy_option(f):
|
2017-02-07 19:18:16 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2019-07-22 19:49:44 +03:00
|
|
|
clictx.cli_options['server_side_copy'] = value
|
2017-02-07 19:18:16 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2019-07-22 19:49:44 +03:00
|
|
|
'--server-side-copy/--no-server-side-copy',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2019-07-22 19:49:44 +03:00
|
|
|
help='Copy source data within Azure Storage [True]',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-09-01 05:25:14 +03:00
|
|
|
def _stdin_as_page_blob_size_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['stdin_as_page_blob_size'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--stdin-as-page-blob-size',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
|
|
|
default=None,
|
|
|
|
help='Size of page blob with input from stdin [0]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-05-20 01:01:49 +03:00
|
|
|
def _stripe_chunk_size_bytes_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['stripe_chunk_size_bytes'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--stripe-chunk-size-bytes',
|
|
|
|
expose_value=False,
|
|
|
|
type=int,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-05-20 01:01:49 +03:00
|
|
|
help='Vectored IO stripe width in bytes [1073741824]',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-02-07 19:18:16 +03:00
|
|
|
def _sync_copy_dest_access_key_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['sync_copy_dest_access_key'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
2017-06-01 23:55:54 +03:00
|
|
|
'--sync-copy-dest-storage-account-key',
|
2017-02-07 19:18:16 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-02-07 19:18:16 +03:00
|
|
|
help='Storage account access key for synccopy destination',
|
2017-06-01 23:55:54 +03:00
|
|
|
envvar='BLOBXFER_SYNC_COPY_DEST_STORAGE_ACCOUNT_KEY',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-07-10 18:46:26 +03:00
|
|
|
def _sync_copy_dest_mode_option(f):
|
2017-06-01 23:55:54 +03:00
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
2017-07-10 18:46:26 +03:00
|
|
|
clictx.cli_options['sync_copy_dest_mode'] = value
|
2017-06-01 23:55:54 +03:00
|
|
|
return value
|
|
|
|
return click.option(
|
2017-07-10 18:46:26 +03:00
|
|
|
'--sync-copy-dest-mode',
|
2017-06-01 23:55:54 +03:00
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-07-10 18:46:26 +03:00
|
|
|
help='Mode for synccopy destination',
|
2017-06-01 23:55:54 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _sync_copy_dest_remote_path_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['sync_copy_dest_remote_path'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--sync-copy-dest-remote-path',
|
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-06-01 23:55:54 +03:00
|
|
|
help='Remote path on Azure Storage for synccopy destination',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
|
|
|
def _sync_copy_dest_sas_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['sync_copy_dest_sas'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--sync-copy-dest-sas',
|
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-02-07 19:18:16 +03:00
|
|
|
help='Shared access signature for synccopy destination',
|
2017-06-01 23:55:54 +03:00
|
|
|
envvar='BLOBXFER_SYNC_COPY_DEST_SAS',
|
2017-02-07 19:18:16 +03:00
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-07-10 18:46:26 +03:00
|
|
|
def _sync_copy_dest_storage_account_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['sync_copy_dest_storage_account'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--sync-copy-dest-storage-account',
|
|
|
|
expose_value=False,
|
2017-08-15 19:46:10 +03:00
|
|
|
default=None,
|
2017-07-10 18:46:26 +03:00
|
|
|
help='Storage account name for synccopy destination',
|
|
|
|
envvar='BLOBXFER_SYNC_COPY_DEST_STORAGE_ACCOUNT',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2018-08-07 22:57:03 +03:00
|
|
|
def _sync_copy_dest_storage_url_option(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['sync_copy_dest_storage_url'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--sync-copy-dest-storage-url',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Azure Storage URL as destination (can include SAS)',
|
|
|
|
envvar='BLOBXFER_SYNC_COPY_DEST_STORAGE_URL',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2019-05-17 20:08:41 +03:00
|
|
|
def _sync_copy_source_url(f):
|
|
|
|
def callback(ctx, param, value):
|
|
|
|
clictx = ctx.ensure_object(CliContext)
|
|
|
|
clictx.cli_options['sync_copy_source_url'] = value
|
|
|
|
return value
|
|
|
|
return click.option(
|
|
|
|
'--sync-copy-source-url',
|
|
|
|
expose_value=False,
|
|
|
|
default=None,
|
|
|
|
help='Remote URL for synccopy source',
|
|
|
|
callback=callback)(f)
|
|
|
|
|
|
|
|
|
2017-02-07 19:18:16 +03:00
|
|
|
def upload_options(f):
|
2017-05-17 01:05:58 +03:00
|
|
|
f = _stripe_chunk_size_bytes_option(f)
|
2017-09-01 05:25:14 +03:00
|
|
|
f = _stdin_as_page_blob_size_option(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
f = _rsa_public_key_option(f)
|
2017-05-20 01:01:49 +03:00
|
|
|
f = _one_shot_bytes_option(f)
|
2019-04-15 19:46:22 +03:00
|
|
|
f = _file_content_type_option(f)
|
2019-02-26 21:43:55 +03:00
|
|
|
f = _file_cache_control_option(f)
|
2017-05-20 01:01:49 +03:00
|
|
|
f = _distribution_mode(f)
|
2018-01-18 18:51:32 +03:00
|
|
|
f = _access_tier_option(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
def download_options(f):
|
2018-08-08 02:48:42 +03:00
|
|
|
f = _restore_file_lmt_option(f)
|
2019-01-14 22:15:06 +03:00
|
|
|
f = _max_single_object_concurrency(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
def sync_copy_options(f):
|
2019-05-17 20:08:41 +03:00
|
|
|
f = _sync_copy_source_url(f)
|
2018-08-07 22:57:03 +03:00
|
|
|
f = _sync_copy_dest_storage_url_option(f)
|
2017-06-02 18:16:46 +03:00
|
|
|
f = _sync_copy_dest_storage_account_option(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
f = _sync_copy_dest_sas_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _sync_copy_dest_remote_path_option(f)
|
2017-07-10 18:46:26 +03:00
|
|
|
f = _sync_copy_dest_mode_option(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
f = _sync_copy_dest_access_key_option(f)
|
2017-06-02 18:16:46 +03:00
|
|
|
f = _storage_account_option(f)
|
2019-04-30 00:54:27 +03:00
|
|
|
f = _server_side_copy_option(f)
|
2017-06-01 23:55:54 +03:00
|
|
|
f = _remote_path_option(f)
|
2018-01-18 18:51:32 +03:00
|
|
|
f = _access_tier_option(f)
|
2017-02-07 19:18:16 +03:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
@click.group(context_settings=_CONTEXT_SETTINGS)
|
|
|
|
@click.version_option(version=blobxfer.__version__)
|
|
|
|
@click.pass_context
|
|
|
|
def cli(ctx):
|
2017-06-09 05:47:42 +03:00
|
|
|
"""blobxfer: Azure Storage transfer tool"""
|
2017-02-07 19:18:16 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command('download')
|
|
|
|
@download_options
|
2019-07-22 19:49:44 +03:00
|
|
|
@upload_download_options
|
2017-02-07 19:18:16 +03:00
|
|
|
@common_options
|
|
|
|
@pass_cli_context
|
2017-06-01 23:55:54 +03:00
|
|
|
def download(ctx):
|
2017-02-07 19:18:16 +03:00
|
|
|
"""Download blobs or files from Azure Storage"""
|
2017-06-01 23:55:54 +03:00
|
|
|
settings.add_cli_options(ctx.cli_options, settings.TransferAction.Download)
|
2017-06-02 18:16:46 +03:00
|
|
|
ctx.initialize(settings.TransferAction.Download)
|
2017-08-15 19:46:10 +03:00
|
|
|
specs = settings.create_download_specifications(
|
|
|
|
ctx.cli_options, ctx.config)
|
|
|
|
del ctx.cli_options
|
2017-02-15 01:57:29 +03:00
|
|
|
for spec in specs:
|
2017-02-22 08:20:16 +03:00
|
|
|
blobxfer.api.Downloader(
|
|
|
|
ctx.general_options, ctx.credentials, spec
|
|
|
|
).start()
|
2017-02-07 19:18:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command('synccopy')
|
|
|
|
@sync_copy_options
|
|
|
|
@common_options
|
|
|
|
@pass_cli_context
|
2017-06-01 23:55:54 +03:00
|
|
|
def synccopy(ctx):
|
2017-08-29 19:19:10 +03:00
|
|
|
"""Synchronously copy blobs or files between Azure Storage accounts"""
|
2017-06-01 23:55:54 +03:00
|
|
|
settings.add_cli_options(ctx.cli_options, settings.TransferAction.Synccopy)
|
2017-06-02 18:16:46 +03:00
|
|
|
ctx.initialize(settings.TransferAction.Synccopy)
|
2017-08-15 19:46:10 +03:00
|
|
|
specs = settings.create_synccopy_specifications(
|
|
|
|
ctx.cli_options, ctx.config)
|
|
|
|
del ctx.cli_options
|
2017-06-09 05:47:42 +03:00
|
|
|
for spec in specs:
|
|
|
|
blobxfer.api.SyncCopy(
|
|
|
|
ctx.general_options, ctx.credentials, spec
|
|
|
|
).start()
|
2017-02-07 19:18:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command('upload')
|
|
|
|
@upload_options
|
2019-07-22 19:49:44 +03:00
|
|
|
@upload_download_options
|
2017-02-07 19:18:16 +03:00
|
|
|
@common_options
|
|
|
|
@pass_cli_context
|
2017-06-01 23:55:54 +03:00
|
|
|
def upload(ctx):
|
2017-02-07 19:18:16 +03:00
|
|
|
"""Upload files to Azure Storage"""
|
2017-06-01 23:55:54 +03:00
|
|
|
settings.add_cli_options(ctx.cli_options, settings.TransferAction.Upload)
|
2017-06-02 18:16:46 +03:00
|
|
|
ctx.initialize(settings.TransferAction.Upload)
|
2017-08-15 19:46:10 +03:00
|
|
|
specs = settings.create_upload_specifications(
|
|
|
|
ctx.cli_options, ctx.config)
|
|
|
|
del ctx.cli_options
|
2017-05-30 22:59:39 +03:00
|
|
|
for spec in specs:
|
|
|
|
blobxfer.api.Uploader(
|
|
|
|
ctx.general_options, ctx.credentials, spec
|
|
|
|
).start()
|
|
|
|
|
|
|
|
|
2017-02-07 19:18:16 +03:00
|
|
|
if __name__ == '__main__':
|
2018-04-17 17:47:45 +03:00
|
|
|
multiprocessing.freeze_support()
|
2017-02-07 19:18:16 +03:00
|
|
|
cli()
|