@@ -676,7 +676,7 @@ def _update_progress(current, total):
676676 del namespace .no_progress
677677
678678
679- def process_blob_download_batch_parameters (namespace , cmd ):
679+ def process_blob_download_batch_parameters (cmd , namespace ):
680680 """Process the parameters for storage blob download command"""
681681 import os
682682
@@ -685,65 +685,22 @@ def process_blob_download_batch_parameters(namespace, cmd):
685685 raise ValueError ('incorrect usage: destination must be an existing directory' )
686686
687687 # 2. try to extract account name and container name from source string
688- process_blob_batch_source_parameters (cmd , namespace )
688+ _process_blob_batch_container_parameters (cmd , namespace )
689689
690-
691- def process_blob_batch_source_parameters (cmd , namespace ):
692- """Process the parameters for storage blob download command"""
693-
694- # try to extract account name and container name from source string
695- from .storage_url_helpers import StorageResourceIdentifier
696- identifier = StorageResourceIdentifier (cmd .cli_ctx .cloud , namespace .source )
697-
698- if not identifier .is_url ():
699- namespace .source_container_name = namespace .source
700- elif identifier .blob :
701- raise ValueError ('incorrect usage: source should be either container URL or name' )
702- else :
703- namespace .source_container_name = identifier .container
704- if namespace .account_name is None :
705- namespace .account_name = identifier .account_name
690+ # 3. Call validators
691+ add_progress_callback (cmd , namespace )
706692
707693
708694def process_blob_upload_batch_parameters (cmd , namespace ):
709695 """Process the source and destination of storage blob upload command"""
710696 import os
711697
712698 # 1. quick check
713- if not os .path .exists (namespace .source ):
714- raise ValueError ('incorrect usage: source {} does not exist' .format (namespace .source ))
715-
716- if not os .path .isdir (namespace .source ):
717- raise ValueError ('incorrect usage: source must be a directory' )
699+ if not os .path .exists (namespace .source ) or not os .path .isdir (namespace .source ):
700+ raise ValueError ('incorrect usage: source must be an existing directory' )
718701
719702 # 2. try to extract account name and container name from destination string
720- from .storage_url_helpers import StorageResourceIdentifier
721- identifier = StorageResourceIdentifier (cmd .cli_ctx .cloud , namespace .destination )
722-
723- if not identifier .is_url ():
724- namespace .destination_container_name = namespace .destination
725- elif identifier .blob is not None :
726- raise ValueError ('incorrect usage: destination cannot be a blob url' )
727- else :
728- namespace .destination_container_name = identifier .container
729-
730- if namespace .account_name :
731- if namespace .account_name != identifier .account_name :
732- raise ValueError (
733- 'The given storage account name is not consistent with the account name in the destination URI' )
734- else :
735- namespace .account_name = identifier .account_name
736-
737- if not (namespace .account_key or namespace .sas_token or namespace .connection_string ):
738- validate_client_parameters (cmd , namespace )
739-
740- # it is possible the account name be overwritten by the connection string
741- if namespace .account_name != identifier .account_name :
742- raise ValueError (
743- 'The given storage account name is not consistent with the account name in the destination URI' )
744-
745- if not (namespace .account_key or namespace .sas_token or namespace .connection_string ):
746- raise ValueError ('Missing storage account credential information.' )
703+ _process_blob_batch_container_parameters (cmd , namespace , source = False )
747704
748705 # 3. collect the files to be uploaded
749706 namespace .source = os .path .realpath (namespace .source )
@@ -765,10 +722,48 @@ def process_blob_upload_batch_parameters(cmd, namespace):
765722 else :
766723 namespace .blob_type = 'block'
767724
725+ # 5. call other validators
726+ validate_metadata (namespace )
727+ t_blob_content_settings = cmd .loader .get_sdk ('blob.models#ContentSettings' )
728+ get_content_setting_validator (t_blob_content_settings , update = False )(cmd , namespace )
729+ add_progress_callback (cmd , namespace )
730+
731+
732+ def process_blob_delete_batch_parameters (cmd , namespace ):
733+ _process_blob_batch_container_parameters (cmd , namespace )
734+
735+
736+ def _process_blob_batch_container_parameters (cmd , namespace , source = True ):
737+ """Process the container parameters for storage blob batch commands before populating args from environment."""
738+ if source :
739+ container_arg , container_name_arg = 'source' , 'source_container_name'
740+ else :
741+ # destination
742+ container_arg , container_name_arg = 'destination' , 'destination_container_name'
743+
744+ # try to extract account name and container name from source string
745+ from .storage_url_helpers import StorageResourceIdentifier
746+ container_arg_val = getattr (namespace , container_arg ) # either a url or name
747+ identifier = StorageResourceIdentifier (cmd .cli_ctx .cloud , container_arg_val )
748+
749+ if not identifier .is_url ():
750+ setattr (namespace , container_name_arg , container_arg_val )
751+ elif identifier .blob :
752+ raise ValueError ('incorrect usage: {} should be either a container URL or name' .format (container_arg ))
753+ else :
754+ setattr (namespace , container_name_arg , identifier .container )
755+ if namespace .account_name is None :
756+ namespace .account_name = identifier .account_name
757+ elif namespace .account_name != identifier .account_name :
758+ raise ValueError ('The given storage account name is not consistent with the '
759+ 'account name in the destination URL' )
760+
761+ # if no sas-token is given and the container url contains one, use it
762+ if not namespace .sas_token and identifier .sas_token :
763+ namespace .sas_token = identifier .sas_token
768764
769- def process_blob_copy_batch_namespace (namespace ):
770- if namespace .prefix is None and not namespace .recursive :
771- raise ValueError ('incorrect usage: --recursive | --pattern PATTERN' )
765+ # Finally, grab missing storage connection parameters from environment variables
766+ validate_client_parameters (cmd , namespace )
772767
773768
774769def process_file_upload_batch_parameters (cmd , namespace ):
0 commit comments