Example #1
0
        internal async Task ListBuckets(S3Context ctx)
        {
            string header = "[" + ctx.Http.Request.Source.IpAddress + ":" + ctx.Http.Request.Source.Port + " " + ctx.Request.RequestType.ToString() + "] ";

            RequestMetadata md = ApiHelper.GetRequestMetadata(ctx);

            if (md == null)
            {
                _Logging.Warn(header + "unable to retrieve metadata");
                await ctx.Response.Send(ErrorCode.InternalError);

                return;
            }

            if (md.Authentication != AuthenticationResult.Authenticated)
            {
                _Logging.Warn(header + "requestor not authenticated");
                await ctx.Response.Send(ErrorCode.AccessDenied);

                return;
            }
            else
            {
                md.Authorization = AuthorizationResult.PermitService;
            }

            List <Classes.Bucket> buckets = _Buckets.GetUserBuckets(md.User.GUID);

            ListAllMyBucketsResult listBucketsResult = new ListAllMyBucketsResult();

            listBucketsResult.Owner             = new S3ServerInterface.S3Objects.Owner();
            listBucketsResult.Owner.DisplayName = md.User.Name;
            listBucketsResult.Owner.ID          = md.User.Name;

            listBucketsResult.Buckets        = new Buckets();
            listBucketsResult.Buckets.Bucket = new List <S3ServerInterface.S3Objects.Bucket>();

            foreach (Classes.Bucket curr in buckets)
            {
                S3ServerInterface.S3Objects.Bucket b = new S3ServerInterface.S3Objects.Bucket();
                b.Name         = curr.Name;
                b.CreationDate = curr.CreatedUtc;
                listBucketsResult.Buckets.Bucket.Add(b);
            }

            await ApiHelper.SendSerializedResponse <ListAllMyBucketsResult>(ctx, listBucketsResult);

            return;
        }