Skip to content
Snippets Groups Projects
Commit 555d10b3 authored by tr-admin's avatar tr-admin
Browse files

New: Add documentation for blobAPI(coscine/issues#1108)

parent b7a4fe55
No related branches found
No related tags found
1 merge request!7Topic/1108 docu blob api
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Coscine.Api.Blob.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
...@@ -42,6 +43,7 @@ ...@@ -42,6 +43,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Coscine.Api.Blob.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL"> <Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
......
...@@ -22,7 +22,11 @@ using System.Web; ...@@ -22,7 +22,11 @@ using System.Web;
namespace Coscine.Api.Blob.Controllers namespace Coscine.Api.Blob.Controllers
{ {
/// <summary>
/// This controller represents the actions which can be taken with a Blob object.
/// </summary>
[Authorize] [Authorize]
public class BlobController : Controller public class BlobController : Controller
{ {
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
...@@ -39,6 +43,13 @@ namespace Coscine.Api.Blob.Controllers ...@@ -39,6 +43,13 @@ namespace Coscine.Api.Blob.Controllers
private readonly string _rdsResourceHost; private readonly string _rdsResourceHost;
private readonly WaterbutlerInterface _waterbutlerInterface; private readonly WaterbutlerInterface _waterbutlerInterface;
/// <summary>
/// Blob controller constructor
/// </summary>
/// <param name="logger">Logger</param>
/// <param name="dataSourceService">Source service for data</param>
public BlobController(ILogger<BlobController> logger, IDataSourceService dataSourceService) public BlobController(ILogger<BlobController> logger, IDataSourceService dataSourceService)
{ {
_configuration = Program.Configuration; _configuration = Program.Configuration;
...@@ -61,7 +72,11 @@ namespace Coscine.Api.Blob.Controllers ...@@ -61,7 +72,11 @@ namespace Coscine.Api.Blob.Controllers
_dataSourceService = dataSourceService; _dataSourceService = dataSourceService;
_waterbutlerInterface = new WaterbutlerInterface(_configuration, _dataSourceService); _waterbutlerInterface = new WaterbutlerInterface(_configuration, _dataSourceService);
} }
/// <summary>
/// This method returns the amount of allocated space for the given resource
/// </summary>
/// <param name="resourceId">Id of a resource</param>
/// <returns>Data, file count and bytesize used </returns>
[HttpGet("[controller]/{resourceId}/quota")] [HttpGet("[controller]/{resourceId}/quota")]
public IActionResult GetQuota(string resourceId) public IActionResult GetQuota(string resourceId)
{ {
...@@ -140,6 +155,13 @@ namespace Coscine.Api.Blob.Controllers ...@@ -140,6 +155,13 @@ namespace Coscine.Api.Blob.Controllers
// inferring a ../ (urlencoded) can manipulate the url. // inferring a ../ (urlencoded) can manipulate the url.
// However the constructed signature for s3 won't match and it will not be resolved. // However the constructed signature for s3 won't match and it will not be resolved.
// This may be a problem for other provider! // This may be a problem for other provider!
/// <summary>
/// This method checks if the given file exists
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path"> Path to the file </param>
/// <returns>Ok if file exists otherwise error </returns>
[HttpGet("[controller]/{resourceId}/{*path}")] [HttpGet("[controller]/{resourceId}/{*path}")]
[DisableRequestSizeLimit] [DisableRequestSizeLimit]
public async Task<IActionResult> GetFile(string resourceId, string path) public async Task<IActionResult> GetFile(string resourceId, string path)
...@@ -205,6 +227,13 @@ namespace Coscine.Api.Blob.Controllers ...@@ -205,6 +227,13 @@ namespace Coscine.Api.Blob.Controllers
// inferring a ../ (urlencoded) can manipulate the url. // inferring a ../ (urlencoded) can manipulate the url.
// However the constructed signature for s3 won't match and it will not be resolved. // However the constructed signature for s3 won't match and it will not be resolved.
// This may be a problem for other provider! // This may be a problem for other provider!
/// <summary>
/// This method uploads a given File
/// </summary>
/// <param name="resourceId">Id of the resource </param>
/// <param name="path">Path to the file</param>
/// <returns>Ok if file is uploaded otherwise error</returns>
[HttpPut("[controller]/{resourceId}/{*path}")] [HttpPut("[controller]/{resourceId}/{*path}")]
[DisableRequestSizeLimit] [DisableRequestSizeLimit]
public async Task<IActionResult> UploadFile(string resourceId, string path) public async Task<IActionResult> UploadFile(string resourceId, string path)
...@@ -284,7 +313,12 @@ namespace Coscine.Api.Blob.Controllers ...@@ -284,7 +313,12 @@ namespace Coscine.Api.Blob.Controllers
} }
} }
/// <summary>
/// This method deletes a given file
/// </summary>
/// <param name="resourceId">Id of the resource </param>
/// <param name="path">Path to the file</param>
/// <returns>Ok if deletion successful otherwise returns error </returns>
[HttpDelete("[controller]/{resourceId}/{*path}")] [HttpDelete("[controller]/{resourceId}/{*path}")]
public async Task<IActionResult> DeleteFile(string resourceId, string path) public async Task<IActionResult> DeleteFile(string resourceId, string path)
{ {
...@@ -345,14 +379,15 @@ namespace Coscine.Api.Blob.Controllers ...@@ -345,14 +379,15 @@ namespace Coscine.Api.Blob.Controllers
} }
} }
} }
/// <summary>
/// This method checks if the resource is valid
/// </summary>
/// <returns>Ok if resource is valid otherwise returns error</returns>
[HttpPost("[controller]/validate")] [HttpPost("[controller]/validate")]
public async Task<IActionResult> IsResourceValid() public async Task<IActionResult> IsResourceValid([FromBody] JToken resource)
{ {
var path = "/"; var path = "/";
JToken resource = ObjectFactory<JToken>.DeserializeFromStream(Request.Body);
string authHeader = null; string authHeader = null;
if (resource["type"]["displayName"].ToString().ToLower() == "s3") if (resource["type"]["displayName"].ToString().ToLower() == "s3")
{ {
...@@ -394,6 +429,9 @@ namespace Coscine.Api.Blob.Controllers ...@@ -394,6 +429,9 @@ namespace Coscine.Api.Blob.Controllers
return NoContent(); return NoContent();
} }
} }
/// <summary>
/// Returns the name of the resource
/// </summary>
private string GetResourceTypeName(Resource resource) private string GetResourceTypeName(Resource resource)
{ {
...@@ -406,6 +444,9 @@ namespace Coscine.Api.Blob.Controllers ...@@ -406,6 +444,9 @@ namespace Coscine.Api.Blob.Controllers
return resource.Type.DisplayName.ToLower(); return resource.Type.DisplayName.ToLower();
} }
} }
/// <summary>
/// Returns the name of the resource
/// </summary>
private string GetResourceTypeName(JToken resource) private string GetResourceTypeName(JToken resource)
{ {
...@@ -418,6 +459,9 @@ namespace Coscine.Api.Blob.Controllers ...@@ -418,6 +459,9 @@ namespace Coscine.Api.Blob.Controllers
return resource["type"]["displayName"].ToString().ToLower(); return resource["type"]["displayName"].ToString().ToLower();
} }
} }
/// <summary>
/// Creates an Action Result that can be returned on error
/// </summary>
private IActionResult FailedRequest(HttpResponseMessage response, string path) private IActionResult FailedRequest(HttpResponseMessage response, string path)
{ {
...@@ -434,7 +478,9 @@ namespace Coscine.Api.Blob.Controllers ...@@ -434,7 +478,9 @@ namespace Coscine.Api.Blob.Controllers
return BadRequest($"Error in communication with waterbutler: {response.StatusCode}"); return BadRequest($"Error in communication with waterbutler: {response.StatusCode}");
} }
} }
/// <summary>
/// Tries to establish connection with resource and validates wether the given file/folder exists
/// </summary>
private IActionResult CheckResourceIdAndPath(string resourceId, string path, out Resource resource) private IActionResult CheckResourceIdAndPath(string resourceId, string path, out Resource resource)
{ {
resource = null; resource = null;
...@@ -479,6 +525,11 @@ namespace Coscine.Api.Blob.Controllers ...@@ -479,6 +525,11 @@ namespace Coscine.Api.Blob.Controllers
} }
// XXX extract in the future to an analytics Controller // XXX extract in the future to an analytics Controller
/// <summary>
/// Writes an analytics log entry
/// </summary>
private void LogAnalytics(string operation, string resourceId, string path, User user) private void LogAnalytics(string operation, string resourceId, string path, User user)
{ {
if (CoscineLoggerConfiguration.IsLogLevelActivated(LogType.Analytics)) if (CoscineLoggerConfiguration.IsLogLevelActivated(LogType.Analytics))
......
...@@ -3,8 +3,14 @@ using Coscine.Configuration; ...@@ -3,8 +3,14 @@ using Coscine.Configuration;
namespace Coscine.Api.Blob namespace Coscine.Api.Blob
{ {
/// <summary>
/// Standard Program Class
/// </summary>
public class Program : AbstractProgram<ConsulConfiguration> public class Program : AbstractProgram<ConsulConfiguration>
{ {
/// <summary>
/// Standard main body
/// </summary>
public static void Main() public static void Main()
{ {
System.Net.ServicePointManager.DefaultConnectionLimit = int.MaxValue; System.Net.ServicePointManager.DefaultConnectionLimit = int.MaxValue;
......
...@@ -5,12 +5,21 @@ using System; ...@@ -5,12 +5,21 @@ using System;
namespace Coscine.Api.Blob namespace Coscine.Api.Blob
{ {
/// <summary>
/// Standard Startup class.
/// </summary>
public class Startup : AbstractStartup public class Startup : AbstractStartup
{ {
/// <summary>
/// Standard Startup constructor.
/// </summary>
public Startup() public Startup()
{ {
} }
/// <summary>
/// Configures custom service extenions
/// </summary>
/// <param name="services">services</param>
public override void ConfigureServicesExtension(IServiceCollection services) public override void ConfigureServicesExtension(IServiceCollection services)
{ {
base.ConfigureServicesExtension(services); base.ConfigureServicesExtension(services);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment