public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var resolveResult = _tenantResolver.ResolveTenantIdOrName(); _tenantResolveResultAccessor.Result = resolveResult; TenantConfiguration tenant = null; if (resolveResult.TenantIdOrName != null) { tenant = await FindTenantAsync(resolveResult.TenantIdOrName); if (tenant == null) { throw new BusinessException( code: "PlusIo.MultiTenancy:010001", message: "Tenant not found!", details: "There is no tenant with the tenant id or name: " + resolveResult.TenantIdOrName ); } } using (_currentTenant.Change(tenant?.Id, tenant?.Name)) { await next(context); } }
public bool CreateTenant(string tenantName, TenantSettings tenantSettings) { List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile(); var tenant = tenants.Find(x => x.Name == tenantName); if (tenant != null) { return(false); } var tenantConfiguration = new TenantConfiguration() { Name = tenantName, Settings = tenantSettings }; tenants.Add(tenantConfiguration); if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true) { _tenantRepository.AddTenantFromApi(tenantConfiguration); _storageHubService.CreateTenantAsync(_tenantFactory .CreateTenant(tenantConfiguration.Name, tenantConfiguration.Settings.DigitalSignature, tenantConfiguration.Settings.EnableEncryption, tenantConfiguration.Settings.AllowProductCreation, tenantConfiguration.Settings.EnableAuthorization, tenantConfiguration.Settings.Tokens, tenantConfiguration.Settings.Logging, tenantConfiguration.Settings.EnableGeoReplication, tenantConfiguration.Settings.CertificatePath)); return(true); } return(false); }
protected override void Seed(BacklogContext context) { TenantConfiguration.Seed(context); RoleConfiguration.Seed(context); UserConfiguration.Seed(context); TaskStatusConfiguration.Seed(context); }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var resolveResult = _tenantResolver.ResolveTenantIdOrName(); _tenantResolveResultAccessor.Result = resolveResult; TenantConfiguration tenant = null; if (resolveResult.TenantIdOrName != null) { tenant = await FindTenantAsync(resolveResult.TenantIdOrName); if (tenant == null) { //TODO: A better exception? throw new AbpException( "There is no tenant with given tenant id or name: " + resolveResult.TenantIdOrName ); } } using (_currentTenant.Change(tenant?.Id, tenant?.Name)) { await next(context); } }
public virtual async Task <TenantConfiguration> GetAsync(bool saveResolveResult = false) { var resolveResult = await TenantResolver.ResolveTenantIdOrNameAsync(); if (saveResolveResult) { TenantResolveResultAccessor.Result = resolveResult; } TenantConfiguration tenant = null; if (resolveResult.TenantIdOrName != null) { tenant = await FindTenantAsync(resolveResult.TenantIdOrName); if (tenant == null) { throw new BusinessException( code: "Volo.AbpIo.MultiTenancy:010001", message: "Tenant not found!", details: "There is no tenant with the tenant id or name: " + resolveResult.TenantIdOrName ); } } return(tenant); }
public Message CreateMessage(TenantConfiguration tenantConfiguration, string deviceId, Guid objectId, Random random) { // get telemetry message type according to the configured distribution var messageType = GetMessageType(random.NextDouble(), tenantConfiguration.MessageTypesDistributionPerDevice); return(_messageBuilders[messageType].BuildMessage(tenantConfiguration.Id, deviceId, objectId)); }
/// <summary> /// Get or create a test configuration tenant to use with our tests. /// /// If we're recording, we'll save a sanitized version of the test /// configuarion. If we're playing recorded tests, we'll use the /// serialized test configuration. If we're running the tests live, /// we'll just return the value. /// /// While we cache things internally, DO NOT cache them elsewhere /// because we need each test to have its configuration recorded. /// </summary> /// <param name="name">The name of the session record variable.</param> /// <param name="getTenant"> /// A function to get the tenant. This is wrapped in a Func becuase /// we'll throw Assert.Inconclusive if you try to access a tenant with /// an invalid config file. /// </param> /// <returns>A test tenant to use with our tests.</returns> private TenantConfiguration GetTestConfig(string name, Func <TenantConfiguration> getTenant) { TenantConfiguration config; string text; switch (Mode) { case RecordedTestMode.Playback: if (!_playbackConfigCache.TryGetValue(name, out config)) { text = Recording.GetVariable(name, null); config = TenantConfiguration.Parse(text); _playbackConfigCache[name] = config; } break; case RecordedTestMode.Record: config = getTenant(); if (!_recordingConfigCache.TryGetValue(name, out text)) { text = TenantConfiguration.Serialize(config, true); _recordingConfigCache[name] = text; } Recording.GetVariable(name, text); break; default: config = getTenant(); break; } return(config); }
public static TenantModel ToTenantModel(this TenantConfiguration tenantEntity) { return(new TenantModel { Name = tenantEntity.Name, ConnectionString = tenantEntity.ConnectionString }); }
public TServiceClient GetServiceClientFromOauthConfig( TenantConfiguration config, TServiceClientOptions options = default) => AzureCoreRecordedTestBase.InstrumentClient( _getServiceClientTokenCredential( new Uri(GetEndpoint(config)), Tenants.GetOAuthCredential(config), options ?? GetOptions()));
private BlobServiceClient GetSecondaryReadServiceClient(TenantConfiguration config, int numberOfReadFailuresToSimulate, out TestExceptionPolicy testExceptionPolicy, bool simulate404 = false, List<RequestMethod> enabledRequestMethods = null) { BlobClientOptions options = GetSecondaryStorageOptions(config, out testExceptionPolicy, numberOfReadFailuresToSimulate, simulate404, enabledRequestMethods); return InstrumentClient( new BlobServiceClient( new Uri(config.BlobServiceEndpoint), new StorageSharedKeyCredential(config.AccountName, config.AccountKey), options)); }
public DisposingImmutableStorageWithVersioningContainer( TenantConfiguration tenantConfiguration, BlobContainerClient containerClient, RecordedTestMode recordedTestMode) { _tenantConfiguration = tenantConfiguration; Container = containerClient; _testMode = recordedTestMode; }
protected override string GetTenantConnectionString(TenantConfiguration tenantConfiguration, ISessionFactoryImplementor sessionFactory) { return(tenantConfiguration is TestTenantConfiguration tenant && tenant.IsSqlServerDialect ? new SqlConnectionStringBuilder(sessionFactory.ConnectionProvider.GetConnectionString()) { ApplicationName = tenantConfiguration.TenantIdentifier }.ToString() : sessionFactory.ConnectionProvider.GetConnectionString()); }
public static TenantModel ToTenantModel(this TenantConfiguration tenantEntity) { return(new TenantModel { DomainName = tenantEntity.DomainName, ConnectionString = tenantEntity.ConnectionString, Default = tenantEntity.Default, Name = tenantEntity.Name }); }
private QueueClientOptions getSecondaryStorageOptions(TenantConfiguration config, out TestExceptionPolicy testExceptionPolicy, int numberOfReadFailuresToSimulate = 1, bool simulate404 = false, List <RequestMethod> enabledRequestMethods = null) { QueueClientOptions options = GetOptions(); options.GeoRedundantSecondaryUri = new Uri(config.QueueServiceSecondaryEndpoint); options.Retry.MaxRetries = 4; testExceptionPolicy = new TestExceptionPolicy(numberOfReadFailuresToSimulate, options.GeoRedundantSecondaryUri, simulate404, enabledRequestMethods); options.AddPolicy(testExceptionPolicy, HttpPipelinePosition.PerRetry); return(options); }
private QueueClient GetSecondaryReadQueueClient(TenantConfiguration config, int numberOfReadFailuresToSimulate, out TestExceptionPolicy testExceptionPolicy, bool simulate404 = false, List <RequestMethod> enabledRequestMethods = null) { QueueClientOptions options = getSecondaryStorageOptions(config, out testExceptionPolicy, numberOfReadFailuresToSimulate, simulate404, enabledRequestMethods); return(InstrumentClient( new QueueClient( new Uri(config.QueueServiceEndpoint).AppendToPath(GetNewQueueName()), new StorageSharedKeyCredential(config.AccountName, config.AccountKey), options))); }
protected TokenCredential GetOAuthCredential(TenantConfiguration tenantConfiguration) { return(new ClientSecretCredential( tenantConfiguration.ActiveDirectoryTenantId, tenantConfiguration.ActiveDirectoryApplicationId, tenantConfiguration.ActiveDirectoryApplicationSecret, new TokenCredentialOptions() { AuthorityHost = new Uri(tenantConfiguration.ActiveDirectoryAuthEndpoint) })); }
private BlobServiceClient GetServiceClientFromOauthConfig(TenantConfiguration config, bool enableTenantDiscovery) { var options = BlobsClientBuilder.GetOptions(); options.EnableTenantDiscovery = enableTenantDiscovery; return(InstrumentClient( new BlobServiceClient( new Uri(config.BlobServiceEndpoint), Tenants.GetOAuthCredential(config), options))); }
private BlobContainerClient GetSecondaryReadBlobContainerClient(TenantConfiguration config, int numberOfReadFailuresToSimulate, out TestExceptionPolicy testExceptionPolicy, bool simulate404 = false, List <RequestMethod> enabledRequestMethods = null) { BlobClientOptions options = GetSecondaryStorageOptions(config, out testExceptionPolicy, numberOfReadFailuresToSimulate, simulate404, enabledRequestMethods); Uri uri = new Uri(config.BlobServiceEndpoint); string containerName = BlobsClientBuilder.GetNewContainerName(); return(InstrumentClient( new BlobContainerClient( uri.AppendToPath(containerName), new StorageSharedKeyCredential(config.AccountName, config.AccountKey), options))); }
public virtual void Set(TenantConfiguration tenant) { var existingTenant = Find(tenant.Id); if (existingTenant != null) { existingTenant.Name = tenant.Name; return; } CachedTenants.Add(tenant); }
private async Task <BlobServiceClient> GetServiceClientFromOauthConfig(TenantConfiguration config) { var initalToken = await this.GenerateOAuthToken( config.ActiveDirectoryAuthEndpoint, config.ActiveDirectoryTenantId, config.ActiveDirectoryApplicationId, config.ActiveDirectoryApplicationSecret); return(this.InstrumentClient( new BlobServiceClient( new Uri(config.BlobServiceEndpoint), this.GetOptions(new TokenCredentials(initalToken))))); }
public BlobServiceClient GetSecondaryStorageReadEnabledServiceClient(TenantConfiguration config, int numberOfReadFailuresToSimulate, bool simulate404 = false) { BlobClientOptions options = GetBlobOptions(); options.GeoRedundantSecondaryUri = new Uri(config.BlobServiceSecondaryEndpoint); options.Retry.MaxRetries = 4; options.AddPolicy(new TestExceptionPolicy(numberOfReadFailuresToSimulate, options.GeoRedundantSecondaryUri, simulate404), HttpPipelinePosition.PerRetry); return(InstrumentClient( new BlobServiceClient( new Uri(config.BlobServiceEndpoint), new StorageSharedKeyCredential(config.AccountName, config.AccountKey), options))); }
private void ShowTenantConfiguration() { var serverDto = GetServerDto(); ActionHelper.Execute(delegate { var tenantName = DisplayName; var frm = new TenantConfiguration(serverDto, tenantName); if (this.SnapIn.Console.ShowDialog(frm) == DialogResult.OK) { // do nothing } }, null); }
public async Task <TenantConfiguration> GetConfig(string tenant) { TenantConfiguration tenantConfig = null; var to = TableOperation.Retrieve <ServiceConfig>(_environment, tenant); var response = await _table.ExecuteAsync(to); if (response.Result != null) { var entity = response.Result as ServiceConfig; tenantConfig = JsonConvert.DeserializeObject <TenantConfiguration>(entity.Value); } return(tenantConfig); }
public async Task <TenantConfiguration> CreateApi(string api, string description) { var config = await TenantConfiguration.FirstOrDefaultAsync(q => q.Name == api); if (config == null) { config = new TenantConfiguration { Name = api, Description = description, }; await TenantConfiguration.AddAsync(config); } return(config); }
public Form1() { InitializeComponent(); try { XElement element = XElement.Load(TestConfigurations.DefaultTestConfigFilePath); this.configurations = TestConfigurations.ReadFromXml(element); this.defaultTenantConfiguration = this.configurations.TenantConfigurations.Single(c => c.TenantName == this.configurations.TargetTenantName); } catch (System.IO.FileNotFoundException) { throw new System.IO.FileNotFoundException("To run tests you need to supply a TestConfigurations.xml file with credentials in the Test/Common folder. Use TestConfigurationsTemplate.xml as a template."); } }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { TenantConfiguration tenant = null; try { tenant = await _tenantConfigurationProvider.GetAsync(saveResolveResult : true); } catch (Exception e) { if (await _options.MultiTenancyMiddlewareErrorPageBuilder(context, e)) { return; } } if (tenant?.Id != _currentTenant.Id) { using (_currentTenant.Change(tenant?.Id, tenant?.Name)) { if (_tenantResolveResultAccessor.Result != null && _tenantResolveResultAccessor.Result.AppliedResolvers.Contains(QueryStringTenantResolveContributor.ContributorName)) { AbpMultiTenancyCookieHelper.SetTenantCookie(context, _currentTenant.Id, _options.TenantKey); } var requestCulture = await TryGetRequestCultureAsync(context); if (requestCulture != null) { CultureInfo.CurrentCulture = requestCulture.Culture; CultureInfo.CurrentUICulture = requestCulture.UICulture; AbpRequestCultureCookieHelper.SetCultureCookie( context, requestCulture ); context.Items[AbpRequestLocalizationMiddleware.HttpContextItemName] = true; } await next(context); } } else { await next(context); } }
public override async Task ValidateAsync(CookieValidatePrincipalContext context) { TenantConfiguration tenant = null; try { tenant = await TenantConfigurationProvider.GetAsync(saveResolveResult : false); } catch (Exception e) { Logger.LogException(e); } using (CurrentTenant.Change(tenant?.Id, tenant?.Name)) { await base.ValidateAsync(context); } }
public static void Seed(AppDbContext context, IConfiguration configuration) { TenantConfiguration.Seed(context, configuration); CardConfiguration.Seed(context); CardLayoutConfiguration.Seed(context); UserConfiguration.Seed(context, configuration); TaxConfiguration.Seed(context); DriverConfiguration.Seed(context, configuration); ProductConfiguration.Seed(context); WarehouseConfiguration.Seed(context); InventoryItemConfiguration.Seed(context); HtmlContentConfiguration.Seed(context); DigitalAssetConfiguration.Seed(context); EmailTemplateConfiguration.Seed(context); VideoConfiguration.Seed(context); ProfessionalServiceProviderConfiguration.Seed(context); //DashboardConfiguration.Seed(context); }
public void Save(TenantConfiguration configuration) { var entity = new DynamicTableEntity(configuration.Tenant, configuration.Tenant); foreach( var property in _properties ) { var value = property.GetValue(configuration); var valueAsString = string.Empty; if (value != null) { if (property.PropertyType.IsConcept()) value = value.GetConceptValue(); valueAsString = value.ToString(); } entity.Properties.Add(property.Name, new EntityProperty(valueAsString)); } var operation = TableOperation.InsertOrReplace(entity); _table.Execute(operation); }
public async Task <string> GetAuthToken(string[] scopes = default, TenantConfiguration tenantConfiguration = default) { if (Mode == RecordedTestMode.Playback) { return("auth token"); } tenantConfiguration ??= Tenants.TestConfigOAuth; IConfidentialClientApplication application = ConfidentialClientApplicationBuilder.Create(tenantConfiguration.ActiveDirectoryApplicationId) .WithAuthority(AzureCloudInstance.AzurePublic, tenantConfiguration.ActiveDirectoryTenantId) .WithClientSecret(tenantConfiguration.ActiveDirectoryApplicationSecret) .Build(); scopes ??= new string[] { "https://storage.azure.com/.default" }; AcquireTokenForClientParameterBuilder result = application.AcquireTokenForClient(scopes); AuthenticationResult authenticationResult = await result.ExecuteAsync(); return(authenticationResult.AccessToken); }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var resolveResult = tenantResolver.ResolveTenantIdOrName(); TenantConfiguration tenant = null; if (resolveResult.TenantIdOrName != null) { tenant = await FindTenantAsync(resolveResult.TenantIdOrName); if (tenant == null) { throw new StructureException("There is no tenant with given tenant id or name: " + resolveResult.TenantIdOrName); } } using (currentTenant.Change(tenant?.Id, tenant?.Name)) { await next(context); } }
TenantConfiguration Map(DynamicTableEntity entity) { var configuration = new TenantConfiguration(); foreach (var property in _properties ) { if (entity.Properties.ContainsKey(property.Name)) { var targetType = property.PropertyType; var value = entity.Properties[property.Name].StringValue; if (targetType.IsConcept()) property.SetValue(configuration, ConceptFactory.CreateConceptInstance(targetType, value)); else property.SetValue(configuration, Convert.ChangeType(value, targetType)); } } return configuration; }