Skip to content

Commit

Permalink
Take care of sas token inputs for storage blob copy source with que…
Browse files Browse the repository at this point in the history
…ry char (Azure#6074)

* take care of sas token inputs for blob copy source with query char

* history

* use source-sas arg in test
  • Loading branch information
williexu authored Apr 11, 2018
1 parent 42b03e9 commit d17098b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-storage/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release History
* Allow destination sas-token to apply to source for blob copy if source sas and account key are unspecified.
* Expose --socket-timeout for blob uploads and downloads.
* Treat blob names that start with path separators as relative paths.
* `storage blob copy` Allow --source-sas with starting query char, '?'

2.0.31
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def validate_source_uri(cmd, namespace): # pylint: disable=too-many-statements

query_params = []
if source_sas:
query_params.append(source_sas)
query_params.append(source_sas.lstrip('?'))
if snapshot:
query_params.append('snapshot={}'.format(snapshot))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,28 @@ def test_storage_blob_copy_same_account_sas(self, resource_group, storage_accoun
actual_content = f.read()

self.assertEqual(expect_content, actual_content)

# test source sas-token input starting with '?'
if not sas.startswith('?'):
sas = '?' + sas

target_container = self.create_container(account_info)
self.storage_cmd('storage blob copy start -b dst -c {} --source-blob src --source-sas {} --source-container {}',
account_info, target_container, sas, source_container)

start = time()
while True:
blob = self.storage_cmd('storage blob show -c {} -n dst',
account_info, target_container).get_output_in_json()
if blob["properties"]["copy"]["status"] == "success" or time() - start > 10:
break
sleep(.1)

target_file = self.create_temp_file(1)
self.storage_cmd('storage blob download -c {} -n dst -f "{}"', account_info,
target_container, target_file)

with open(target_file, 'rb') as f:
actual_content = f.read()

self.assertEqual(expect_content, actual_content)

0 comments on commit d17098b

Please sign in to comment.