Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worm2 #197

Closed
wants to merge 2 commits into from
Closed

Worm2 #197

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/storage-preview/azext_storage_preview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azure.cli.core.profiles import ResourceType, register_resource_type
from azure.cli.core.profiles import register_resource_type
from azure.cli.core.commands import AzCommandGroup, AzArgumentContext

import azext_storage_preview._help # pylint: disable=unused-import
from .profiles import CUSTOM_DATA_STORAGE
from .profiles import CUSTOM_DATA_STORAGE, CUSTOM_MGMT_STORAGE


class StorageCommandsLoader(AzCommandsLoader):
def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType

register_resource_type('latest', CUSTOM_DATA_STORAGE, '2017-11-09')
register_resource_type('latest', CUSTOM_MGMT_STORAGE, '2018-02-01')
storage_custom = CliCommandType(operations_tmpl='azext_storage_preview.custom#{}')

super(StorageCommandsLoader, self).__init__(cli_ctx=cli_ctx,
Expand Down Expand Up @@ -107,12 +108,12 @@ def register_common_storage_account_options(self):
from ._validators import validate_encryption_services

t_access_tier, t_sku_name, t_encryption_services = self.command_loader.get_models(
'AccessTier', 'SkuName', 'EncryptionServices', resource_type=ResourceType.MGMT_STORAGE)
'AccessTier', 'SkuName', 'EncryptionServices', resource_type=CUSTOM_MGMT_STORAGE)

self.argument('https_only', help='Allows https traffic only to storage service.',
arg_type=get_three_state_flag())
self.argument('sku', help='The storage account SKU.', arg_type=get_enum_type(t_sku_name))
self.argument('assign_identity', action='store_true', resource_type=ResourceType.MGMT_STORAGE,
self.argument('assign_identity', action='store_true', resource_type=CUSTOM_MGMT_STORAGE,
min_api='2017-06-01',
help='Generate and assign a new Storage Account Identity for this storage account for use '
'with key management services like Azure KeyVault.')
Expand All @@ -125,7 +126,7 @@ def register_common_storage_account_options(self):
encryption_choices = list(
t_encryption_services._attribute_map.keys()) # pylint: disable=protected-access
self.argument('encryption_services', arg_type=get_enum_type(encryption_choices),
resource_type=ResourceType.MGMT_STORAGE, min_api='2016-12-01', nargs='+',
resource_type=CUSTOM_MGMT_STORAGE, min_api='2016-12-01', nargs='+',
validator=validate_encryption_services, help='Specifies which service(s) to encrypt.')


Expand Down
6 changes: 3 additions & 3 deletions src/storage-preview/azext_storage_preview/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client, _get_add_headers_callback
from azure.cli.core.profiles import ResourceType, get_sdk
from azure.cli.core.profiles import get_sdk
from knack.util import CLIError
from knack.log import get_logger

from .sdkutil import get_table_data_type
from .profiles import CUSTOM_DATA_STORAGE
from .profiles import CUSTOM_DATA_STORAGE, CUSTOM_MGMT_STORAGE

NO_CREDENTIALS_ERROR_MESSAGE = """
No credentials specified to access storage service. Please provide any of the following:
Expand Down Expand Up @@ -75,7 +75,7 @@ def generic_data_service_factory(cli_ctx, service, name=None, key=None, connecti


def storage_client_factory(cli_ctx, **_):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_STORAGE)
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_STORAGE)


def file_data_service_factory(cli_ctx, kwargs):
Expand Down
9 changes: 4 additions & 5 deletions src/storage-preview/azext_storage_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.profiles import ResourceType
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azure.cli.core.commands.parameters import (tags_type, file_type, get_location_type, get_enum_type)

Expand All @@ -13,7 +12,7 @@
validate_table_payload_format, validate_key, add_progress_callback,
storage_account_key_options, process_file_download_namespace, process_metric_update_namespace,
get_char_options_validator, validate_bypass, validate_encryption_source)

from .profiles import CUSTOM_MGMT_STORAGE

def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statements
from argcomplete.completers import FilesCompleter
Expand Down Expand Up @@ -93,7 +92,7 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem

with self.argument_context('storage account create') as c:
t_account_type, t_sku_name, t_kind = self.get_models('AccountType', 'SkuName', 'Kind',
resource_type=ResourceType.MGMT_STORAGE)
resource_type=CUSTOM_MGMT_STORAGE)

c.register_common_storage_account_options()
c.argument('location', get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
Expand Down Expand Up @@ -126,10 +125,10 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
c.ignore('encryption_key_vault_properties')

for scope in ['storage account create', 'storage account update']:
with self.argument_context(scope, resource_type=ResourceType.MGMT_STORAGE, min_api='2017-06-01',
with self.argument_context(scope, resource_type=CUSTOM_MGMT_STORAGE, min_api='2017-06-01',
arg_group='Network Rule') as c:
t_bypass, t_default_action = self.get_models('Bypass', 'DefaultAction',
resource_type=ResourceType.MGMT_STORAGE)
resource_type=CUSTOM_MGMT_STORAGE)

c.argument('bypass', nargs='+', validator=validate_bypass, arg_type=get_enum_type(t_bypass),
help='Bypass traffic for space-separated uses.')
Expand Down
11 changes: 6 additions & 5 deletions src/storage-preview/azext_storage_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# pylint: disable=protected-access
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.commands.validators import validate_key_value_pairs
from azure.cli.core.profiles import ResourceType, get_sdk
from azure.cli.core.profiles import get_sdk

from ._client_factory import get_storage_data_service_client
from .util import glob_files_locally, guess_content_type
from .sdkutil import get_table_data_type
from .url_quote_util import encode_for_url
from .oauth_token_util import TokenUpdater
from .profiles import CUSTOM_MGMT_STORAGE

storage_account_key_options = {'primary': 'key1', 'secondary': 'key2'}

Expand All @@ -23,15 +24,15 @@
# pylint: disable=inconsistent-return-statements
def _query_account_key(cli_ctx, account_name):
"""Query the storage account key. This is used when the customer doesn't offer account key but name."""
scf = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_STORAGE)
scf = get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_STORAGE)
acc = next((x for x in scf.storage_accounts.list() if x.name == account_name), None)
if acc:
from msrestazure.tools import parse_resource_id
rg = parse_resource_id(acc.id)['resource_group']

