Ejemplo n.º 1
0
        public string LoggedUserBucketKey(string userId, string userHashParam = null)
        {
            // an OSS bucket must have a unique name, so it should be generated in a way,
            // so it a Forge user gets registered into several deployments it will not cause
            // name collisions. So use client ID (as a salt) to generate bucket name.
            var userHash = userHashParam == null?Crypto.GenerateHashString(_forgeConfiguration.ClientId + userId) : userHashParam;

            return($"{_bucketPrefixProvider.GetBucketPrefix()}-{userId.Substring(0, 3)}-{userHash}".ToLowerInvariant());
        }
Ejemplo n.º 2
0
        public async Task ScanBuckets(List <MigrationJob> adoptJobs, List <MigrationJob> configJobs)
        {
            string        suffixFrom     = _configuration.GetValue <string>("BucketKeySuffixOld");
            string        bucketKeyStart = _bucketPrefix.GetBucketPrefix(suffixFrom);
            List <string> bucketKeys     = await _forgeOSS.GetBucketsAsync();

            string AnonymousBucketKeyOld = _resourceProvider.AnonymousBucketKey(suffixFrom);

            foreach (string bucketKey in bucketKeys)
            {
                if (bucketKey.StartsWith(bucketKeyStart) ||
                    bucketKey == AnonymousBucketKeyOld
                    )
                {
                    await ScanBucket(adoptJobs, configJobs, bucketKey);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task ClearAsync(bool deleteUserBuckets)
        {
            try
            {
                _logger.LogInformation($"Deleting anonymous user bucket {_bucket.BucketKey}");
                await _bucket.DeleteAsync();

                // We need to wait because the server needs some time to settle down. If we try to create the bucket again immediately we'll get a conflict error.
                await Task.Delay(4000);
            }
            catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound)
            {
                _logger.LogInformation($"Nothing to delete because bucket {_bucket.BucketKey} does not exist yet");
            }

            if (deleteUserBuckets)
            {
                _logger.LogInformation($"Deleting user buckets for registered users");
                // delete all user buckets
                var buckets = await _bucket.GetBucketsAsync();

                string userBucketPrefix = _bucketPrefixProvider.GetBucketPrefix();
                foreach (string bucket in buckets)
                {
                    if (bucket.Contains(userBucketPrefix))
                    {
                        _logger.LogInformation($"Deleting user bucket {bucket}");
                        await _bucket.DeleteBucketAsync(bucket);
                    }
                }
            }

            // delete bundles and activities
            await _fdaClient.CleanUpAsync();

            // cleanup locally cached files but keep the directory as it is initialized at the start of the app and needed to run the web server
            Directory.EnumerateFiles(_localCache.LocalRootName).ToList().ForEach((string filePath) => File.Delete(filePath));
            Directory.EnumerateDirectories(_localCache.LocalRootName).ToList().ForEach((string dirPath) => Directory.Delete(dirPath, true));
        }