/// <summary> /// Storage table management constructor /// </summary> /// <param name="client">Cloud table client</param> public StorageTableManagement(AzureStorageContext context) { internalStorageContext = context; TableClientOptions clientOptions = new TableClientOptions(); clientOptions.AddPolicy(new UserAgentPolicy(ApiConstants.UserAgentHeaderValue), HttpPipelinePosition.PerCall); if (!context.StorageAccount.Credentials.IsToken) { tableClient = internalStorageContext.TableStorageAccount.CreateCloudTableClient(); } else { tableServiceClient = new TableServiceClient(context.StorageAccount.TableEndpoint, context.Track2OauthToken, clientOptions); } }
/// <summary> /// Create the table client /// </summary> /// <param name="connectionString">The connection string</param> /// <param name="tableName">The name of the table</param> /// <param name="retries">Number of retries</param> /// <param name="retryWaitTimeInSeconds">Wait time between retries in seconds</param> /// <returns>The table client</returns> private static (TableServiceClient serviceClient, TableClient tableClient) CreateTableClient(string connectionString, string tableName, int retries, double retryWaitTimeInSeconds) { var options = new TableClientOptions { Retry = { MaxRetries = retries, Delay = TimeSpan.FromSeconds(retryWaitTimeInSeconds), Mode = Azure.Core.RetryMode.Exponential } }; var serviceClient = new TableServiceClient(connectionString, options); var tableClient = serviceClient.GetTableClient(tableName); return(serviceClient, tableClient); }
private static TableClientOptions GetTableClientOptions(Uri geoRedundantServiceUrl) { var tableClientOptions = new TableClientOptions(); // { GeoRedundantSecondaryUri = geoRedundantServiceUrl }; // TODO - Set retry options in line with NFRs once they have been established with the client tableClientOptions.Retry.Delay = TimeSpan.FromMilliseconds(800); tableClientOptions.Retry.MaxDelay = TimeSpan.FromMinutes(1); tableClientOptions.Retry.MaxRetries = 5; tableClientOptions.Retry.Mode = Core.RetryMode.Exponential; tableClientOptions.Retry.NetworkTimeout = TimeSpan.FromSeconds(5); tableClientOptions.Diagnostics.IsDistributedTracingEnabled = true; tableClientOptions.Diagnostics.IsLoggingContentEnabled = false; tableClientOptions.Diagnostics.IsLoggingEnabled = true; tableClientOptions.Diagnostics.IsTelemetryEnabled = true; return(tableClientOptions); }
private static TableClient ConstructTableClientFromCloudTable(CloudTable cloudTable, TableClientOptions options) { TableClient tableClient; if (cloudTable.ServiceClient.Credentials.IsSAS) { AzureSasCredential sasCredential = new AzureSasCredential(cloudTable.ServiceClient.Credentials.SASToken); tableClient = new TableClient(cloudTable.Uri, sasCredential, options); } else if (cloudTable.ServiceClient.Credentials.IsSharedKey) { TableSharedKeyCredential keyCredential = new TableSharedKeyCredential( cloudTable.ServiceClient.Credentials.AccountName, cloudTable.ServiceClient.Credentials.Key); tableClient = new TableClient(cloudTable.Uri, cloudTable.Name, keyCredential, options); } else // IsAnonymous { tableClient = new TableClient(cloudTable.Uri, options); } return(tableClient); }
/// <summary> /// Constructs AzureStorageTable from track 1 CloudTable. /// Internally it constructs track 2 TableClient used by data plane cmdlets. /// </summary> /// <param name="table">Cloud table object.</param> /// <param name="storageContext">Storage context containing account information used to construct TableClient.</param> /// <param name="options">Table client options which should contain powershell user agent.</param> public AzureStorageTable(CloudTable table, AzureStorageContext storageContext, TableClientOptions options) { this.CloudTable = table; this.Name = table.Name; this.Uri = table.Uri; this.Context = storageContext; // construct track 2 table client from track 1 cloud table instance this.TableClient = AzureStorageTable.ConstructTableClientFromCloudTable(this.CloudTable, options); }
protected StorageCloudTableCmdletBase() { this.tableClientOptions = new TableClientOptions(); tableClientOptions.AddPolicy(new UserAgentPolicy(ApiConstants.UserAgentHeaderValue), HttpPipelinePosition.PerCall); }
public TableServiceClient(Uri endpoint, StorageSharedKeyCredential credential, TableClientOptions options = null) { options ??= new TableClientOptions(); var endpoint1 = endpoint.ToString(); var pipeline = HttpPipelineBuilder.Build(options, new TablesSharedKeyPipelinePolicy(credential)); var diagnostics = new ClientDiagnostics(options); _tableOperations = new TableInternalClient(diagnostics, pipeline, endpoint1, "2019-02-02"); }