/// <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, TablesClientOptions options = null) { Argument.AssertNotNull(connectionString, nameof(connectionString)); TableConnectionString connString = TableConnectionString.Parse(connectionString); _accountName = connString._accountName; options ??= new TablesClientOptions(); 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 }; _pipeline = HttpPipelineBuilder.Build( options, perCallPolicies: perCallPolicies, perRetryPolicies: new[] { policy }, 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); }
/// <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, TablesClientOptions options = null) : this(endpoint, default, credential, options) { if (endpoint.Scheme != Uri.UriSchemeHttps) { throw new ArgumentException("Cannot use TokenCredential without HTTPS.", nameof(endpoint)); } Argument.AssertNotNull(credential, nameof(credential)); }
internal TableServiceClient(Uri endpoint, TableSharedKeyPipelinePolicy policy, AzureSasCredential sasCredential, TablesClientOptions options) { Argument.AssertNotNull(endpoint, nameof(endpoint)); _endpoint = endpoint; options ??= new TablesClientOptions(); _isCosmosEndpoint = IsPremiumEndpoint(endpoint); var perCallPolicies = _isCosmosEndpoint ? new[] { new CosmosPatchTransformPolicy() } : Array.Empty <HttpPipelinePolicy>(); var endpointString = endpoint.AbsoluteUri; string secondaryEndpoint = TableConnectionString.GetSecondaryUriFromPrimary(endpoint)?.AbsoluteUri; HttpPipelinePolicy authPolicy = sasCredential switch { null => policy, _ => new AzureSasCredentialSynchronousPolicy(sasCredential) }; _pipeline = HttpPipelineBuilder.Build( options, perCallPolicies: perCallPolicies, perRetryPolicies: new[] { authPolicy }, 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); }
/// <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, TablesClientOptions options) : this(endpoint, new TableSharedKeyPipelinePolicy(credential), default, options) { Argument.AssertNotNull(credential, nameof(credential)); }