/// <summary>
        /// Initializes a new instance of the <see cref="TableServiceClient"/> using the specified connection string.
        /// </summary>
        /// <param name="connectionString">
        /// A connection string includes the authentication information
        /// required for your application to access data in an Azure Storage
        /// account at runtime.
        ///
        /// For more information,
        /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string">
        /// Configure Azure Storage connection strings</see>.
        /// </param>
        /// <param name="options">
        /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
        /// </param>
        public TableServiceClient(string connectionString, TableClientOptions options = null)
        {
            Argument.AssertNotNull(connectionString, nameof(connectionString));

            TableConnectionString connString = TableConnectionString.Parse(connectionString);

            _accountName = connString._accountName;

            options ??= new TableClientOptions();
            var endpointString    = connString.TableStorageUri.PrimaryUri.AbsoluteUri;
            var secondaryEndpoint = connString.TableStorageUri.SecondaryUri?.AbsoluteUri;

            _isCosmosEndpoint = TableServiceClient.IsPremiumEndpoint(connString.TableStorageUri.PrimaryUri);
            var perCallPolicies = _isCosmosEndpoint ? new[] { new CosmosPatchTransformPolicy() } : Array.Empty <HttpPipelinePolicy>();

            TableSharedKeyPipelinePolicy policy = connString.Credentials switch
            {
                TableSharedKeyCredential credential => new TableSharedKeyPipelinePolicy(credential),
                _ => default
            };
            HttpPipeline pipeline = HttpPipelineBuilder.Build(options, perCallPolicies: perCallPolicies, perRetryPolicies: new[] { policy }, new ResponseClassifier());

            _version                    = options.VersionString;
            _diagnostics                = new ClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, pipeline, endpointString, _version);
            _serviceOperations          = new ServiceRestClient(_diagnostics, pipeline, endpointString, _version);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, pipeline, secondaryEndpoint, _version);
        }
 public TableServiceClient(Uri endpoint, TableClientOptions options = null)
     : this(endpoint, default(TableSharedKeyPipelinePolicy), options)
 {
     if (endpoint.Scheme != "https")
     {
         throw new ArgumentException("Cannot use TokenCredential without HTTPS.", nameof(endpoint));
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableServiceClient"/> using the specified <see cref="Uri" /> containing a shared access signature (SAS)
 /// token credential. See <see cref="TableClient.GetSasBuilder(TableSasPermissions, DateTimeOffset)" /> for creating a SAS token.
 /// </summary>
 /// <param name="endpoint">
 /// A <see cref="Uri"/> referencing the table service account.
 /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
 /// </param>
 /// <param name="credential">The shared access signature credential used to sign requests.</param>
 /// <param name="options">
 /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
 /// </param>
 public TableServiceClient(Uri endpoint, AzureSasCredential credential, TableClientOptions options = null)
     : this(endpoint, default, credential, options)
 {
     if (endpoint.Scheme != "https")
     {
         throw new ArgumentException("Cannot use TokenCredential without HTTPS.", nameof(endpoint));
     }
     Argument.AssertNotNull(credential, nameof(credential));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableServiceClient"/> using the specified <see cref="Uri" /> containing a shared access signature (SAS)
 /// token credential. See <see cref="GenerateSasUri(TableAccountSasPermissions,TableAccountSasResourceTypes,DateTimeOffset)"/> for creating a SAS token.
 /// </summary>
 /// <param name="endpoint">
 /// A <see cref="Uri"/> referencing the table service account.
 /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
 /// </param>
 /// <param name="options">
 /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
 /// </param>
 /// <exception cref="ArgumentException"><paramref name="endpoint"/> does not start with 'https'.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="endpoint"/> is null.</exception>
 public TableServiceClient(Uri endpoint, TableClientOptions options = null)
     : this(endpoint, default, default, options)
 {
     if (endpoint.Scheme != Uri.UriSchemeHttps)
     {
         throw new ArgumentException("Cannot use TokenCredential without HTTPS.", nameof(endpoint));
     }
     if (string.IsNullOrEmpty(endpoint.Query))
     {
         throw new ArgumentException($"{nameof(endpoint)} must contain a SAS token query.");
     }
 }
        /// <summary>
        /// Creates a pipeline to use for processing sub-operations before they
        /// are combined into a single multipart request.
        /// </summary>
        /// <returns>A pipeline to use for processing sub-operations.</returns>
        private static HttpPipeline CreateBatchPipeline()
        {
            // Configure the options to use minimal policies
            var options = new TableClientOptions();

            options.Diagnostics.IsLoggingEnabled            = false;
            options.Diagnostics.IsTelemetryEnabled          = false;
            options.Diagnostics.IsDistributedTracingEnabled = false;
            options.Retry.MaxRetries = 0;

            // Use an empty transport so requests aren't sent
            options.Transport = new MemoryTransport();

            // Use the same authentication mechanism
            return(HttpPipelineBuilder.Build(options));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TableServiceClient"/> using the specified connection string.
        /// </summary>
        /// <param name="connectionString">
        /// A connection string includes the authentication information
        /// required for your application to access data in an Azure Storage
        /// account at runtime.
        ///
        /// For more information,
        /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string">
        /// Configure Azure Storage connection strings</see>.
        /// </param>
        /// <param name="options">
        /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
        /// </param>
        public TableServiceClient(string connectionString, TableClientOptions options = null)
        {
            Argument.AssertNotNull(connectionString, nameof(connectionString));

            TableConnectionString connString = TableConnectionString.Parse(connectionString);

            options ??= new TableClientOptions();
            var endpointString    = connString.TableStorageUri.PrimaryUri.AbsoluteUri;
            var secondaryEndpoint = connString.TableStorageUri.SecondaryUri?.AbsoluteUri;

            TableSharedKeyPipelinePolicy policy = connString.Credentials switch
            {
                TableSharedKeyCredential credential => new TableSharedKeyPipelinePolicy(credential),
                _ => default
            };
            HttpPipeline pipeline = HttpPipelineBuilder.Build(options, policy);

            _version                    = options.VersionString;
            _diagnostics                = new ClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, pipeline, endpointString, _version);
            _serviceOperations          = new ServiceRestClient(_diagnostics, pipeline, endpointString, _version);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, pipeline, secondaryEndpoint, _version);
            _isPremiumEndpoint          = IsPremiumEndpoint(connString.TableStorageUri.PrimaryUri);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TableServiceClient"/> using the specified <see cref="Uri" />.
        /// </summary>
        /// <param name="endpoint">
        /// A <see cref="Uri"/> referencing the table service account.
        /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
        /// </param>
        /// <param name="tokenCredential">The <see cref="TokenCredential"/> used to authorize requests.</param>
        /// <param name="options">
        /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="endpoint"/> or <paramref name="tokenCredential"/> is null.</exception>
        public TableServiceClient(Uri endpoint, TokenCredential tokenCredential, TableClientOptions options = default)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));
            Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));

            _endpoint = endpoint;
            options ??= TableClientOptions.DefaultOptions;
            _isCosmosEndpoint = IsPremiumEndpoint(endpoint);
            var    perCallPolicies   = _isCosmosEndpoint ? new[] { new CosmosPatchTransformPolicy() } : Array.Empty <HttpPipelinePolicy>();
            var    endpointString    = endpoint.AbsoluteUri;
            string secondaryEndpoint = TableConnectionString.GetSecondaryUriFromPrimary(endpoint)?.AbsoluteUri;

            _pipeline = HttpPipelineBuilder.Build(
                options,
                perCallPolicies: perCallPolicies,
                perRetryPolicies: new[] { new BearerTokenAuthenticationPolicy(tokenCredential, TableConstants.StorageScope) },
                new ResponseClassifier());

            _version                    = options.VersionString;
            _diagnostics                = new TablesClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, _pipeline, endpointString, _version);
            _serviceOperations          = new ServiceRestClient(_diagnostics, _pipeline, endpointString, _version);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, _pipeline, secondaryEndpoint, _version);
        }
        internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, AzureSasCredential sasCredential, TableClientOptions options)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));

            _endpoint = endpoint;
            options ??= new TableClientOptions();
            _isCosmosEndpoint = IsPremiumEndpoint(endpoint);
            var          perCallPolicies   = _isCosmosEndpoint ? new[] { new CosmosPatchTransformPolicy() } : Array.Empty <HttpPipelinePolicy>();
            var          endpointString    = endpoint.AbsoluteUri;
            string       secondaryEndpoint = TableConnectionString.GetSecondaryUriFromPrimary(endpoint)?.AbsoluteUri;
            HttpPipeline pipeline          = sasCredential switch
            {
                null => HttpPipelineBuilder.Build(options, perCallPolicies: perCallPolicies, perRetryPolicies: new[] { policy }, new ResponseClassifier()),
                _ => HttpPipelineBuilder.Build(options, perCallPolicies: perCallPolicies, perRetryPolicies: new HttpPipelinePolicy[] { policy, new AzureSasCredentialSynchronousPolicy(sasCredential) }, new ResponseClassifier())
            };

            _version                    = options.VersionString;
            _diagnostics                = new ClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, pipeline, endpointString, _version);
            _serviceOperations          = new ServiceRestClient(_diagnostics, pipeline, endpointString, _version);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, pipeline, secondaryEndpoint, _version);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableServiceClient"/> using the specified table service <see cref="Uri" /> and <see cref="TableSharedKeyCredential" />.
 /// </summary>
 /// <param name="endpoint">
 /// A <see cref="Uri"/> referencing the table service account.
 /// This is likely to be similar to "https://{account_name}.table.core.windows.net/" or "https://{account_name}.table.cosmos.azure.com/".
 /// </param>
 /// <param name="credential">The shared key credential used to sign requests.</param>
 /// <param name="options">
 /// Optional client options that define the transport pipeline policies for authentication, retries, etc., that are applied to every request.
 /// </param>
 public TableServiceClient(Uri endpoint, TableSharedKeyCredential credential, TableClientOptions options = null)
     : this(endpoint, new TableSharedKeyPipelinePolicy(credential), default, options)
 {
     Argument.AssertNotNull(credential, nameof(credential));
 }
        internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, TableClientOptions options)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));

            options ??= new TableClientOptions();
            var          endpointString    = endpoint.ToString();
            var          secondaryEndpoint = endpointString.Insert(endpointString.IndexOf('.'), "-secondary");
            HttpPipeline pipeline;

            if (policy == default)
            {
                pipeline = HttpPipelineBuilder.Build(options);
            }
            else
            {
                pipeline = HttpPipelineBuilder.Build(options, policy);
            }

            _diagnostics                = new ClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, pipeline, endpointString);
            _serviceOperations          = new ServiceRestClient(_diagnostics, pipeline, endpointString);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, pipeline, secondaryEndpoint);
            _version = options.VersionString;

            string absoluteUri = endpoint.OriginalString.ToLowerInvariant();

            _isPremiumEndpoint = (endpoint.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase) && endpoint.Port != 10002) ||
                                 absoluteUri.Contains(TableConstants.CosmosTableDomain) || absoluteUri.Contains(TableConstants.LegacyCosmosTableDomain);
        }
