示例#1
0
def cf_table_service(cli_ctx, kwargs):
    from azure.data.tables._table_service_client import TableServiceClient
    client_kwargs = prepare_client_kwargs_track2(cli_ctx)
    client_kwargs = _config_location_mode(kwargs, client_kwargs)
    connection_string = kwargs.pop('connection_string', None)
    account_name = kwargs.pop('account_name', None)
    account_url = kwargs.pop('account_url', None)
    account_key = kwargs.pop('account_key', None)
    token_credential = kwargs.pop('token_credential', None)
    sas_token = kwargs.pop('sas_token', None)

    if connection_string:
        return TableServiceClient.from_connection_string(
            conn_str=connection_string, **client_kwargs)
    if not account_url:
        account_url = get_account_url(cli_ctx,
                                      account_name=account_name,
                                      service='table')
    if account_key:
        from azure.core.credentials import AzureNamedKeyCredential
        credential = AzureNamedKeyCredential(name=account_name,
                                             key=account_key)
    elif sas_token:
        from azure.core.credentials import AzureSasCredential
        credential = AzureSasCredential(signature=sas_token)
    else:
        credential = token_credential

    return TableServiceClient(endpoint=account_url,
                              credential=credential,
                              **client_kwargs)
示例#2
0
def cf_blob_service(cli_ctx, kwargs):
    client_kwargs = prepare_client_kwargs_track2(cli_ctx)
    client_kwargs = _config_location_mode(kwargs, client_kwargs)
    t_blob_service = get_sdk(cli_ctx, ResourceType.DATA_STORAGE_BLOB,
                             '_blob_service_client#BlobServiceClient')
    connection_string = kwargs.pop('connection_string', None)
    account_name = kwargs.pop('account_name', None)
    account_key = kwargs.pop('account_key', None)
    token_credential = kwargs.pop('token_credential', None)
    sas_token = kwargs.pop('sas_token', None)

    if connection_string:
        try:
            return t_blob_service.from_connection_string(conn_str=connection_string, **client_kwargs)
        except ValueError as err:
            from azure.cli.core.azclierror import InvalidArgumentValueError
            raise InvalidArgumentValueError('Invalid connection string: {}, err detail: {}'
                                            .format(connection_string, str(err)),
                                            recommendation='Try `az storage account show-connection-string` '
                                                           'to get a valid connection string')

    account_url = get_account_url(cli_ctx, account_name=account_name, service='blob')
    credential = account_key or sas_token or token_credential

    return t_blob_service(account_url=account_url, credential=credential, **client_kwargs)
示例#3
0
def cf_adls_service(cli_ctx, kwargs):
    client_kwargs = prepare_client_kwargs_track2(cli_ctx)
    client_kwargs = _config_location_mode(kwargs, client_kwargs)
    t_adls_service = get_sdk(
        cli_ctx, ResourceType.DATA_STORAGE_FILEDATALAKE,
        '_data_lake_service_client#DataLakeServiceClient')
    connection_string = kwargs.pop('connection_string', None)
    account_name = kwargs.pop('account_name', None)
    account_url = kwargs.pop('account_url', None)
    account_key = kwargs.pop('account_key', None)
    token_credential = kwargs.pop('token_credential', None)
    sas_token = kwargs.pop('sas_token', None)

    location_mode = kwargs.pop('location_mode', None)
    if location_mode:
        client_kwargs['_location_mode'] = location_mode

    if connection_string:
        return t_adls_service.from_connection_string(
            conn_str=connection_string, **client_kwargs)
    if not account_url:
        account_url = get_account_url(cli_ctx,
                                      account_name=account_name,
                                      service='dfs')
    credential = account_key or sas_token or token_credential

    return t_adls_service(account_url=account_url,
                          credential=credential,
                          **client_kwargs)
示例#4
0
def cf_queue_service(cli_ctx, kwargs):
    client_kwargs = prepare_client_kwargs_track2(cli_ctx)
    client_kwargs = _config_location_mode(kwargs, client_kwargs)
    t_queue_service = get_sdk(cli_ctx, ResourceType.DATA_STORAGE_QUEUE, '_queue_service_client#QueueServiceClient')
    connection_string = kwargs.pop('connection_string', None)
    account_name = kwargs.pop('account_name', None)
    account_key = kwargs.pop('account_key', None)
    token_credential = kwargs.pop('token_credential', None)
    sas_token = kwargs.pop('sas_token', None)

    if connection_string:
        return t_queue_service.from_connection_string(conn_str=connection_string, **client_kwargs)

    account_url = get_account_url(cli_ctx, account_name=account_name, service='queue')
    credential = account_key or sas_token or token_credential

    return t_queue_service(account_url=account_url, credential=credential, **client_kwargs)