Skip to content
Snippets Groups Projects

New: Included Mockup for bucket Application

Merged Marcel Nellesen requested to merge Sprint/201922-2 into master
15 files
+ 200
44
Compare changes
  • Side-by-side
  • Inline
Files
15
@@ -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)
{
Loading