Aufgrund einer Wartung wird GitLab am 29.10. zwischen 9:00 und 10:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 29.10. between 9:00 and 10:00 am.

Commit a86eab9e authored by Marcel Nellesen's avatar Marcel Nellesen

Merge branch 'Sprint/201922-2' into 'master'

New: Included Mockup for bucket Application

See merge request !46
parents aa44dd00 f50bd8f7
......@@ -144,9 +144,8 @@ namespace Coscine.Api.Project.Tests
RDSResourceTypeModel rdsResourceTypeModel = new RDSResourceTypeModel();
RdsResourceType = new RDSResourceType()
{
AccessKey = "a",
SecretKey = "b",
BucketName = "c",
Size = 25,
};
rdsResourceTypeModel.Insert(RdsResourceType);
......
......@@ -65,8 +65,8 @@
<Reference Include="Coscine.Configuration, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Configuration.1.4.0\lib\net461\Coscine.Configuration.dll</HintPath>
</Reference>
<Reference Include="Coscine.Database, Version=1.10.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.1.10.0\lib\net461\Coscine.Database.dll</HintPath>
<Reference Include="Coscine.Database, Version=1.11.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.1.11.0\lib\net461\Coscine.Database.dll</HintPath>
</Reference>
<Reference Include="Coscine.ProxyApi, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ProxyApi.1.2.0\lib\net461\Coscine.ProxyApi.dll</HintPath>
......
......@@ -53,7 +53,7 @@ namespace Coscine.Api.Project.Tests
ResourceObject resourceObject = (ResourceObject)okObjectResult.Value;
resourceObject.DisplayName = "OtherName";
resourceObject.ResourceTypeOption = JObject.FromObject(new RDSResourceTypeObject(Guid.NewGuid(), "PITLABTTEST", "accesskey", "secretkey"));
resourceObject.ResourceTypeOption = JObject.FromObject(new RDSResourceTypeObject(Guid.NewGuid(), "PITLABTTEST", 0));
Stream stream = ObjectFactory<ResourceObject>.SerializeToStream(resourceObject);
......@@ -97,7 +97,7 @@ namespace Coscine.Api.Project.Tests
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayNameDe, Discipline.DisplayNameEn) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName),
new LicenseObject(License.Id, License.DisplayName),
JObject.FromObject(new RDSResourceTypeObject(Guid.NewGuid(), "PITLABTTEST", "accesskey", "secretkey")),
JObject.FromObject(new RDSResourceTypeObject(Guid.NewGuid(), "PITLABTTEST", 0)),
"link",
JToken.Parse("{}")
);
......
......@@ -24,11 +24,10 @@ namespace Coscine.Api.Project.Tests
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
List<string> fields = (List<string>) okObjectResult.Value;
if(fields.Count() == 3)
if(fields.Count() == 2)
{
Assert.IsTrue(fields[0] == "BucketName");
Assert.IsTrue(fields[1] == "AccessKey");
Assert.IsTrue(fields[2] == "SecretKey");
Assert.IsTrue(fields[1] == "Size");
}
else
{
......
......@@ -88,7 +88,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Coscine.Database" publicKeyToken="767d77427707b70a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.10.0.0" newVersion="1.10.0.0" />
<bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
......
......@@ -7,7 +7,7 @@
<package id="Coscine.Action" version="1.7.0" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.2.2" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.10.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.11.0" targetFramework="net472" />
<package id="Coscine.ProxyApi" version="1.2.0" targetFramework="net472" />
<package id="Coscine.SharePoint.Webparts.Vue" version="1.4.0" targetFramework="net472" />
<package id="dotNetRDF" version="2.2.1" targetFramework="net472" />
......
......@@ -91,7 +91,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Coscine.Database" publicKeyToken="767d77427707b70a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.10.0.0" newVersion="1.10.0.0" />
<bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
......
......@@ -73,7 +73,7 @@ namespace Coscine.Api.Project.Controllers
else
{
// If the path is null, an empty string is added.
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{resource.Type.DisplayName.ToLower()}{path}";
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{GetResourceTypeName(resource)}{path}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authHeader);
......@@ -127,7 +127,7 @@ namespace Coscine.Api.Project.Controllers
else
{
// If the path is null, an empty string is added.
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{resource.Type.DisplayName.ToLower()}/?kind=file&name={path}";
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{GetResourceTypeName(resource)}/?kind=file&name={path}";
try
{
......@@ -176,7 +176,7 @@ namespace Coscine.Api.Project.Controllers
else
{
// If the path is null, an empty string is added.
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{resource.Type.DisplayName.ToLower()}/{path}?kind=file";
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{GetResourceTypeName(resource)}/{path}?kind=file";
try
{
......@@ -198,6 +198,29 @@ namespace Coscine.Api.Project.Controllers
}
}
private string GetResourceTypeName(Resource resource)
{
if (resource.Type.DisplayName.ToLower().Equals("s3")) {
return "rds";
}
else
{
return resource.Type.DisplayName.ToLower();
}
}
private string GetResourceTypeName(JToken resource)
{
if (resource["type"]["displayName"].ToString().ToLower().Equals("s3"))
{
return "rds";
}
else
{
return resource["type"]["displayName"].ToString().ToLower();
}
}
public async Task<HttpResponseMessage> UploadFile(string url, string authHeader, Stream stream)
{
......@@ -230,7 +253,7 @@ namespace Coscine.Api.Project.Controllers
else
{
// If the path is null, an empty string is added.
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{resource.Type.DisplayName.ToLower()}{path}";
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{GetResourceTypeName(resource)}{path}";
var request = new HttpRequestMessage(HttpMethod.Delete, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authHeader);
......@@ -265,13 +288,13 @@ namespace Coscine.Api.Project.Controllers
string authHeader = null;
if (resource["type"]["displayName"].ToString().ToLower() == "rds")
if (resource["type"]["displayName"].ToString().ToLower() == "s3")
{
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);
S3ResourceType s3ResourceType = new S3ResourceType();
s3ResourceType.BucketName = resource["resourceTypeOption"]["BucketName"].ToString();
s3ResourceType.AccessKey = resource["resourceTypeOption"]["AccessKey"].ToString();
s3ResourceType.SecretKey = resource["resourceTypeOption"]["SecretKey"].ToString();
authHeader = BuildS3AuthHeader(s3ResourceType);
}
else if (resource["type"]["displayName"].ToString().ToLower() == "gitlab")
{
......@@ -289,7 +312,7 @@ namespace Coscine.Api.Project.Controllers
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}";
string url = $"{_configuration.GetString("coscine/global/waterbutler_url")}{GetResourceTypeName(resource)}{path}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authHeader);
......@@ -413,6 +436,13 @@ namespace Coscine.Api.Project.Controllers
authHeader = BuildRdsAuthHeader(rdsResourceType);
}
else if (resource.Type.DisplayName.ToLower() == "s3")
{
S3ResourceTypeModel s3ResourceTypeModel = new S3ResourceTypeModel();
var s3ResourceType = s3ResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
authHeader = BuildS3AuthHeader(s3ResourceType);
}
else if (resource.Type.DisplayName.ToLower() == "gitlab")
{
GitlabResourceTypeModel gitlabResourceTypeModel = new GitlabResourceTypeModel();
......@@ -430,8 +460,8 @@ namespace Coscine.Api.Project.Controllers
var credentials = new Dictionary<string, object>
{
{ "access_key", rdsResourceType.AccessKey },
{ "secret_key", rdsResourceType.SecretKey }
{ "access_key", _configuration.GetStringAndWait("coscine/global/buckets/accessKey") },
{ "secret_key", _configuration.GetStringAndWait("coscine/global/buckets/secretKey") }
};
var settings = new Dictionary<string, object>
......@@ -442,6 +472,24 @@ namespace Coscine.Api.Project.Controllers
return BuildWaterbutlerPayload(auth, credentials, settings);
}
private string BuildS3AuthHeader(S3ResourceType s3ResourceType)
{
var auth = new Dictionary<string, object>();
var credentials = new Dictionary<string, object>
{
{ "access_key", s3ResourceType.AccessKey },
{ "secret_key", s3ResourceType.SecretKey }
};
var settings = new Dictionary<string, object>
{
{ "bucket", s3ResourceType.BucketName }
};
return BuildWaterbutlerPayload(auth, credentials, settings);
}
private string BuildGitlabAuthHeader(GitlabResourceType gitlabResourceType)
{
......
......@@ -38,7 +38,14 @@ namespace Coscine.Api.Project.Controllers
{
var resourceType = _resourceTypeModel.GetById(Guid.Parse(id));
if(resourceType.DisplayName == "rds")
if (resourceType.DisplayName == "s3")
{
return Type.GetType("Coscine.Api.Project.ReturnObjects.S3ResourceTypeObject").GetProperties()
.Where((property) => property.Name != "Id")
.Select((property) => property.Name)
.ToList();
}
else if (resourceType.DisplayName == "rds")
{
return Type.GetType("Coscine.Api.Project.ReturnObjects.RDSResourceTypeObject").GetProperties()
.Where((property) => property.Name != "Id")
......
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons.Models;
using Coscine.Configuration;
using Coscine.Database.Model;
using LinqToDB;
using Newtonsoft.Json.Linq;
......@@ -12,8 +13,11 @@ namespace Coscine.Api.Project.Models
{
public class ResourceModel : DatabaseModel<Resource>
{
private readonly IConfiguration _configuration;
public ResourceModel() : base(Program.Configuration)
{
_configuration = Program.Configuration;
}
public Resource StoreFromObject(ResourceObject resourceObject)
......@@ -84,26 +88,47 @@ namespace Coscine.Api.Project.Models
if (resource.ResourceTypeOptionId != null)
{
RDSResourceType rdsResourceType = rdsResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
rdsResourceType.BucketName = rdsResourceTypeObject.BucketName;
rdsResourceType.AccessKey = rdsResourceTypeObject.AccessKey ?? rdsResourceType.AccessKey;
rdsResourceType.SecretKey = rdsResourceTypeObject.SecretKey ?? rdsResourceType.SecretKey;
rdsResourceTypeModel.Update(rdsResourceType);
}
else
{
RDSResourceType rdsResourceType = new RDSResourceType()
{
BucketName = rdsResourceTypeObject.BucketName,
AccessKey = rdsResourceTypeObject.AccessKey,
SecretKey = rdsResourceTypeObject.SecretKey
BucketName = GetRDSBucketName(),
Size = rdsResourceTypeObject.Size,
};
rdsResourceTypeModel.Insert(rdsResourceType);
resource.ResourceTypeOptionId = rdsResourceType.Id;
Update(resource);
}
}
else if (resource.Type.DisplayName == "s3")
{
S3ResourceTypeObject s3ResourceTypeObject = resourceTypeOption.ToObject<S3ResourceTypeObject>();
S3ResourceTypeModel s3ResourceTypeModel = new S3ResourceTypeModel();
if (resource.ResourceTypeOptionId != null)
{
S3ResourceType s3ResourceType = s3ResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
s3ResourceType.BucketName = s3ResourceTypeObject.BucketName;
s3ResourceType.AccessKey = s3ResourceTypeObject.AccessKey ?? s3ResourceType.AccessKey;
s3ResourceType.SecretKey = s3ResourceTypeObject.SecretKey ?? s3ResourceType.SecretKey;
s3ResourceTypeModel.Update(s3ResourceType);
}
else
{
S3ResourceType s3ResourceType = new S3ResourceType()
{
BucketName = s3ResourceTypeObject.BucketName,
AccessKey = s3ResourceTypeObject.AccessKey,
SecretKey = s3ResourceTypeObject.SecretKey
};
s3ResourceTypeModel.Insert(s3ResourceType);
resource.ResourceTypeOptionId = s3ResourceType.Id;
Update(resource);
}
}
else if (resource.Type.DisplayName == "gitlab")
{
GitlabResourceTypeObject gitlabResourceTypeObject = resourceTypeOption.ToObject<GitlabResourceTypeObject>();
......@@ -137,6 +162,17 @@ namespace Coscine.Api.Project.Models
}
}
private string GetRDSBucketName()
{
var prefix = _configuration.GetStringAndWait("coscine/global/buckets/prefix");
var number = Int32.Parse(_configuration.GetStringAndWait("coscine/global/buckets/currentid"));
var maxNumber = Int32.Parse(_configuration.GetStringAndWait("coscine/global/buckets/highestid"));
var newNumber = number % maxNumber == 0 ? 1 : number + 1;
_configuration.Put("coscine/global/buckets/currentid", "" + newNumber);
return String.Format("{0}{1,3:000}", prefix, number);
}
private void SetDisciplines(Resource resource, IEnumerable<DisciplineObject> disciplines)
{
ResourceDisciplineModel resourceDisciplineModel = new ResourceDisciplineModel();
......@@ -220,6 +256,11 @@ namespace Coscine.Api.Project.Models
RDSResourceTypeModel rdsResourceTypeModel = new RDSResourceTypeModel();
rdsResourceTypeModel.Delete(rdsResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value));
}
else if (resource.Type.DisplayName == "s3" && resource.ResourceTypeOptionId != null)
{
S3ResourceTypeModel s3ResourceTypeModel = new S3ResourceTypeModel();
s3ResourceTypeModel.Delete(s3ResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value));
}
else if (resource.Type.DisplayName == "gitlab" && resource.ResourceTypeOptionId != null)
{
GitlabResourceTypeModel gitlabResourceTypeModel = new GitlabResourceTypeModel();
......@@ -255,7 +296,13 @@ namespace Coscine.Api.Project.Models
{
RDSResourceTypeModel rdsResourceTypeModel = new RDSResourceTypeModel();
var rdsResourceType = rdsResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
resourceTypeOptionObject = new RDSResourceTypeObject(rdsResourceType.Id, rdsResourceType.BucketName, null, null);
resourceTypeOptionObject = new RDSResourceTypeObject(rdsResourceType.Id, rdsResourceType.BucketName, (int)rdsResourceType.Size);
}
else if (resource.Type.DisplayName == "s3" && resource.ResourceTypeOptionId != null)
{
S3ResourceTypeModel s3ResourceTypeModel = new S3ResourceTypeModel();
var s3ResourceType = s3ResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
resourceTypeOptionObject = new S3ResourceTypeObject(s3ResourceType.Id, s3ResourceType.BucketName, null, null);
}
else if(resource.Type.DisplayName == "gitlab" && resource.ResourceTypeOptionId != null)
{
......
using Coscine.ApiCommons.Models;
using Coscine.Database.Model;
using LinqToDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Models
{
public class S3ResourceTypeModel : DatabaseModel<S3ResourceType>
{
public S3ResourceTypeModel() : base(Program.Configuration)
{
}
public override Expression<Func<S3ResourceType, Guid>> GetIdFromObject()
{
return (rdsResourceType) => rdsResourceType.Id;
}
public override ITable<S3ResourceType> GetITableFromDatabase(CoscineDB db)
{
return db.S3ResourceTypes;
}
public override void SetObjectId(S3ResourceType databaseObject, Guid id)
{
databaseObject.Id = id;
}
}
}
......@@ -54,8 +54,8 @@
<Reference Include="Coscine.Configuration, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Configuration.1.4.0\lib\net461\Coscine.Configuration.dll</HintPath>
</Reference>
<Reference Include="Coscine.Database, Version=1.10.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.1.10.0\lib\net461\Coscine.Database.dll</HintPath>
<Reference Include="Coscine.Database, Version=1.11.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.Database.1.11.0\lib\net461\Coscine.Database.dll</HintPath>
</Reference>
<Reference Include="Coscine.ProxyApi, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ProxyApi.1.2.0\lib\net461\Coscine.ProxyApi.dll</HintPath>
......@@ -606,6 +606,7 @@
<Compile Include="Models\ProjectModel.cs" />
<Compile Include="Models\ProjectResourceModel.cs" />
<Compile Include="Models\ProjectRoleModel.cs" />
<Compile Include="Models\S3ResourceTypeModel.cs" />
<Compile Include="Models\RDSResourceTypeModel.cs" />
<Compile Include="Models\ResourceDisciplineModel.cs" />
<Compile Include="Models\MetadataModel.cs" />
......@@ -619,6 +620,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReturnObjects\GitlabResourceTypeObject.cs" />
<Compile Include="ReturnObjects\LicenseObject.cs" />
<Compile Include="ReturnObjects\S3ResourceTypeObject.cs" />
<Compile Include="ReturnObjects\RDSResourceTypeObject.cs" />
<Compile Include="ReturnObjects\ResourceTypeOptionObject.cs" />
<Compile Include="ReturnObjects\VisibilityObject.cs" />
......
......@@ -7,16 +7,13 @@ namespace Coscine.Api.Project.ReturnObjects
{
public Guid Id { get; set; }
public string BucketName { get; set; }
public string AccessKey { get; set; }
public string SecretKey { get; set; }
public int Size { get; set; }
public RDSResourceTypeObject(Guid id, string bucketName, string accessKey, string secretKey)
public RDSResourceTypeObject(Guid id, string bucketName, int size)
{
Id = id;
BucketName = bucketName;
AccessKey = accessKey;
SecretKey = secretKey;
Size = size;
}
}
}
using System;
namespace Coscine.Api.Project.ReturnObjects
{
[Serializable]
public class S3ResourceTypeObject : ResourceTypeOptionObject
{
public Guid Id { get; set; }
public string BucketName { get; set; }
public string AccessKey { get; set; }
public string SecretKey { get; set; }
public S3ResourceTypeObject(Guid id, string bucketName, string accessKey, string secretKey)
{
Id = id;
BucketName = bucketName;
AccessKey = accessKey;
SecretKey = secretKey;
}
}
}
......@@ -6,7 +6,7 @@
<package id="Coscine.Action" version="1.7.0" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.2.2" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.10.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.11.0" targetFramework="net472" />
<package id="Coscine.ProxyApi" version="1.2.0" targetFramework="net472" />
<package id="Coscine.SharePoint.Webparts.Vue" version="1.4.0" targetFramework="net472" />
<package id="dotNetRDF" version="2.2.1" targetFramework="net472" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment