public async Task SetTokenAsync(string tenantId, string userId, string token) { await _tableClient.CreateIfNotExistsAsync(); var entity = new UserTokenEntity { TenantId = tenantId, UserId = userId, Token = token }; await _tableClient.UpsertEntityAsync(entity); }
public AzureTableLogger(string connectionString, string tableName) { var cloudTableClient = new TableClient(connectionString, tableName); cloudTableClient.CreateIfNotExistsAsync(); _tableClient = cloudTableClient; }
public async Task TokenCredentialAuth() { string storageUri = StorageUri; string tableName = "OfficeSuppliesTokenAuth" + _random.Next(); #region Snippet:TablesAuthTokenCredential // Construct a new TableClient using a TokenCredential. var client = new TableClient( new Uri(storageUri), tableName, #if SNIPPET new DefaultAzureCredential()); #else new ClientSecretCredential( GetVariable("TENANT_ID"), GetVariable("CLIENT_ID"), GetVariable("CLIENT_SECRET"))); #endif // Create the table if it doesn't already exist to verify we've successfully authenticated. await client.CreateIfNotExistsAsync(); #endregion }
public override async Task GlobalSetupAsync() { var serviceUri = Options.EndpointType switch { TableEndpointType.Storage => TestEnvironment.StorageUri, TableEndpointType.CosmosTable => TestEnvironment.CosmosUri, _ => throw new NotSupportedException("Unknown endpoint type") }; var accountName = Options.EndpointType switch { TableEndpointType.Storage => TestEnvironment.StorageAccountName, TableEndpointType.CosmosTable => TestEnvironment.CosmosAccountName, _ => throw new NotSupportedException("Unknown endpoint type") }; var accountKey = Options.EndpointType switch { TableEndpointType.Storage => TestEnvironment.PrimaryStorageAccountKey, TableEndpointType.CosmosTable => TestEnvironment.PrimaryCosmosAccountKey, _ => throw new NotSupportedException("Unknown endpoint type") }; Client = new TableClient( new Uri(serviceUri), TableName, new TableSharedKeyCredential(accountName, accountKey), new TableClientOptions()); await Client.CreateIfNotExistsAsync().ConfigureAwait(false); await base.GlobalSetupAsync().ConfigureAwait(false); }
public EntityMutexFactory(IOptions <EntityMutexFactoryOptions> options, IMutexCollector mutexGc) { _mutexGc = mutexGc; _entityTable = new TableClient(options.Value.ConnectionString, options.Value.Name); _entityTable.CreateIfNotExistsAsync().Wait(); _mutexGc = mutexGc; }
static async Task Main(string[] args) { var tableClient = new TableClient( new Uri("http://127.0.0.1:10002/devstoreaccount1"), "people", new TableSharedKeyCredential( "devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==") ); await tableClient.CreateIfNotExistsAsync(); while (true) { var response = await tableClient.AddEntityAsync( new TableEntity("jong", Guid.NewGuid().ToString()) { { "FirstName", "Jon" }, { "LastName", "Gallant" } } ); Console.WriteLine(response.Status); await Task.Delay(TimeSpan.FromSeconds(1)); } }
public AuthorizationSessionClient(IAuthorizationSessionOptions options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); tableClient = new AsyncLazy <TableClient>(async() => { var client = new TableClient(this.options.ConnectionString, TableName); await client.CreateIfNotExistsAsync().ConfigureAwait(false); return(client); }); }
public async Task <TableClient> GetTable(string tableName) { var client = new TableClient(this.connectionString, tableName); if (!tablesTouched.Contains(tableName)) { await client.CreateIfNotExistsAsync(); tablesTouched.Add(tableName); } return(client); }
public OneTimeTokenService(IOneTimeTokenServiceOptions options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); tableClient = new AsyncLazy <TableClient>(async() => { var client = new TableClient(this.options.ConnectionString, nameof(OneTimeTokenService)); await client.CreateIfNotExistsAsync().ConfigureAwait(false); return(client); }); }
public async Task InitializeAsync(TokenCredential credential) { // KeyVault SecretClient = new SecretClient(new Uri(Env.GetString("AZURE_KEYVAULT_ENDPOINT")), credential); var storageKey = await SecretClient.GetSecretAsync(Env.GetString("AZURE_STORAGE_KEY_SECRET_NAME", "StorageKey")); TableClient = new TableClient( new Uri(Env.GetString("AZURE_STORAGE_TABLE_ENDPOINT")), Env.GetString("AZURE_STORAGE_TABLE_NAME"), new TableSharedKeyCredential( Env.GetString("AZURE_STORAGE_ACCOUNT_NAME"), storageKey.Value.Value)); await TableClient.CreateIfNotExistsAsync(); }
private async Task TestBindToConcurrentlyUpdatedTableEntity <T>(string parameterName) { // Arrange await TableClient.CreateIfNotExistsAsync(); await TableClient.AddEntityAsync(CreateTableEntity(PartitionKey, RowKey, "Value", "Foo")); // Act & Assert var exception = Assert.CatchAsync <FunctionInvocationException>(async() => await CallAsync <T>("Call")); AssertInvocationETagFailure(parameterName, exception); SdkTableEntity entity = await TableClient.GetEntityAsync <SdkTableEntity>(PartitionKey, RowKey); Assert.NotNull(entity); Assert.AreEqual("FooBackground", entity.Value); }
public async Task ConnStringAuth() { string tableName = "OfficeSupplies"; string connectionString = $"DefaultEndpointsProtocol=https;AccountName={StorageAccountName};AccountKey={PrimaryStorageAccountKey};EndpointSuffix={StorageEndpointSuffix ?? DefaultStorageSuffix}"; #region Snippet:TablesAuthConnString // Construct a new TableClient using a connection string. var client = new TableClient( connectionString, tableName); // Create the table if it doesn't already exist to verify we've successfully authenticated. await client.CreateIfNotExistsAsync(); #endregion }
private static async Task <TableClient> InitTableAsync(ILogger logger) { try { var tableCreationClient = GetCloudTableCreationClient(logger); TableClient tableRef = tableCreationClient.GetTableClient(tableName); var tableItem = await tableRef.CreateIfNotExistsAsync(); var didCreate = tableItem is not null; logger.LogInformation("{Verb} Azure storage table {TableName}", didCreate ? "Created" : "Attached to", tableName); return(tableRef); } catch (Exception exc) { logger.LogError(exc, "Could not initialize connection to storage table {TableName}", tableName); throw; } }
public async Task SharedKeyAuth() { string storageUri = StorageUri; string accountName = StorageAccountName; string accountKey = PrimaryStorageAccountKey; string tableName = "OfficeSuppliesSharedKeyAuth" + _random.Next(); #region Snippet:TablesAuthSharedKey // Construct a new TableClient using a TableSharedKeyCredential. var client = new TableClient( new Uri(storageUri), tableName, new TableSharedKeyCredential(accountName, accountKey)); // Create the table if it doesn't already exist to verify we've successfully authenticated. await client.CreateIfNotExistsAsync(); #endregion }
public async Task CreateIfNotExists() { // Call CreateIfNotExists when the table already exists. Assert.That(async() => await CosmosThrottleWrapper(async() => await client.CreateIfNotExistsAsync().ConfigureAwait(false)), Throws.Nothing); // Call CreateIfNotExists when the table does not already exist. var newTableName = Recording.GenerateAlphaNumericId("testtable", useOnlyLowercase: true); TableItem table; TableClient tableClient = null; try { tableClient = service.GetTableClient(newTableName); table = await CosmosThrottleWrapper(async() => await tableClient.CreateIfNotExistsAsync().ConfigureAwait(false)); } finally { await tableClient.DeleteAsync().ConfigureAwait(false); } Assert.That(table.TableName, Is.EqualTo(newTableName)); }
public EntityMutexFactory(TableClient entityTable, IMutexCollector mutexGc) { _entityTable = entityTable; _entityTable.CreateIfNotExistsAsync().Wait(); _mutexGc = mutexGc; }
/// <summary> /// Create the table /// </summary> public Task CreateTableAsync() { return(CloudTable.CreateIfNotExistsAsync()); }