Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BlobApi
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Coscine
backend
apis
BlobApi
Commits
031315ff
Commit
031315ff
authored
May 30, 2022
by
L. Ellenbeck
Committed by
Petar Hristov
May 30, 2022
Browse files
Options
Downloads
Patches
Plain Diff
New: Updated to new resource types
parent
22ee5cf6
No related branches found
No related tags found
1 merge request
!65
Issue/2072 worm resource type
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Blob/Blob.csproj
+1
-4
1 addition, 4 deletions
src/Blob/Blob.csproj
src/Blob/Controllers/BlobController.cs
+23
-72
23 additions, 72 deletions
src/Blob/Controllers/BlobController.cs
src/Blob/Startup.cs
+0
-7
0 additions, 7 deletions
src/Blob/Startup.cs
with
24 additions
and
83 deletions
src/Blob/Blob.csproj
+
1
−
4
View file @
031315ff
...
...
@@ -21,9 +21,6 @@
<PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" />
<PackageReference Include="Coscine.WaterbutlerHelper" Version="2.*-*" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />
<PackageReference Include="Coscine.ResourceTypes" Version="*-*" />
</ItemGroup>
</Project>
This diff is collapsed.
Click to expand it.
src/Blob/Controllers/BlobController.cs
+
23
−
72
View file @
031315ff
...
...
@@ -6,15 +6,13 @@ using Coscine.Database.Models;
using
Coscine.Database.Util
;
using
Coscine.Logging
;
using
Coscine.Metadata
;
using
Coscine.ResourceLoader
;
using
Coscine.ResourceTypeBase
;
using
Coscine.WaterbutlerHelper.Services
;
using
Coscine.ResourceTypes
;
using
Coscine.ResourceTypes.Base.Models
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.StaticFiles
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Net
;
...
...
@@ -44,8 +42,7 @@ namespace Coscine.Api.Blob.Controllers
/// 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
)
{
_configuration
=
Program
.
Configuration
;
_authenticator
=
new
Authenticator
(
this
,
_configuration
);
...
...
@@ -100,7 +97,7 @@ namespace Coscine.Api.Blob.Controllers
if
(
resource
.
Type
==
null
)
{
ResourceTypeModel
resourceTypeModel
=
new
ResourceTypeModel
();
var
resourceTypeModel
=
new
ResourceTypeModel
();
resource
.
Type
=
resourceTypeModel
.
GetById
(
resource
.
TypeId
);
}
...
...
@@ -109,8 +106,7 @@ namespace Coscine.Api.Blob.Controllers
return
BadRequest
(
"User does not have permission to the resource."
);
}
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
Instance
.
GetResourceType
(
resource
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
...
...
@@ -122,7 +118,7 @@ namespace Coscine.Api.Blob.Controllers
{
try
{
var
totalFileSize
=
resourceTypeDefinition
.
GetResourceQuotaUsed
(
resourceId
,
resourceTypeOptions
).
Result
;
var
totalFileSize
=
resourceTypeDefinition
.
GetResourceQuotaUsed
(
resourceId
).
Result
;
return
Ok
(
$"
{{
\
"data\": {{ \"usedSizeByte\": {totalFileSize} }}}}"
);
}
catch
(
Exception
e
)
...
...
@@ -159,7 +155,7 @@ namespace Coscine.Api.Blob.Controllers
/// <returns>File if file exists otherwise status code 204, 400, 401 or 404 </returns>
[
HttpGet
(
"[controller]/{resourceId}/"
)]
[
DisableRequestSizeLimit
]
public
async
Task
<
IActionResult
>
GetFileWithParameter
(
string
resourceId
,
[
System
.
Web
.
Http
.
FromUri
]
string
path
)
public
async
Task
<
IActionResult
>
GetFileWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -179,7 +175,7 @@ namespace Coscine.Api.Blob.Controllers
public
async
Task
<
IActionResult
>
GetFile
(
string
resourceId
,
string
path
)
{
var
user
=
_authenticator
.
GetUser
();
path
=
$"/
{
path
}
"
;
//
path = $"/{path}";
var
checkPath
=
CheckPath
(
path
);
if
(
checkPath
!=
null
)
{
...
...
@@ -195,18 +191,17 @@ namespace Coscine.Api.Blob.Controllers
{
return
checkUser
;
}
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
try
{
var
resourceTypeDefinition
=
ResourceTypeFactory
.
Create
ResourceType
Object
(
resource
.
Type
.
DisplayName
,
_configuration
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
Instance
.
Get
ResourceType
(
resource
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
}
var
infos
=
await
resourceTypeDefinition
.
GetEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
var
response
=
await
resourceTypeDefinition
.
LoadEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
new
FileExtensionContentTypeProvider
().
TryGetContentType
(
path
[
path
.
LastIndexOf
(
"/"
)..]
,
out
string
contentType
);
LogAnalytics
(
"Download File"
,
resourceId
,
path
[
1
..]
,
user
);
var
infos
=
await
resourceTypeDefinition
.
GetEntry
(
resource
.
Id
.
ToString
(),
path
);
var
response
=
await
resourceTypeDefinition
.
LoadEntry
(
resource
.
Id
.
ToString
(),
path
);
new
FileExtensionContentTypeProvider
().
TryGetContentType
(
path
,
out
string
contentType
);
LogAnalytics
(
"Download File"
,
resourceId
,
path
,
user
);
return
File
(
response
,
contentType
??
"application/octet-stream"
);
}
catch
(
Exception
e
)
...
...
@@ -242,7 +237,7 @@ namespace Coscine.Api.Blob.Controllers
[
DisableRequestSizeLimit
]
[
RequestFormLimits
(
MultipartBodyLengthLimit
=
long
.
MaxValue
)]
[
HttpPut
(
"[controller]/{resourceId}/"
)]
public
async
Task
<
IActionResult
>
UploadFileWithParameter
(
string
resourceId
,
[
System
.
Web
.
Http
.
FromUri
]
string
path
,
List
<
IFormFile
>
files
)
public
async
Task
<
IActionResult
>
UploadFileWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
,
List
<
IFormFile
>
files
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -263,7 +258,6 @@ namespace Coscine.Api.Blob.Controllers
public
async
Task
<
IActionResult
>
UploadFile
(
string
resourceId
,
string
path
,
List
<
IFormFile
>
files
)
{
var
user
=
_authenticator
.
GetUser
();
path
=
$"/
{
path
}
"
;
var
checkPath
=
CheckPath
(
path
);
if
(
checkPath
!=
null
)
{
...
...
@@ -290,7 +284,7 @@ namespace Coscine.Api.Blob.Controllers
return
BadRequest
(
"Only one file can be uploaded per request."
);
}
var
id
=
GenerateId
(
resourceId
,
path
);
var
id
=
GenerateId
(
resourceId
,
$"/
{
path
}
"
);
if
(!
_rdfStoreConnector
.
HasGraph
(
id
))
{
return
StatusCode
((
int
)
HttpStatusCode
.
Forbidden
,
...
...
@@ -299,10 +293,8 @@ namespace Coscine.Api.Blob.Controllers
try
{
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
stream
=
files
[
0
].
OpenReadStream
();
resourceTypeOptions
.
Add
(
"ContentLength"
,
stream
.
Length
.
ToString
());
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
Instance
.
GetResourceType
(
resource
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
...
...
@@ -310,13 +302,13 @@ namespace Coscine.Api.Blob.Controllers
ResourceEntry
infos
=
null
;
try
{
infos
=
await
resourceTypeDefinition
.
GetEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
infos
=
await
resourceTypeDefinition
.
GetEntry
(
resource
.
Id
.
ToString
(),
path
,
null
);
}
catch
{
// do nothing
}
await
resourceTypeDefinition
.
StoreEntry
(
resource
.
Id
.
ToString
(),
path
,
stream
,
resourceTypeOptions
);
await
resourceTypeDefinition
.
StoreEntry
(
resource
.
Id
.
ToString
(),
path
,
stream
);
LogAnalytics
(
infos
==
null
?
"Upload File"
:
"Update File"
,
resourceId
,
path
,
user
);
return
NoContent
();
}
...
...
@@ -347,7 +339,7 @@ namespace Coscine.Api.Blob.Controllers
/// <param name="path">Path to the file</param>
/// <returns>status code 204 if deletion successful otherwise status code 400, 401 or 404 </returns>
[
HttpDelete
(
"[controller]/{resourceId}/"
)]
public
async
Task
<
IActionResult
>
DeleteFileWithParameter
(
string
resourceId
,
[
System
.
Web
.
Http
.
FromUri
]
string
path
)
public
async
Task
<
IActionResult
>
DeleteFileWithParameter
(
string
resourceId
,
[
FromQuery
]
string
path
)
{
// Strip the first slash, to reuse the previous implementation.
if
(
path
.
StartsWith
(
"/"
))
...
...
@@ -367,7 +359,7 @@ namespace Coscine.Api.Blob.Controllers
public
async
Task
<
IActionResult
>
DeleteFile
(
string
resourceId
,
string
path
)
{
var
user
=
_authenticator
.
GetUser
();
path
=
$"/
{
path
}
"
;
var
checkPath
=
CheckPath
(
path
);
if
(
checkPath
!=
null
)
{
...
...
@@ -391,13 +383,12 @@ namespace Coscine.Api.Blob.Controllers
try
{
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
Instance
.
GetResourceType
(
resource
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
}
await
resourceTypeDefinition
.
DeleteEntry
(
resource
.
Id
.
ToString
(),
path
,
resourceTypeOptions
);
await
resourceTypeDefinition
.
DeleteEntry
(
resource
.
Id
.
ToString
(),
path
);
LogAnalytics
(
"Delete File"
,
resourceId
,
path
,
user
);
return
NoContent
();
}
...
...
@@ -408,46 +399,6 @@ namespace Coscine.Api.Blob.Controllers
}
}
/// <summary>
/// This method checks if the resource is valid
/// </summary>
/// <returns>status code 204 if resource is valid otherwise status code 400 or 404</returns>
[
HttpPost
(
"[controller]/validate"
)]
public
async
Task
<
IActionResult
>
IsResourceValid
([
FromBody
]
JToken
resource
)
{
var
displayName
=
resource
[
"type"
][
"displayName"
].
ToString
().
ToLower
();
var
resourceTypeOptions
=
new
Dictionary
<
string
,
string
>();
if
(
displayName
==
"s3"
)
{
resourceTypeOptions
.
Add
(
"accessKey"
,
resource
[
"resourceTypeOption"
][
"AccessKey"
].
ToString
());
resourceTypeOptions
.
Add
(
"secretKey"
,
resource
[
"resourceTypeOption"
][
"SecretKey"
].
ToString
());
resourceTypeOptions
.
Add
(
"bucketname"
,
resource
[
"resourceTypeOption"
][
"BucketName"
].
ToString
());
resourceTypeOptions
.
Add
(
"resourceUrl"
,
resource
[
"resourceTypeOption"
][
"ResourceUrl"
].
ToString
());
}
else
if
(
displayName
==
"gitlab"
)
{
resourceTypeOptions
.
Add
(
"token"
,
resource
[
"resourceTypeOption"
][
"Token"
].
ToString
());
resourceTypeOptions
.
Add
(
"repositoryUrl"
,
resource
[
"resourceTypeOption"
][
"RepositoryUrl"
].
ToString
());
resourceTypeOptions
.
Add
(
"repositoryNumber"
,
resource
[
"resourceTypeOption"
][
"RepositoryNumber"
].
ToString
());
}
try
{
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
displayName
,
_configuration
);
if
(
resourceTypeDefinition
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
displayName
}
\"."
);
}
await
resourceTypeDefinition
.
IsResourceCreated
(
""
,
resourceTypeOptions
);
return
NoContent
();
}
catch
(
Exception
e
)
{
_coscineLogger
.
Log
(
"Resource validation failed"
,
e
);
return
BadRequest
(
"Error in communication with the resource"
);
}
}
/// <summary>
/// Tries to establish connection with resource and validates whether the given file/folder exists
/// </summary>
...
...
@@ -475,7 +426,7 @@ namespace Coscine.Api.Blob.Controllers
if
(
resource
.
Type
==
null
)
{
ResourceTypeModel
resourceTypeModel
=
new
ResourceTypeModel
();
var
resourceTypeModel
=
new
ResourceTypeModel
();
resource
.
Type
=
resourceTypeModel
.
GetById
(
resource
.
TypeId
);
}
// All good
...
...
This diff is collapsed.
Click to expand it.
src/Blob/Startup.cs
+
0
−
7
View file @
031315ff
using
Coscine.ApiCommons
;
using
Coscine.WaterbutlerHelper.Services
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
...
...
@@ -24,12 +23,6 @@ namespace Coscine.Api.Blob
public
override
void
ConfigureServicesExtension
(
IServiceCollection
services
)
{
base
.
ConfigureServicesExtension
(
services
);
services
.
AddHttpClient
<
IDataSourceService
,
DataSourceService
>(
client
=>
{
//TODO: Discuss Timeout value
client
.
Timeout
=
TimeSpan
.
FromMinutes
(
30
);
});
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment