public async Task <OssBucket> GetBucketAsync(bool tryToCreate = false) { if (!IsAuthenticated) { return(AnonymousBucket); } dynamic profile = await GetProfileAsync(); var userId = profile.userId; // 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 = Crypto.GenerateHashString(_forgeConfig.ClientId + userId); var bucketKey = $"{GetBucketPrefix()}-{userId.Substring(0, 3)}-{userHash}".ToLowerInvariant(); var bucket = new OssBucket(_forgeOSS, bucketKey, _logger); if (tryToCreate) { // TODO: VERY INEFFECTIVE!!!!! try { await bucket.CreateAsync(); } catch (ApiException e) when(e.ErrorCode == StatusCodes.Status409Conflict) { // means - the bucket already exists } } return(bucket); }
public async Task <OssBucket> GetBucketAsync(bool tryToCreate = false) { var bucket = new OssBucket(_forgeOSS, await _bucketKeyProvider.GetBucketKeyAsync(), _logger); if (tryToCreate) { // TODO: VERY INEFFECTIVE!!!!! try { await bucket.CreateAsync(); } catch (ApiException e) when(e.ErrorCode == StatusCodes.Status409Conflict) { // means - the bucket already exists } } return(bucket); }