Beispiel #11
0
        internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, TableClientOptions options)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));

            options ??= new TableClientOptions();
            var          endpointString = endpoint.ToString();
            HttpPipeline pipeline;

            if (policy == default)
            {
                pipeline = HttpPipelineBuilder.Build(options);
            }
            else
            {
                pipeline = HttpPipelineBuilder.Build(options, policy);
            }

            var diagnostics = new ClientDiagnostics(options);

            _tableOperations = new TableRestClient(diagnostics, pipeline, endpointString);
            _version         = options.VersionString;
        }
        internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, AzureSasCredential sasCredential, TableClientOptions options)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));

            options ??= new TableClientOptions();
            var          endpointString    = endpoint.AbsoluteUri;
            string       secondaryEndpoint = TableConnectionString.GetSecondaryUriFromPrimary(endpoint)?.AbsoluteUri;
            HttpPipeline pipeline          = sasCredential switch
            {
                null => HttpPipelineBuilder.Build(options, policy),
                _ => HttpPipelineBuilder.Build(options, policy, new AzureSasCredentialSynchronousPolicy(sasCredential))
            };

            _version                    = options.VersionString;
            _diagnostics                = new ClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, pipeline, endpointString, _version);
            _serviceOperations          = new ServiceRestClient(_diagnostics, pipeline, endpointString, _version);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, pipeline, secondaryEndpoint, _version);
            _isPremiumEndpoint          = IsPremiumEndpoint(endpoint);
        }
        internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, TableClientOptions options)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));
            if (endpoint.Scheme != "https")
            {
                throw new ArgumentException("Cannot use TokenCredential without HTTPS.");
            }
            options ??= new TableClientOptions();
            var          endpointString = endpoint.ToString();
            HttpPipeline pipeline;

            if (policy == default)
            {
                pipeline = HttpPipelineBuilder.Build(options);
            }
            else
            {
                pipeline = HttpPipelineBuilder.Build(options, policy);
            }

            var diagnostics = new ClientDiagnostics(options);

            _tableOperations = new TableInternalClient(diagnostics, pipeline, endpointString);
        }
 public TableServiceClient(Uri endpoint, TableClientOptions options = null)
     : this(endpoint, default(TableSharedKeyPipelinePolicy), options)
 {
 }
        internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, TableClientOptions options)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));

            options ??= new TableClientOptions();
            var          endpointString    = endpoint.ToString();
            var          secondaryEndpoint = endpointString.Insert(endpointString.IndexOf('.'), "-secondary");
            HttpPipeline pipeline          = HttpPipelineBuilder.Build(options, policy);

            _diagnostics                = new ClientDiagnostics(options);
            _tableOperations            = new TableRestClient(_diagnostics, pipeline, endpointString);
            _serviceOperations          = new ServiceRestClient(_diagnostics, pipeline, endpointString);
            _secondaryServiceOperations = new ServiceRestClient(_diagnostics, pipeline, secondaryEndpoint);
            _version           = options.VersionString;
            _isPremiumEndpoint = IsPremiumEndpoint(endpoint);
        }
        public TableServiceClient(Uri endpoint, TablesSharedKeyCredential credential, TableClientOptions options = null)
        {
            Argument.AssertNotNull(endpoint, nameof(endpoint));
            Argument.AssertNotNull(credential, nameof(credential));

            options ??= new TableClientOptions();

            var endpointString = endpoint.ToString();
            var pipeline       = HttpPipelineBuilder.Build(options, new TablesSharedKeyPipelinePolicy(credential));
            var diagnostics    = new ClientDiagnostics(options);

            _tableOperations = new TableInternalClient(diagnostics, pipeline, endpointString);
        }