protected override Track.IdKey GetTrackIdKey(string[] route, bool hasCustomDomain) { var trackIdKey = new Track.IdKey(); trackIdKey.TrackName = Constants.Routes.MasterTrackName; if (route.Length >= 2 && route[0].Equals(Constants.Routes.MasterApiName, StringComparison.InvariantCultureIgnoreCase) && route[1].StartsWith(Constants.Routes.PreApikey, StringComparison.InvariantCulture)) { trackIdKey.TenantName = Constants.Routes.MasterTenantName; } else if (route.Length >= 2 && route[1].StartsWith(Constants.Routes.PreApikey, StringComparison.InvariantCulture)) { trackIdKey.TenantName = route[0].ToLower(); } else if (route.Length >= 3 && route[2].StartsWith(Constants.Routes.PreApikey, StringComparison.InvariantCulture)) { trackIdKey.TenantName = route[0].ToLower(); trackIdKey.TrackName = route[1].ToLower(); } else { throw new NotSupportedException($"FoxIDs API route '{string.Join('/', route)}' not supported."); } return(trackIdKey); }
public async Task <HashSet <T> > GetListAsync <T>(Track.IdKey idKey = null, Expression <Func <T, bool> > whereQuery = null, int maxItemCount = 20) where T : IDataDocument { var partitionId = PartitionIdFormat <T>(idKey); var orderedQueryable = GetQueryAsync <T>(partitionId, maxItemCount: maxItemCount); var query = (whereQuery == null) ? orderedQueryable.AsDocumentQuery() : orderedQueryable.Where(whereQuery).AsDocumentQuery(); double totalRU = 0; try { var response = await query.ExecuteNextAsync <T>(); totalRU += response.RequestCharge; var items = response.ToHashSet(); await items.ValidateObjectAsync(); return(items); } catch (Exception ex) { throw new CosmosDataException(ex); } finally { var scopedLogger = httpContextAccessor.HttpContext.RequestServices.GetService <TelemetryScopedLogger>(); scopedLogger.ScopeMetric($"CosmosDB RU, tenant - read list (maxItemCount: {maxItemCount}) by query of type '{typeof(T)}'.", totalRU); } }
public async Task DeleteRefreshTokenGrantsAsync(string sessionId) { if (sessionId.IsNullOrWhiteSpace()) { return; } logger.ScopeTrace($"Delete Refresh Token grants, Route '{RouteBinding.Route}', Session ID '{sessionId}'."); var idKey = new Track.IdKey { TenantName = RouteBinding.TenantName, TrackName = RouteBinding.TrackName }; var ttlGrantCount = await tenantRepository.DeleteListAsync <RefreshTokenTtlGrant>(idKey, d => d.SessionId == sessionId); if (ttlGrantCount > 0) { logger.ScopeTrace($"TTL Refresh Token grants deleted, Session ID '{sessionId}'."); } var grantCount = await tenantRepository.DeleteListAsync <RefreshTokenGrant>(idKey, d => d.SessionId == sessionId); if (grantCount > 0) { logger.ScopeTrace($"Refresh Token grants deleted, Session ID '{sessionId}'."); } }
public async Task <ActionResult <HashSet <Api.User> > > GetFilterUser(string filterEmail) { try { var idKey = new Track.IdKey { TenantName = RouteBinding.TenantName, TrackName = RouteBinding.TrackName, }; var mUsers = filterEmail.IsNullOrWhiteSpace() ? await tenantRepository.GetListAsync <User>(idKey, whereQuery : u => u.DataType.Equals(dataType)) : await tenantRepository.GetListAsync <User>(idKey, whereQuery : u => u.DataType.Equals(dataType) && u.Email.Contains(filterEmail)); var aUsers = new HashSet <Api.User>(mUsers.Count()); foreach (var mUser in mUsers.OrderBy(t => t.Email)) { aUsers.Add(mapper.Map <Api.User>(mUser)); } return(Ok(aUsers)); } catch (CosmosDataException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { logger.Warning(ex, $"NotFound, Get '{typeof(Api.User).Name}' by filter email '{filterEmail}'."); return(NotFound(typeof(Api.User).Name, filterEmail)); } throw; } }
public async Task <HashSet <T> > GetListAsync <T>(Track.IdKey idKey = null, Expression <Func <T, bool> > whereQuery = null, int maxItemCount = 50) where T : IDataDocument { var partitionId = PartitionIdFormat <T>(idKey); var query = GetQueryAsync <T>(partitionId, maxItemCount: maxItemCount); var setIterator = (whereQuery == null) ? query.ToFeedIterator() : query.Where(whereQuery).ToFeedIterator(); double totalRU = 0; try { var response = await setIterator.ReadNextAsync(); totalRU += response.RequestCharge; var items = response.ToHashSet(); await items.ValidateObjectAsync(); return(items); } catch (Exception ex) { throw new CosmosDataException(ex); } finally { var scopedLogger = GetScopedLogger(); scopedLogger.ScopeMetric(metric => { metric.Message = $"CosmosDB RU, tenant - read list (maxItemCount: {maxItemCount}) by query of type '{typeof(T)}'."; metric.Value = totalRU; }, properties: GetProperties()); } }
public async Task DeleteRefreshTokenGrantAsync(TClient client, string sessionId) { if (sessionId.IsNullOrWhiteSpace()) { return; } logger.ScopeTrace($"Delete Refresh Token grant, Route '{RouteBinding.Route}', Session ID '{sessionId}'."); var idKey = new Track.IdKey { TenantName = RouteBinding.TenantName, TrackName = RouteBinding.TrackName }; await idKey.ValidateObjectAsync(); RefreshTokenGrant grant = await tenantRepository.DeleteAsync <RefreshTokenTtlGrant>(idKey, d => d.SessionId == sessionId); if (grant != null) { logger.ScopeTrace($"TTL Refresh Token grant deleted, Refresh Token '{grant.RefreshToken}', Session ID '{sessionId}'."); } else { grant = await tenantRepository.DeleteAsync <RefreshTokenGrant>(idKey, d => d.SessionId == sessionId); if (grant != null) { logger.ScopeTrace($"Refresh Token grant deleted, Refresh Token '{grant.RefreshToken}', Session ID '{sessionId}'."); } } }
public async Task <ActionResult <HashSet <Api.Track> > > GetFilterTrack(string filterName) { try { var idKey = new Track.IdKey { TenantName = RouteBinding.TenantName, TrackName = RouteBinding.TrackName }; var mTracks = filterName.IsNullOrWhiteSpace() ? await tenantRepository.GetListAsync <Track>(idKey, whereQuery : p => p.DataType.Equals(dataType)) : await tenantRepository.GetListAsync <Track>(idKey, whereQuery : p => p.DataType.Equals(dataType) && p.Name.Contains(filterName)); var aTracks = new HashSet <Api.Track>(mTracks.Count()); foreach (var mTrack in mTracks.OrderBy(t => t.Name)) { aTracks.Add(mapper.Map <Api.Track>(mTrack)); } return(Ok(aTracks)); } catch (CosmosDataException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { logger.Warning(ex, $"NotFound, Get '{typeof(Api.Track).Name}' by filter name '{filterName}'."); return(NotFound(typeof(Api.Track).Name, filterName)); } throw; } }
public async Task <ActionResult <HashSet <Api.DownParty> > > GetFilterDownParty(string filterName) { try { var doFilterPartyType = Enum.TryParse <PartyTypes>(filterName, out var filterPartyType); var idKey = new Track.IdKey { TenantName = RouteBinding.TenantName, TrackName = RouteBinding.TrackName }; var mDownPartys = filterName.IsNullOrWhiteSpace() ? await tenantRepository.GetListAsync <DownParty>(idKey, whereQuery : p => p.DataType.Equals(dataType)) : await tenantRepository.GetListAsync <DownParty>(idKey, whereQuery : p => p.DataType.Equals(dataType) && (p.Name.Contains(filterName) || (doFilterPartyType && p.Type == filterPartyType))); var aDownPartys = new HashSet <Api.DownParty>(mDownPartys.Count()); foreach (var mDownParty in mDownPartys.OrderBy(p => p.Name)) { aDownPartys.Add(mapper.Map <Api.DownParty>(mDownParty)); } return(Ok(aDownPartys)); } catch (CosmosDataException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { logger.Warning(ex, $"NotFound, Get '{typeof(Api.DownParty).Name}' by filter name '{filterName}'."); return(NotFound(typeof(Api.DownParty).Name, filterName)); } throw; } }
public async Task <Track> GetTrackByNameAsync(Track.IdKey idKey, bool required = true) { if (idKey == null) { new ArgumentNullException(nameof(idKey)); } return(await ReadItemAsync <Track>(await Track.IdFormat(idKey), Track.PartitionIdFormat(idKey), required)); }
private async Task <Track> GetTrackAsync(ITenantRepository tenantRepository, Track.IdKey idKey) { try { return(await tenantRepository.GetTrackByNameAsync(idKey)); } catch (Exception ex) { throw new RouteCreationException($"Invalid tenantName '{idKey.TenantName}' and trackName '{idKey.TrackName}'.", ex); } }
private async Task <Track> GetTrackAsync(Track.IdKey idKey, bool hasCustomDomain) { try { return(await tenantRepository.GetTrackByNameAsync(idKey)); } catch (Exception ex) { if (hasCustomDomain && idKey.TenantName.Equals(idKey.TrackName, StringComparison.OrdinalIgnoreCase)) { throw new RouteCreationException($"Invalid tenant and track name '{idKey.TenantName}'. The URL for a custom domain has to be without the tenant element.", ex); } throw new RouteCreationException($"Invalid tenant name '{idKey.TenantName}' and track name '{idKey.TrackName}'.", ex); } }
public async Task <int> DeleteListAsync <T>(Track.IdKey idKey, Expression <Func <T, bool> > whereQuery = null) where T : IDataDocument { if (idKey == null) { new ArgumentNullException(nameof(idKey)); } await idKey.ValidateObjectAsync(); var partitionId = PartitionIdFormat <T>(idKey); var orderedQueryable = GetQueryAsync <T>(partitionId, -1); var query = (whereQuery == null) ? orderedQueryable.AsDocumentQuery() : orderedQueryable.Where(whereQuery).AsDocumentQuery(); double totalRU = 0; try { var response = await query.ExecuteNextAsync <T>(); totalRU += response.RequestCharge; var li = response.ToHashSet(); var count = 0; foreach (var item in li) { var requestOptions = new RequestOptions { PartitionKey = new PartitionKey(partitionId) }; var deleteResponse = await client.DeleteDocumentAsync(GetDocumentLink <T>(item.Id), requestOptions); count++; totalRU += deleteResponse.RequestCharge; } return(count); } catch (Exception ex) { throw new CosmosDataException(partitionId, ex); } finally { var scopedLogger = httpContextAccessor.HttpContext.RequestServices.GetService <TelemetryScopedLogger>(); scopedLogger.ScopeMetric($"CosmosDB RU, tenant - delete list type '{typeof(T)}'.", totalRU); } }
public async Task <T> DeleteAsync <T>(Track.IdKey idKey, Expression <Func <T, bool> > whereQuery) where T : IDataDocument { if (idKey == null) { new ArgumentNullException(nameof(idKey)); } await idKey.ValidateObjectAsync(); var partitionId = DataDocument.PartitionIdFormat(idKey); var query = GetQueryAsync <T>(partitionId).Where(whereQuery).AsDocumentQuery(); double totalRU = 0; try { var response = await query.ExecuteNextAsync <T>(); totalRU += response.RequestCharge; var item = response.FirstOrDefault(); if (item != null) { var requestOptions = new RequestOptions { PartitionKey = new PartitionKey(partitionId) }; var deleteResponse = await client.DeleteDocumentAsync(GetDocumentLink <T>(item.Id), requestOptions); totalRU += deleteResponse.RequestCharge; } await item.ValidateObjectAsync(); return(item); } catch (Exception ex) { throw new CosmosDataException(partitionId, ex); } finally { var scopedLogger = httpContextAccessor.HttpContext.RequestServices.GetService <TelemetryScopedLogger>(); scopedLogger.ScopeMetric($"CosmosDB RU, tenant - delete type '{typeof(T)}'.", totalRU); } }
public async Task <int> DeleteListAsync <T>(Track.IdKey idKey, Expression <Func <T, bool> > whereQuery = null) where T : IDataDocument { if (idKey == null) { new ArgumentNullException(nameof(idKey)); } await idKey.ValidateObjectAsync(); var partitionId = PartitionIdFormat <T>(idKey); var query = GetQueryAsync <T>(partitionId, -1); var setIterator = (whereQuery == null) ? query.ToFeedIterator() : query.Where(whereQuery).ToFeedIterator(); double totalRU = 0; try { var response = await setIterator.ReadNextAsync(); totalRU += response.RequestCharge; var items = response.ToHashSet(); var count = 0; var container = GetContainer <T>(); foreach (var item in items) { var deleteResponse = await container.DeleteItemAsync <T>(item.Id, new PartitionKey(partitionId)); count++; totalRU += deleteResponse.RequestCharge; } return(count); } catch (Exception ex) { throw new CosmosDataException(partitionId, ex); } finally { var scopedLogger = GetScopedLogger(); scopedLogger.ScopeMetric(metric => { metric.Message = $"CosmosDB RU, tenant - delete list type '{typeof(T)}'."; metric.Value = totalRU; }, properties: GetProperties()); } }
private string PartitionIdFormat <T>(Track.IdKey idKey) where T : IDataDocument { if (typeof(T).Equals(typeof(Tenant))) { return(Tenant.PartitionIdFormat()); } else if (typeof(T).Equals(typeof(Track))) { if (idKey == null) { new ArgumentNullException(nameof(idKey)); } return(Track.PartitionIdFormat(idKey)); } else { if (idKey == null) { new ArgumentNullException(nameof(idKey)); } return(DataDocument.PartitionIdFormat(idKey)); } }
public Task <Track> GetTrackByNameAsync(Track.IdKey idKey, bool requered = true) { throw new NotImplementedException(); }
private async Task <RouteTrackKey> LoadTrackKeyAsync(IServiceProvider requestServices, Track.IdKey trackIdKey, Track track) { switch (track.Key.Type) { case TrackKeyType.Contained: return(new RouteTrackKey { Type = track.Key.Type, PrimaryKey = new RouteTrackKeyItem { Key = track.Key.Keys[0].Key }, SecondaryKey = track.Key.Keys.Count > 1 ? new RouteTrackKeyItem { Key = track.Key.Keys[1].Key } : null, }); case TrackKeyType.KeyVaultRenewSelfSigned: var trackKeyExternal = await GetTrackKeyItemsAsync(trackIdKey.TenantName, trackIdKey.TrackName, track); return(new RouteTrackKey { Type = track.Key.Type, ExternalName = track.Key.ExternalName, PrimaryKey = new RouteTrackKeyItem { ExternalId = trackKeyExternal.Keys[0].ExternalId, Key = trackKeyExternal.Keys[0].Key }, SecondaryKey = trackKeyExternal.Keys.Count > 1 ? new RouteTrackKeyItem { ExternalId = trackKeyExternal.Keys[1].ExternalId, Key = trackKeyExternal.Keys[1].Key } : null, }); case TrackKeyType.KeyVaultUpload: default: throw new Exception($"Track key type not supported '{track.Key.Type}'."); } }
private async Task <RouteBinding> GetRouteDataAsync(TelemetryScopedLogger scopedLogger, IServiceProvider requestServices, Track.IdKey trackIdKey, bool hasCustomDomain, string customDomain, string partyNameAndBinding, bool acceptUnknownParty) { if (hasCustomDomain) { var tenantCacheLogic = requestServices.GetService <TenantCacheLogic>(); trackIdKey.TenantName = await tenantCacheLogic.GetTenantNameByCustomDomain(customDomain); } var track = await GetTrackAsync(trackIdKey, hasCustomDomain); scopedLogger.SetScopeProperty(Constants.Logs.TenantName, trackIdKey.TenantName); scopedLogger.SetScopeProperty(Constants.Logs.TrackName, trackIdKey.TrackName); var routeBinding = new RouteBinding { HasCustomDomain = hasCustomDomain, RouteUrl = $"{(!hasCustomDomain ? $"{trackIdKey.TenantName}/" : string.Empty)}{trackIdKey.TrackName}{(!partyNameAndBinding.IsNullOrWhiteSpace() ? $"/{partyNameAndBinding}" : string.Empty)}", TenantName = trackIdKey.TenantName, TrackName = trackIdKey.TrackName, Resources = track.Resources, }; return(await PostRouteDataAsync(scopedLogger, requestServices, trackIdKey, track, routeBinding, partyNameAndBinding, acceptUnknownParty)); }
protected virtual ValueTask <RouteBinding> PostRouteDataAsync(TelemetryScopedLogger scopedLogger, IServiceProvider requestServices, Track.IdKey trackIdKey, Track track, RouteBinding routeBinding, string partyNameAndBinding, bool acceptUnknownParty) => new ValueTask <RouteBinding>(routeBinding);
private async Task <UpParty> GetUpPartyAsync(ITenantRepository tenantRepository, Track.IdKey trackIdKey, Group upPartyGroup) { var upPartyIdKey = new Party.IdKey { TenantName = trackIdKey.TenantName, TrackName = trackIdKey.TrackName, PartyName = upPartyGroup.Value, }; try { return(await tenantRepository.GetUpPartyByNameAsync(upPartyIdKey)); } catch (Exception ex) { throw new RouteCreationException($"Invalid tenantName '{upPartyIdKey.TenantName}', trackName '{upPartyIdKey.TrackName}' and upPartyName '{upPartyIdKey.PartyName}'.", ex); } }
private async Task <DownParty> GetDownPartyAsync(ITenantRepository tenantRepository, Track.IdKey trackIdKey, Group downPartyGroup, bool acceptUnknownParty) { var downPartyIdKey = new Party.IdKey { TenantName = trackIdKey.TenantName, TrackName = trackIdKey.TrackName, PartyName = downPartyGroup.Value, }; try { return(await tenantRepository.GetDownPartyByNameAsync(downPartyIdKey, required : !acceptUnknownParty)); } catch (Exception ex) { throw new RouteCreationException($"Invalid tenantName '{downPartyIdKey.TenantName}', trackName '{downPartyIdKey.TrackName}' and downPartyName '{downPartyIdKey.PartyName}'.", ex); } }
private async Task <RouteBinding> GetRouteDataAsync(TelemetryScopedLogger scopedLogger, IServiceProvider requestServices, Track.IdKey trackIdKey, string partyNameAndBinding, bool acceptUnknownParty) { var track = await GetTrackAsync(tenantRepository, trackIdKey); var routeBinding = new RouteBinding { RouteUrl = $"{trackIdKey.TenantName}/{trackIdKey.TrackName}{(!partyNameAndBinding.IsNullOrWhiteSpace() ? $"/{partyNameAndBinding}" : string.Empty)}", TenantName = trackIdKey.TenantName, TrackName = trackIdKey.TrackName, Resources = track.Resources, }; return(await PostRouteDataAsync(scopedLogger, requestServices, trackIdKey, track, routeBinding, partyNameAndBinding, acceptUnknownParty)); }
private async Task <RouteTrackKey> LoadTrackKeyAsync(TelemetryScopedLogger scopedLogger, Track.IdKey trackIdKey, Track track) { switch (track.Key.Type) { case TrackKeyType.Contained: return(new RouteTrackKey { Type = track.Key.Type, PrimaryKey = new RouteTrackKeyItem { Key = track.Key.Keys[0].Key }, SecondaryKey = track.Key.Keys.Count > 1 ? new RouteTrackKeyItem { Key = track.Key.Keys[1].Key } : null, }); case TrackKeyType.KeyVaultRenewSelfSigned: var trackKeyExternal = await GetTrackKeyItemsAsync(scopedLogger, trackIdKey.TenantName, trackIdKey.TrackName, track); var externalRouteTrackKey = new RouteTrackKey { Type = track.Key.Type, ExternalName = track.Key.ExternalName, }; if (trackKeyExternal == null) { externalRouteTrackKey.PrimaryKey = new RouteTrackKeyItem { ExternalKeyIsNotReady = true }; } else { externalRouteTrackKey.PrimaryKey = new RouteTrackKeyItem { ExternalId = trackKeyExternal.Keys[0].ExternalId, Key = trackKeyExternal.Keys[0].Key }; externalRouteTrackKey.SecondaryKey = trackKeyExternal.Keys.Count > 1 ? new RouteTrackKeyItem { ExternalId = trackKeyExternal.Keys[1].ExternalId, Key = trackKeyExternal.Keys[1].Key } : null; } return(externalRouteTrackKey); case TrackKeyType.KeyVaultUpload: default: throw new Exception($"Track key type not supported '{track.Key.Type}'."); } }
private async Task <List <UpPartyLink> > GetAllowedToUpPartyIds(TelemetryScopedLogger scopedLogger, Track.IdKey trackIdKey, Group toUpPartyGroup, DownParty downParty) { var toUpParties = new List <UpPartyLink>(); if (toUpPartyGroup.Captures.Count > 5) { throw new ArgumentException($"More then 5 to up-party for down-party '{downParty.Id}'."); } foreach (Capture upPartyCapture in toUpPartyGroup.Captures) { var toUpPartyIdKey = new Party.IdKey { TenantName = trackIdKey.TenantName, TrackName = trackIdKey.TrackName, PartyName = upPartyCapture.Value, }; await toUpPartyIdKey.ValidateObjectAsync(); var allowUpParty = downParty.AllowUpParties.Where(ap => ap.Name == toUpPartyIdKey.PartyName).SingleOrDefault(); if (allowUpParty != null) { toUpParties.Add(allowUpParty); } else { try { throw new ArgumentException($"Up-party name '{toUpPartyIdKey.PartyName}' not allowed for down-party '{downParty.Id}',"); } catch (Exception ex) { scopedLogger.Warning(ex); } } } if (toUpParties.Count() > 1) { throw new NotSupportedException("Currently only 0 and 1 to up-party is supported."); } return(toUpParties); }
protected override async ValueTask <RouteBinding> PostRouteDataAsync(TelemetryScopedLogger scopedLogger, IServiceProvider requestServices, Track.IdKey trackIdKey, Track track, RouteBinding routeBinding, string partyNameAndBinding, bool acceptUnknownParty) { routeBinding.PartyNameAndBinding = partyNameAndBinding; routeBinding.Key = await LoadTrackKeyAsync(requestServices, trackIdKey, track); routeBinding.ClaimMappings = track.ClaimMappings; routeBinding.SequenceLifetime = track.SequenceLifetime; routeBinding.MaxFailingLogins = track.MaxFailingLogins; routeBinding.FailingLoginCountLifetime = track.FailingLoginCountLifetime; routeBinding.FailingLoginObservationPeriod = track.FailingLoginObservationPeriod; routeBinding.PasswordLength = track.PasswordLength; routeBinding.CheckPasswordComplexity = track.CheckPasswordComplexity.Value; routeBinding.CheckPasswordRisk = track.CheckPasswordRisk.Value; routeBinding.AllowIframeOnDomains = track.AllowIframeOnDomains; routeBinding.SendEmail = track.SendEmail; if (!partyNameAndBinding.IsNullOrWhiteSpace()) { var partyNameBindingMatch = partyNameBindingRegex.Match(partyNameAndBinding); if (!partyNameBindingMatch.Success) { throw new ArgumentException($"Invalid party name and binding match. PartyNameAndBinding '{partyNameAndBinding}'"); } if (partyNameBindingMatch.Groups["upparty"].Success) { routeBinding.UpParty = await GetUpPartyAsync(tenantRepository, trackIdKey, partyNameBindingMatch.Groups["upparty"]); } else if (partyNameBindingMatch.Groups["downparty"].Success) { routeBinding.DownParty = await GetDownPartyAsync(tenantRepository, trackIdKey, partyNameBindingMatch.Groups["downparty"], acceptUnknownParty); if (routeBinding.DownParty?.AllowUpParties?.Count() >= 1) { if (partyNameBindingMatch.Groups["toupparty"].Success) { routeBinding.ToUpParties = await GetAllowedToUpPartyIds(scopedLogger, trackIdKey, partyNameBindingMatch.Groups["toupparty"], routeBinding.DownParty); } else { routeBinding.ToUpParties = routeBinding.DownParty.AllowUpParties.Take(1).ToList(); routeBinding.DefaultToUpParties = true; } } } else { throw new ArgumentException($"Invalid party name and binding group match. PartyNameAndBinding '{partyNameAndBinding}'"); } } return(routeBinding); }
public Task <HashSet <T> > GetListAsync <T>(Track.IdKey idKey = null, Expression <Func <T, bool> > whereQuery = null, int maxItemCount = 10) where T : IDataDocument { throw new NotImplementedException(); }
private async Task <RouteBinding> GetRouteDataAsync(TelemetryScopedLogger scopedLogger, Track.IdKey trackIdKey, string partyNameAndBinding = null) { var track = await GetTrackAsync(tenantRepository, trackIdKey); var routeBinding = new RouteBinding { RouteUrl = $"{trackIdKey.TenantName}{$"/{trackIdKey.TrackName}{(!partyNameAndBinding.IsNullOrWhiteSpace() ? $"/{partyNameAndBinding}" : string.Empty)}"}", TenantName = trackIdKey.TenantName, TrackName = trackIdKey.TrackName, PartyNameAndBinding = partyNameAndBinding, PrimaryKey = track.PrimaryKey, SecondaryKey = track.SecondaryKey, ClaimMappings = track.ClaimMappings, Resources = track.Resources, SequenceLifetime = track.SequenceLifetime, PasswordLength = track.PasswordLength, CheckPasswordComplexity = track.CheckPasswordComplexity.Value, CheckPasswordRisk = track.CheckPasswordRisk.Value, AllowIframeOnDomains = track.AllowIframeOnDomains }; if (!partyNameAndBinding.IsNullOrWhiteSpace()) { var partyNameBindingMatch = partyNameBindingRegex.Match(partyNameAndBinding); if (!partyNameBindingMatch.Success) { throw new ArgumentException($"Invalid party name and binding match. PartyNameAndBinding '{partyNameAndBinding}'"); } if (partyNameBindingMatch.Groups["upparty"].Success) { routeBinding.UpParty = await GetUpPartyAsync(tenantRepository, trackIdKey, partyNameBindingMatch.Groups["upparty"]); } else if (partyNameBindingMatch.Groups["downparty"].Success) { routeBinding.DownParty = await GetDownPartyAsync(tenantRepository, trackIdKey, partyNameBindingMatch.Groups["downparty"]); if (routeBinding.DownParty.AllowUpParties?.Count() >= 1) { if (partyNameBindingMatch.Groups["toupparty"].Success) { routeBinding.ToUpParties = await GetAllowedToUpPartyIds(scopedLogger, trackIdKey, partyNameBindingMatch.Groups["toupparty"], routeBinding.DownParty); } else { routeBinding.ToUpParties = routeBinding.DownParty.AllowUpParties.Take(1).ToList(); } } } else { throw new ArgumentException($"Invalid party name and binding group match. PartyNameAndBinding '{partyNameAndBinding}'"); } } return(routeBinding); }
public Task <T> DeleteAsync <T>(Track.IdKey idKey, Expression <Func <T, bool> > whereQuery) where T : IDataDocument { throw new NotImplementedException(); }
protected override ValueTask <RouteBinding> PostRouteDataAsync(TelemetryScopedLogger scopedLogger, IServiceProvider requestServices, Track.IdKey trackIdKey, Track track, RouteBinding routeBinding, string partyNameAndBinding, bool acceptUnknownParty) { routeBinding.PasswordLength = track.PasswordLength; routeBinding.CheckPasswordComplexity = track.CheckPasswordComplexity.Value; routeBinding.CheckPasswordRisk = track.CheckPasswordRisk.Value; routeBinding.Logging = track.Logging; return(new ValueTask <RouteBinding>(routeBinding)); }