Beispiel #1
0
        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}'.");
            }
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteTrack(string name)
        {
            try
            {
                if (!ModelState.TryValidateRequiredParameter(name, nameof(name)))
                {
                    return(BadRequest(ModelState));
                }
                name = name?.ToLower();

                //TODO delete all sub elements
                // Waiting for https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/17296813-add-the-ability-to-delete-all-data-in-a-partition
                //            Add the ability to delete ALL data in a partition
                await tenantRepository.DeleteListAsync <DefaultElement>(new Track.IdKey {
                    TenantName = RouteBinding.TenantName, TrackName = name
                });

                await tenantRepository.DeleteAsync <Track>(await Track.IdFormat(RouteBinding, name));

                return(NoContent());
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Delete '{typeof(Api.Track).Name}' by name '{name}'.");
                    return(NotFound(typeof(Api.Track).Name, name));
                }
                throw;
            }
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteTenant(string name)
        {
            try
            {
                if (!ModelState.TryValidateRequiredParameter(name, nameof(name)))
                {
                    return(BadRequest(ModelState));
                }
                name = name?.ToLower();

                if (name.Equals(Constants.Routes.MasterTenantName, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("The master tenant can not be deleted.");
                }

                var mTracks = await tenantRepository.GetListAsync <Track>(new Track.IdKey {
                    TenantName = name
                }, whereQuery : p => p.DataType.Equals("track"));

                foreach (var mTrack in mTracks)
                {
                    await tenantRepository.DeleteListAsync <DefaultElement>(new Track.IdKey {
                        TenantName = name, TrackName = mTrack.Name
                    });

                    await tenantRepository.DeleteAsync <Track>(mTrack.Id);

                    if (mTrack.Key.Type == TrackKeyType.KeyVaultRenewSelfSigned)
                    {
                        await externalKeyLogic.DeleteExternalKeyAsync(mTrack.Key.ExternalName);
                    }
                }
                var mTenant = await tenantRepository.DeleteAsync <Tenant>(await Tenant.IdFormat(name));

                if (!string.IsNullOrEmpty(mTenant?.CustomDomain))
                {
                    await tenantCacheLogic.InvalidateCustomDomainCacheAsync(mTenant.CustomDomain);
                }

                return(NoContent());
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Delete '{typeof(Api.Tenant).Name}' by name '{name}'.");
                    return(NotFound(typeof(Api.Tenant).Name, name));
                }
                throw;
            }
        }
Beispiel #4
0
        public async Task <IActionResult> DeleteTenant(string name)
        {
            try
            {
                if (!ModelState.TryValidateRequiredParameter(name, nameof(name)))
                {
                    return(BadRequest(ModelState));
                }
                name = name?.ToLower();

                if (name.Equals(Constants.Routes.MasterTenantName, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("The master track can not be deleted.");
                }

                //TODO delete all sub elements
                // Waiting for https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/17296813-add-the-ability-to-delete-all-data-in-a-partition
                //            Add the ability to delete ALL data in a partition
                var mTracks = await tenantRepository.GetListAsync <Track>(new Track.IdKey {
                    TenantName = name
                }, whereQuery : p => p.DataType.Equals("track"));

                foreach (var mTrack in mTracks)
                {
                    await tenantRepository.DeleteListAsync <DefaultElement>(new Track.IdKey {
                        TenantName = name, TrackName = mTrack.Name
                    });

                    await tenantRepository.DeleteAsync <Track>(mTrack.Id);
                }
                await tenantRepository.DeleteAsync <Tenant>(await Tenant.IdFormat(name));

                return(NoContent());
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Delete '{typeof(Api.Tenant).Name}' by name '{name}'.");
                    return(NotFound(typeof(Api.Tenant).Name, name));
                }
                throw;
            }
        }
Beispiel #5
0
        public async Task <IActionResult> DeleteTrack(string name)
        {
            try
            {
                if (!ModelState.TryValidateRequiredParameter(name, nameof(name)))
                {
                    return(BadRequest(ModelState));
                }
                name = name?.ToLower();

                var mTrack = await tenantRepository.GetTrackByNameAsync(new Track.IdKey {
                    TenantName = RouteBinding.TenantName, TrackName = name
                });

                await tenantRepository.DeleteListAsync <DefaultElement>(new Track.IdKey {
                    TenantName = RouteBinding.TenantName, TrackName = name
                });

                await tenantRepository.DeleteAsync <Track>(await Track.IdFormat(RouteBinding, name));

                if (mTrack.Key.Type == TrackKeyType.KeyVaultRenewSelfSigned)
                {
                    await externalKeyLogic.DeleteExternalKeyAsync(mTrack.Key.ExternalName);
                }

                return(NoContent());
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Delete '{typeof(Api.Track).Name}' by name '{name}'.");
                    return(NotFound(typeof(Api.Track).Name, name));
                }
                throw;
            }
        }