Exemplo n.º 1
0
        public async Task <ActionResult> Index(string accountName, string containerName)
        {
            var account = await _accountDbCommand.FindByNameAsync(accountName);

            if (account == null)
            {
                return(HttpNotFound());
            }
            if (account.Owner != User.Identity.Name)
            {
                return(new HttpUnauthorizedResult());
            }

            var container = await _containerDbCommand.FindAsync(account, containerName);

            if (container == null)
            {
                return(HttpNotFound());
            }

            var count = await _blobDbCommand.CountAsync(container);

            var blobs = await _blobDbCommand.GetAttributesListAsync(container, 0, 10);

            ViewBag.AccountName   = container.Account.Name;
            ViewBag.ContainerName = container.Name;
            ViewBag.Skip          = 0;
            ViewBag.Take          = 10;
            ViewBag.TotalCount    = count;
            ViewBag.HasNext       = !(count <= 10);
            ViewBag.HasPreview    = false;

            return(View(Mapper.Map <IEnumerable <BlobIndexModel> >(blobs)));
        }
Exemplo n.º 2
0
        public async Task CreateCommonTest()
        {
            var container = Mock.CommonStorageAccount.CreateContainer("CreateCommonTest");

            container.Metadata["key1"]        = "value1";
            container.Metadata["key2"]        = "value2";
            container.IsPublic                = true;
            container.LastModifiedUtcDateTime = new DateTime(2015, 12, 31);

            await _dbCommand.SaveAsync(container);

            var created = await _dbCommand.FindAsync(container.Id);

            created.IsStructuralEqual(container);
        }
Exemplo n.º 3
0
        public async Task <ContainerResponseModel> GetReferenceAsync([FromUri] string accountName, [FromUri] string name)
        {
            var account = await CheckAccessKey(accountName);

            var container = await _containerDbCommand.FindAsync(account, name);

            var response = container != null
                ? Mapper.Map <ContainerResponseModel>(container)
                : new ContainerResponseModel
            {
                Name = name,
            };

            return(response);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Detail(string accountName, string id)
        {
            var account = await _accountDbCommand.FindByNameAsync(accountName);

            if (account == null)
            {
                return(HttpNotFound());
            }
            if (account.Owner != User.Identity.Name)
            {
                return(new HttpUnauthorizedResult());
            }

            var container = await _containerDbCommand.FindAsync(id);

            if (container == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_Detail", Mapper.Map <ContainerIndexModel>(container)));
        }
Exemplo n.º 5
0
        private async Task <Container> CheckAccessKey(string accountName, string containerName, bool throughCheckAccessKeyIfPublic = false)
        {
            var account = await _accountDbCommand.FindByNameAsync(accountName);

            if (account == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var container = await _containerDbCommand.FindAsync(account, containerName);

            if (container == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (throughCheckAccessKeyIfPublic && container.IsPublic)
            {
                return(container);
            }

            IEnumerable <string> s;

            if (!Request.Headers.TryGetValues("X-Bloqs-API-Key", out s))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var keys = s as string[] ?? s.ToArray();

            if (!keys.Any())
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            var key = keys.FirstOrDefault();

            if (account.PrimaryAccessKey != key && account.SecondaryAccessKey != key)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            return(container);
        }