...
 
Commits (3)
......@@ -9,8 +9,8 @@ using System.Reflection;
[assembly: AssemblyDescription("Project.Tests is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Project.Tests")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
[assembly: AssemblyInformationalVersion("1.6.1.0")]
[assembly: AssemblyVersion("1.6.2.0")]
[assembly: AssemblyFileVersion("1.6.2.0")]
[assembly: AssemblyInformationalVersion("1.6.2.0")]
[assembly: AssemblyCopyright("2019 IT Center, RWTH Aachen University")]
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Factories;
using Coscine.ApiCommons.Utils;
using Coscine.Configuration;
using Coscine.Database.Model;
......@@ -255,6 +256,66 @@ namespace Coscine.Api.Project.Controllers
}
}
[HttpPost("[controller]/validate")]
public async Task<IActionResult> IsResourceValid()
{
var path = "/";
JToken resource = ObjectFactory<JToken>.DeserializeFromStream(Request.Body);
string authHeader = null;
if (resource["type"]["displayName"].ToString().ToLower() == "rds")
{
RDSResourceType rdsResourceType = new RDSResourceType();
rdsResourceType.BucketName = resource["resourceTypeOption"]["BucketName"].ToString();
rdsResourceType.AccessKey = resource["resourceTypeOption"]["AccessKey"].ToString();
rdsResourceType.SecretKey = resource["resourceTypeOption"]["SecretKey"].ToString();
authHeader = BuildRdsAuthHeader(rdsResourceType);
}
else if (resource["type"]["displayName"].ToString().ToLower() == "gitlab")
{
GitlabResourceType gitlabResourceType = new GitlabResourceType();
gitlabResourceType.RepositoryNumber = (int)resource["resourceTypeOption"]["RepositoryNumber"];
gitlabResourceType.RepositoryUrl = resource["resourceTypeOption"]["RepositoryUrl"].ToString();
gitlabResourceType.Token = resource["resourceTypeOption"]["Token"].ToString();
authHeader = BuildGitlabAuthHeader(gitlabResourceType);
}
if (authHeader == null)
{
return BadRequest($"No provider for: \"{resource["type"]["displayName"].ToString()}\".");
}
else
{
// If the path is null, an empty string is added.
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{resource["type"]["displayName"].ToString().ToLower()}{path}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authHeader);
// Thread safe according to msdn and HttpCompletionOption sets it to get only headers first.
var response = await Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
if (response.Content.Headers.Contains("Content-Disposition"))
{
return File(await response.Content.ReadAsStreamAsync(),
response.Content.Headers.GetValues("Content-Type").First());
}
else
{
var data = JObject.Parse(await response.Content.ReadAsStringAsync())["data"];
return Ok(new WaterbutlerObject(path, data));
}
}
else
{
return FailedRequest(response, path);
}
}
}
private IActionResult FailedRequest(HttpResponseMessage response, string path)
{
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
......@@ -393,9 +454,9 @@ namespace Coscine.Api.Project.Controllers
var settings = new Dictionary<string, object>
{
{"owner", "Tester"},
{ "owner", "Tester"},
{ "repo", gitlabResourceType.RepositoryUrl},
{ "repo_id", gitlabResourceType.RepositoryNumber},
{ "repo_id", gitlabResourceType.RepositoryNumber.ToString()},
{ "host", "https://git.rwth-aachen.de"}
};
......
......@@ -9,8 +9,8 @@ using System.Reflection;
[assembly: AssemblyDescription("Project is a part of the CoScInE group.")]
[assembly: AssemblyCompany("IT Center, RWTH Aachen University")]
[assembly: AssemblyProduct("Project")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
[assembly: AssemblyInformationalVersion("1.6.1.0")]
[assembly: AssemblyVersion("1.6.2.0")]
[assembly: AssemblyFileVersion("1.6.2.0")]
[assembly: AssemblyInformationalVersion("1.6.2.0")]
[assembly: AssemblyCopyright("2019 IT Center, RWTH Aachen University")]