コード例 #1
0
        public async Task <HttpResponseMessage> DeleteBlob(string container, string blob, string snapshot = null)
        {
            var  requestWrapper  = DashHttpRequestWrapper.Create(this.Request);
            var  headers         = requestWrapper.Headers;
            var  queryParams     = requestWrapper.QueryParameters;
            bool dataBlobDeleted = false;

            return(await DoHandlerAsync(String.Format("BlobController.DeleteBlob: {0}/{1}", container, blob),
                                        async() => await NamespaceHandler.PerformNamespaceOperation(container, blob, async(namespaceBlob) =>
            {
                // We only need to delete the actual blob. We are leaving the namespace entry alone as a sort of cache.
                if (!(await namespaceBlob.ExistsAsync()) || namespaceBlob.IsMarkedForDeletion)
                {
                    return this.CreateResponse(HttpStatusCode.NotFound, headers);
                }
                // Delete the real data blob by forwarding the request onto the data account
                if (!dataBlobDeleted)
                {
                    var forwardedResponse = await ForwardRequestHandler(namespaceBlob, StorageOperationTypes.DeleteBlob);
                    if (!forwardedResponse.IsSuccessStatusCode)
                    {
                        return forwardedResponse;
                    }
                    dataBlobDeleted = true;
                }
                // See if we need to delete any replicas
                if (namespaceBlob.IsReplicated)
                {
                    await BlobReplicationHandler.EnqueueBlobReplicationAsync(namespaceBlob, true, false);
                }
                // Mark the namespace blob for deletion
                await namespaceBlob.MarkForDeletionAsync();
                return this.CreateResponse(HttpStatusCode.Accepted, headers);
            })));
        }
コード例 #2
0
        public async Task <HttpResponseMessage> PutBlobComp(string container, string blob, string comp)
        {
            var requestWrapper = DashHttpRequestWrapper.Create(this.Request);
            var operation      = StorageOperations.GetBlobOperation(requestWrapper);

            switch (operation)
            {
            case StorageOperationTypes.SetBlobProperties:
            case StorageOperationTypes.SetBlobMetadata:
            case StorageOperationTypes.LeaseBlob:
            case StorageOperationTypes.SnapshotBlob:
            case StorageOperationTypes.PutPage:
                return(await BasicBlobHandler(container, blob, requestWrapper, operation));

            case StorageOperationTypes.PutBlock:
            case StorageOperationTypes.PutBlockList:
                return(await PutBlobHandler(container, blob, requestWrapper, operation));

            case StorageOperationTypes.AbortCopyBlob:
                /// Abort Copy Blob - http://msdn.microsoft.com/en-us/library/azure/jj159098.aspx
                return(ProcessResultResponse(await BlobHandler.AbortCopyBlobAsync(
                                                 requestWrapper, container, blob, requestWrapper.QueryParameters.Value <string>("copyid"))));

            default:
                return(this.CreateResponse(HttpStatusCode.BadRequest, requestWrapper.Headers));
            }
        }
コード例 #3
0
        public async Task <HttpResponseMessage> GetBlobComp(string container, string blob, string comp, string snapshot = null)
        {
            var requestWrapper = DashHttpRequestWrapper.Create(this.Request);
            var operation      = StorageOperations.GetBlobOperation(requestWrapper);

            switch (operation)
            {
            case StorageOperationTypes.GetBlobMetadata:
            case StorageOperationTypes.GetBlockList:
            case StorageOperationTypes.GetPageRanges:
                return(await BasicBlobHandler(container, blob, requestWrapper, operation));

            default:
                return(this.CreateResponse(HttpStatusCode.BadRequest, requestWrapper.Headers));
            }
        }
コード例 #4
0
        public async Task <HttpResponseMessage> PutBlob(string container, string blob)
        {
            var requestWrapper = DashHttpRequestWrapper.Create(this.Request);
            var operation      = StorageOperations.GetBlobOperation(requestWrapper);

            switch (operation)
            {
            case StorageOperationTypes.CopyBlob:
                /// Copy Blob - https://msdn.microsoft.com/en-us/library/azure/dd894037.aspx
                return(ProcessResultResponse(await BlobHandler.CopyBlobAsync(requestWrapper, container, blob, requestWrapper.Headers.Value <string>("x-ms-copy-source"))));

            case StorageOperationTypes.PutBlob:
                /// Put Blob - http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
                return(await PutBlobHandler(container, blob, requestWrapper, operation));

            default:
                System.Diagnostics.Debug.Assert(false);
                return(this.CreateResponse(HttpStatusCode.BadRequest, requestWrapper.Headers));
            }
        }
コード例 #5
0
 private async Task <HttpResponseMessage> GetBlobList(string container)
 {
     return(CreateResponse(await BlobListHandler.GetBlobListing(container, DashHttpRequestWrapper.Create(this.Request))));
 }
コード例 #6
0
ファイル: Global.asax.cs プロジェクト: CedarLogic/Dash
        async Task PreRequestHandlerExecuteAsync(Object sender, EventArgs e)
        {
            // Insert handling here for any requests which can potentially contain a body and that we intend to redirect. We must
            // process the request here because if the client is using the Expect: 100-Continue header, then we should issue our
            // final (redirect) status BEFORE IIS sends the 100 Continue response. This way the blob content is never sent to us.
            var result = await WebOperationRunner.DoHandlerAsync("App.PreRequestHandlerExecuteAsync",
                                                                 async() => await StorageOperationsHandler.HandlePrePipelineOperationAsync(DashHttpRequestWrapper.Create(this.Request, true)));

            if (result != null)
            {
                switch (result.StatusCode)
                {
                case HttpStatusCode.Redirect:
                    this.Response.Redirect(result.Location, false);
                    if (!String.IsNullOrWhiteSpace(result.SignedLocation))
                    {
                        this.Response.AppendHeader("x-ms-redirect-signature", result.SignedLocation);
                    }
                    if (result.Headers != null)
                    {
                        foreach (var header in result.Headers
                                 .SelectMany(headerGroup => headerGroup
                                             .Select(headerItem => Tuple.Create(headerGroup.Key, headerItem))))
                        {
                            this.Response.AppendHeader(header.Item1, header.Item2);
                        }
                    }
                    break;

                case HttpStatusCode.NotFound:
                    this.Response.StatusCode        = (int)HttpStatusCode.NotFound;
                    this.Response.StatusDescription = "The specified blob does not exist.";
                    this.Response.ContentType       = "application/xml";
                    this.Response.Write(String.Format(@"
<?xml version='1.0' encoding='utf-8'?>
<Error>
  <Code>BlobNotFound</Code>
  <Message>The specified blob does not exist.\n Time:{0:o}</Message>
</Error>", DateTime.UtcNow));
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false);
                    this.Response.StatusCode = (int)result.StatusCode;
                    break;
                }

                this.CompleteRequest();
            }
        }
コード例 #7
0
ファイル: Global.asax.cs プロジェクト: CedarLogic/Dash
        async Task AuthorizeRequestAsync(Object sender, EventArgs e)
        {
            if (!await OperationRunner.DoActionAsync("App.AuthorizeRequestAsync",
                                                     async() => await RequestAuthorization.IsRequestAuthorizedAsync(DashHttpRequestWrapper.Create(this.Request, true))))
            {
                this.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                // Details lifted directly from Storage Service auth failure responses
                this.Response.ContentType       = "application/xml";
                this.Response.StatusDescription = "Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.";
                this.Response.Write(String.Format(@"
<?xml version='1.0' encoding='utf-8'?>
<Error>
  <Code>AuthenticationFailed</Code>
  <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. Time:{0:o}</Message>
</Error>", DateTime.UtcNow));
                this.CompleteRequest();
            }
        }