t_storage_account_keys, t_storage_account_list_keys_results = get_sdk(
cli_ctx,
ResourceType.MGMT_STORAGE,
CUSTOM_MGMT_STORAGE,
'models.storage_account_keys#StorageAccountKeys',
'models.storage_account_list_keys_result#StorageAccountListKeysResult')

Expand Down Expand Up @@ -398,7 +399,7 @@ def validate_encryption_services(cmd, namespace):
Builds up the encryption services object for storage account operations based on the list of services passed in.
"""
if namespace.encryption_services:
t_encryption_services, t_encryption_service = get_sdk(cmd.cli_ctx, ResourceType.MGMT_STORAGE,
t_encryption_services, t_encryption_service = get_sdk(cmd.cli_ctx, CUSTOM_MGMT_STORAGE,
'EncryptionServices', 'EncryptionService', mod='models')
services = {service: t_encryption_service(enabled=True) for service in namespace.encryption_services}

Expand All @@ -420,7 +421,7 @@ def validate_encryption_source(cmd, namespace):
if namespace.encryption_key_source != 'Microsoft.Keyvault':
raise ValueError('--encryption-key-name, --encryption-key-vault, and --encryption-key-version are not '
'applicable when --encryption-key-source=Microsoft.Keyvault is not specified.')
KeyVaultProperties = get_sdk(cmd.cli_ctx, ResourceType.MGMT_STORAGE, 'KeyVaultProperties',
KeyVaultProperties = get_sdk(cmd.cli_ctx, CUSTOM_MGMT_STORAGE, 'KeyVaultProperties',
mod='models')
if not KeyVaultProperties:
return
Expand Down
8 changes: 4 additions & 4 deletions src/storage-preview/azext_storage_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
cloud_storage_account_service_factory,
multi_service_properties_factory)
from .sdkutil import cosmosdb_table_exists
from .profiles import CUSTOM_DATA_STORAGE
from .profiles import CUSTOM_DATA_STORAGE, CUSTOM_MGMT_STORAGE


def load_command_table(self, _): # pylint: disable=too-many-locals, too-many-statements
storage_account_sdk = CliCommandType(
operations_tmpl='azure.mgmt.storage.operations.storage_accounts_operations#StorageAccountsOperations.{}',
client_factory=cf_sa,
resource_type=ResourceType.MGMT_STORAGE
resource_type=CUSTOM_MGMT_STORAGE
)

storage_account_custom_type = CliCommandType(
Expand All @@ -40,7 +40,7 @@ def get_custom_sdk(custom_module, client_factory, resource_type=CUSTOM_DATA_STOR
resource_type=resource_type
)

with self.command_group('storage account', storage_account_sdk, resource_type=ResourceType.MGMT_STORAGE,
with self.command_group('storage account', storage_account_sdk, resource_type=CUSTOM_MGMT_STORAGE,
custom_command_type=storage_account_custom_type) as g:
g.command('check-name', 'check_name_availability')
g.custom_command('create', 'create_storage_account', min_api='2016-01-01')
Expand All @@ -57,7 +57,7 @@ def get_custom_sdk(custom_module, client_factory, resource_type=CUSTOM_DATA_STOR

with self.command_group('storage account network-rule', storage_account_sdk,
custom_command_type=storage_account_custom_type,
resource_type=ResourceType.MGMT_STORAGE, min_api='2017-06-01') as g:
resource_type=CUSTOM_MGMT_STORAGE, min_api='2017-06-01') as g:
g.custom_command('add', 'add_network_rule')
g.custom_command('list', 'list_network_rules')
g.custom_command('remove', 'remove_network_rule')
Expand Down
2 changes: 2 additions & 0 deletions src/storage-preview/azext_storage_preview/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@


CUSTOM_DATA_STORAGE = CustomResourceType('azext_storage_preview.vendored_sdks.azure_storage', None)
CUSTOM_MGMT_STORAGE = CustomResourceType('azext_storage_preview.vendored_sdks.azure_mgmt_storage',
'StorageManagementClient')
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
StorageAccountPreparer, api_version_constraint)
from azure.cli.core.profiles import ResourceType
from .storage_test_util import StorageScenarioMixin
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageAccountTests(StorageScenarioMixin, ScenarioTest):
@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2017-06-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2017-06-01')
@ResourceGroupPreparer(name_prefix='cli_test_storage_service_endpoints')
@StorageAccountPreparer()
def test_storage_account_service_endpoints(self, resource_group, storage_account):
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_storage_account_service_endpoints(self, resource_group, storage_account
JMESPathCheck('length(virtualNetworkRules)', 0)
])

@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2017-06-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2017-06-01')
@ResourceGroupPreparer(location='southcentralus')
def test_create_storage_account_with_assigned_identity(self, resource_group):
name = self.create_random_name(prefix='cli', length=24)
Expand All @@ -69,7 +70,7 @@ def test_create_storage_account_with_assigned_identity(self, resource_group):
self.assertTrue(result['identity']['principalId'])
self.assertTrue(result['identity']['tenantId'])

@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2017-06-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2017-06-01')
@ResourceGroupPreparer(location='southcentralus')
def test_update_storage_account_with_assigned_identity(self, resource_group):
name = self.create_random_name(prefix='cli', length=24)
Expand Down Expand Up @@ -127,7 +128,7 @@ def test_create_storage_account(self, resource_group, location):
self.cmd('storage account check-name --name {}'.format(name),
checks=JMESPathCheck('nameAvailable', True))

@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2017-10-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2017-10-01')
@ResourceGroupPreparer(parameter_name_for_location='location', location='southcentralus')
def test_create_storage_account_v2(self, resource_group, location):
self.kwargs.update({
Expand All @@ -143,7 +144,7 @@ def test_create_storage_account_v2(self, resource_group, location):
JMESPathCheck('reason', 'AlreadyExists')
])

@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-01-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-01-01')
@ResourceGroupPreparer(location='southcentralus')
def test_storage_create_default_sku(self, resource_group):
name = self.create_random_name(prefix='cli', length=24)
Expand Down Expand Up @@ -254,7 +255,7 @@ def test_customer_managed_key(self, resource_group, storage_account):
'--encryption-key-version {ver} ')


@api_version_constraint(ResourceType.MGMT_STORAGE, max_api='2016-01-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, max_api='2016-01-01')
class StorageAccountTestsForStack(StorageScenarioMixin, ScenarioTest):
@ResourceGroupPreparer(parameter_name_for_location='location', name_prefix='cli_test_storage_stack_scenario',
location='local', dev_setting_location='local')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
api_version_constraint)
from azure.cli.core.profiles import ResourceType
from .storage_test_util import StorageScenarioMixin
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageAccessControlListTests(StorageScenarioMixin, ScenarioTest):
@ResourceGroupPreparer()
@StorageAccountPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from azure.cli.testsdk import (LiveScenarioTest, ResourceGroupPreparer, StorageAccountPreparer,
JMESPathCheck, api_version_constraint)
from azure.cli.core.profiles import ResourceType
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageBlobUploadLiveTests(LiveScenarioTest):
@ResourceGroupPreparer()
@StorageAccountPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

from ..._client_factory import NO_CREDENTIALS_ERROR_MESSAGE
from .storage_test_util import StorageScenarioMixin
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageBlobUploadTests(StorageScenarioMixin, ScenarioTest):
@ResourceGroupPreparer()
@StorageAccountPreparer(parameter_name='source_account')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from azure.cli.testsdk import (ScenarioTest, JMESPathCheck, ResourceGroupPreparer,
StorageAccountPreparer, api_version_constraint)
from azure.cli.core.profiles import ResourceType
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageCorsTests(ScenarioTest):
@ResourceGroupPreparer()
@StorageAccountPreparer(parameter_name='account')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, StorageAccountPreparer, api_version_constraint,
JMESPathCheck, JMESPathCheckExists, NoneCheck)
from azure.cli.core.profiles import ResourceType
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageQueueScenarioTests(ScenarioTest):
@ResourceGroupPreparer()
@StorageAccountPreparer(sku='Standard_RAGRS')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
JMESPathCheck, NoneCheck, api_version_constraint)
from azure.cli.core.profiles import ResourceType
from .storage_test_util import StorageScenarioMixin
from ...profiles import CUSTOM_MGMT_STORAGE


@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class StorageTableScenarioTests(StorageScenarioMixin, ScenarioTest):
@ResourceGroupPreparer()
@StorageAccountPreparer(sku='Standard_RAGRS')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from azure.cli.testsdk import api_version_constraint
from ..._validators import (get_source_file_or_blob_service_client, validate_encryption_source,
validate_encryption_services)
from ...profiles import CUSTOM_DATA_STORAGE
from ...profiles import CUSTOM_DATA_STORAGE, CUSTOM_MGMT_STORAGE


class MockCLI(CLI):
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_storage_get_char_options_validator(self):
self.assertEqual(result, set('ab'))


@api_version_constraint(resource_type=ResourceType.MGMT_STORAGE, min_api='2016-12-01')
@api_version_constraint(resource_type=CUSTOM_MGMT_STORAGE, min_api='2016-12-01')
class TestEncryptionValidators(unittest.TestCase):
def setUp(self):
self.cli = MockCLI()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from .storage_management_client import StorageManagementClient
from .version import VERSION

__all__ = ['StorageManagementClient']

__version__ = VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from .v2018_02_01.models import *
Loading