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
7b7b77ba
Commit
7b7b77ba
authored
3 years ago
by
Petar Hristov
Browse files
Options
Downloads
Plain Diff
Merge branch 'Hotfix/0071-fixResourceCreate' into 'master'
Hotfix/0071 fix resource create See merge request
!46
parents
ea5c8af4
0cef8fa9
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!46
Hotfix/0071 fix resource create
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Blob/Blob.csproj
+2
-1
2 additions, 1 deletion
src/Blob/Blob.csproj
src/Blob/Controllers/BlobController.cs
+34
-32
34 additions, 32 deletions
src/Blob/Controllers/BlobController.cs
src/Blob/Program.cs
+1
-1
1 addition, 1 deletion
src/Blob/Program.cs
src/Blob/Startup.cs
+5
-5
5 additions, 5 deletions
src/Blob/Startup.cs
with
42 additions
and
39 deletions
src/Blob/Blob.csproj
+
2
−
1
View file @
7b7b77ba
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" />
<PackageReference Include="Coscine.WaterbutlerHelper" Version="2.*-*" />
<PackageReference Include="Coscine.WaterbutlerHelper" Version="2.*-*" />
</ItemGroup>
</ItemGroup>
</Project>
</Project>
This diff is collapsed.
Click to expand it.
src/Blob/Controllers/BlobController.cs
+
34
−
32
View file @
7b7b77ba
...
@@ -27,7 +27,6 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -27,7 +27,6 @@ namespace Coscine.Api.Blob.Controllers
/// This controller represents the actions which can be taken with a Blob object.
/// This controller represents the actions which can be taken with a Blob object.
/// </summary>
/// </summary>
[
Authorize
]
[
Authorize
]
public
class
BlobController
:
Controller
public
class
BlobController
:
Controller
{
{
private
readonly
IConfiguration
_configuration
;
private
readonly
IConfiguration
_configuration
;
...
@@ -80,7 +79,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -80,7 +79,7 @@ namespace Coscine.Api.Blob.Controllers
{
{
if
(!
Guid
.
TryParse
(
resourceId
,
out
Guid
resourceGuid
))
if
(!
Guid
.
TryParse
(
resourceId
,
out
Guid
resourceGuid
))
{
{
return
BadRequest
(
$"
{
resourceId
}
is not a
guid
."
);
return
BadRequest
(
$"
{
resourceId
}
is not a
GUID
."
);
}
}
var
user
=
_authenticator
.
GetUser
();
var
user
=
_authenticator
.
GetUser
();
...
@@ -109,28 +108,31 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -109,28 +108,31 @@ namespace Coscine.Api.Blob.Controllers
return
BadRequest
(
"User does not have permission to the resource."
);
return
BadRequest
(
"User does not have permission to the resource."
);
}
}
if
((
resource
.
Type
.
DisplayName
.
ToLower
()
==
"rds"
||
resource
.
Type
.
DisplayName
.
ToLower
()
==
"rdss3"
)
&&
resource
.
ResourceTypeOptionId
.
HasValue
)
{
try
{
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
resourceTypeOptions
=
_resourceModel
.
GetResourceTypeOptions
(
resource
.
Id
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
var
resourceTypeDefinition
=
ResourceTypeFactory
.
CreateResourceTypeObject
(
resource
.
Type
.
DisplayName
,
_configuration
);
if
(
resourceTypeDefinition
==
null
)
if
(
resourceTypeDefinition
==
null
)
{
{
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
return
BadRequest
(
$"No provider for: \"
{
resource
.
Type
.
DisplayName
}
\"."
);
}
}
var
resourceTypeInformation
=
resourceTypeDefinition
.
GetResourceTypeInformation
().
Result
;
if
(
resource
.
ResourceTypeOptionId
.
HasValue
&&
resourceTypeInformation
.
IsQuotaAvailable
)
{
try
{
var
totalFileSize
=
resourceTypeDefinition
.
GetResourceQuotaUsed
(
resourceId
,
resourceTypeOptions
).
Result
;
var
totalFileSize
=
resourceTypeDefinition
.
GetResourceQuotaUsed
(
resourceId
,
resourceTypeOptions
).
Result
;
return
Ok
(
$"
{{
\
"data\": {{ \"usedSizeByte\": {totalFileSize} }}}}"
);
return
Ok
(
$"
{{
\
"data\": {{ \"usedSizeByte\": {totalFileSize} }}}}"
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
_coscineLogger
.
Log
(
"Get Quota failed"
,
e
);
_coscineLogger
.
Log
(
"Get Quota failed"
,
e
);
return
BadRequest
(
$
"Error in communication with the resource"
);
return
BadRequest
(
"Error in communication with the resource"
);
}
}
}
}
else
else
{
{
return
BadRequest
(
"The resource
type
must be
rds
."
);
return
BadRequest
(
"The resource
quota
must be
adjustable
."
);
}
}
}
}
...
@@ -139,7 +141,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -139,7 +141,7 @@ namespace Coscine.Api.Blob.Controllers
/// </summary>
/// </summary>
/// <param name="resourceId">Id of the resource</param>
/// <param name="resourceId">Id of the resource</param>
/// <param name="path"> Path to the file </param>
/// <param name="path"> Path to the file </param>
/// <returns>File if file exists otherwise
S
tatuscode 204, 400, 401 or 404 </returns>
/// <returns>File if file exists otherwise
s
tatus
code 204, 400, 401 or 404 </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
)
...
@@ -171,14 +173,14 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -171,14 +173,14 @@ namespace Coscine.Api.Blob.Controllers
}
}
var
infos
=
await
resourceTypeDefinition
.
GetEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
var
infos
=
await
resourceTypeDefinition
.
GetEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
var
response
=
await
resourceTypeDefinition
.
LoadEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
var
response
=
await
resourceTypeDefinition
.
LoadEntry
(
resource
.
Id
.
ToString
(),
path
,
null
,
resourceTypeOptions
);
new
FileExtensionContentTypeProvider
().
TryGetContentType
(
path
.
Substring
(
path
.
LastIndexOf
(
"/"
)
)
,
out
string
contentType
);
new
FileExtensionContentTypeProvider
().
TryGetContentType
(
path
[
path
.
LastIndexOf
(
"/"
)
..]
,
out
string
contentType
);
LogAnalytics
(
"Download File"
,
resourceId
,
path
.
Substring
(
1
)
,
user
);
LogAnalytics
(
"Download File"
,
resourceId
,
path
[
1
..]
,
user
);
return
File
(
response
,
contentType
??
"application/octet-stream"
);
return
File
(
response
,
contentType
??
"application/octet-stream"
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
_coscineLogger
.
Log
(
"Get File failed"
,
e
);
_coscineLogger
.
Log
(
"Get File failed"
,
e
);
return
BadRequest
(
$
"Error in communication with the resource"
);
return
BadRequest
(
"Error in communication with the resource"
);
}
}
}
}
...
@@ -188,7 +190,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -188,7 +190,7 @@ namespace Coscine.Api.Blob.Controllers
/// <param name="resourceId">Id of the resource </param>
/// <param name="resourceId">Id of the resource </param>
/// <param name="path">Path to the file</param>
/// <param name="path">Path to the file</param>
/// <param name="files">List of files.</param>
/// <param name="files">List of files.</param>
/// <returns>
S
tatuscode 204 if file is uploaded otherwise
S
tatuscode 400 or 403</returns>
/// <returns>
s
tatus
code 204 if file is uploaded otherwise
s
tatus
code 400 or 403</returns>
[
DisableRequestSizeLimit
]
[
DisableRequestSizeLimit
]
[
RequestFormLimits
(
MultipartBodyLengthLimit
=
long
.
MaxValue
)]
[
RequestFormLimits
(
MultipartBodyLengthLimit
=
long
.
MaxValue
)]
[
HttpPut
(
"[controller]/{resourceId}/{*path}"
)]
[
HttpPut
(
"[controller]/{resourceId}/{*path}"
)]
...
@@ -219,7 +221,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -219,7 +221,7 @@ namespace Coscine.Api.Blob.Controllers
if
(
files
.
Count
!=
1
)
if
(
files
.
Count
!=
1
)
{
{
return
BadRequest
(
$
"Only one file can be uploaded per request."
);
return
BadRequest
(
"Only one file can be uploaded per request."
);
}
}
var
id
=
GenerateId
(
resourceId
,
path
);
var
id
=
GenerateId
(
resourceId
,
path
);
...
@@ -255,7 +257,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -255,7 +257,7 @@ namespace Coscine.Api.Blob.Controllers
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
_coscineLogger
.
Log
(
"Upload File failed"
,
e
);
_coscineLogger
.
Log
(
"Upload File failed"
,
e
);
return
BadRequest
(
$
"Error in communication with the resource"
);
return
BadRequest
(
"Error in communication with the resource"
);
}
}
}
}
...
@@ -264,7 +266,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -264,7 +266,7 @@ namespace Coscine.Api.Blob.Controllers
/// </summary>
/// </summary>
/// <param name="resourceId">Id of the resource </param>
/// <param name="resourceId">Id of the resource </param>
/// <param name="path">Path to the file</param>
/// <param name="path">Path to the file</param>
/// <returns>
S
tatuscode 204 if deletion successful otherwise
S
tatuscode 400, 401 or 404 </returns>
/// <returns>
s
tatus
code 204 if deletion successful otherwise
s
tatus
code 400, 401 or 404 </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
)
{
{
...
@@ -306,14 +308,14 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -306,14 +308,14 @@ namespace Coscine.Api.Blob.Controllers
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
_coscineLogger
.
Log
(
"Delete failed"
,
e
);
_coscineLogger
.
Log
(
"Delete failed"
,
e
);
return
BadRequest
(
$
"Error in communication with the resource"
);
return
BadRequest
(
"Error in communication with the resource"
);
}
}
}
}
/// <summary>
/// <summary>
/// This method checks if the resource is valid
/// This method checks if the resource is valid
/// </summary>
/// </summary>
/// <returns>
S
tatuscode 204 if resource is valid otherwise
S
tatuscode 400 or 404</returns>
/// <returns>
s
tatus
code 204 if resource is valid otherwise
s
tatus
code 400 or 404</returns>
[
HttpPost
(
"[controller]/validate"
)]
[
HttpPost
(
"[controller]/validate"
)]
public
async
Task
<
IActionResult
>
IsResourceValid
([
FromBody
]
JToken
resource
)
public
async
Task
<
IActionResult
>
IsResourceValid
([
FromBody
]
JToken
resource
)
{
{
...
@@ -346,12 +348,12 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -346,12 +348,12 @@ namespace Coscine.Api.Blob.Controllers
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
_coscineLogger
.
Log
(
"Resource validation failed"
,
e
);
_coscineLogger
.
Log
(
"Resource validation failed"
,
e
);
return
BadRequest
(
$
"Error in communication with the resource"
);
return
BadRequest
(
"Error in communication with the resource"
);
}
}
}
}
/// <summary>
/// <summary>
/// Tries to establish connection with resource and validates wether the given file/folder exists
/// Tries to establish connection with resource and validates w
h
ether the given file/folder exists
/// </summary>
/// </summary>
private
IActionResult
CheckResource
(
string
resourceId
,
out
Resource
resource
)
private
IActionResult
CheckResource
(
string
resourceId
,
out
Resource
resource
)
{
{
...
@@ -359,7 +361,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -359,7 +361,7 @@ namespace Coscine.Api.Blob.Controllers
if
(!
Guid
.
TryParse
(
resourceId
,
out
Guid
resourceGuid
))
if
(!
Guid
.
TryParse
(
resourceId
,
out
Guid
resourceGuid
))
{
{
return
BadRequest
(
$"
{
resourceId
}
is not a
guid
."
);
return
BadRequest
(
$"
{
resourceId
}
is not a
GUID
."
);
}
}
try
try
...
@@ -388,7 +390,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -388,7 +390,7 @@ namespace Coscine.Api.Blob.Controllers
/// Checks if the path is valid
/// Checks if the path is valid
/// </summary>
/// </summary>
/// <param name="path">path</param>
/// <param name="path">path</param>
/// <returns>
S
tatuscode 400 if the given path is not valid</returns>
/// <returns>
s
tatus
code 400 if the given path is not valid</returns>
public
IActionResult
CheckPath
(
string
path
)
public
IActionResult
CheckPath
(
string
path
)
{
{
if
(
string
.
IsNullOrWhiteSpace
(
path
))
if
(
string
.
IsNullOrWhiteSpace
(
path
))
...
@@ -415,7 +417,7 @@ namespace Coscine.Api.Blob.Controllers
...
@@ -415,7 +417,7 @@ namespace Coscine.Api.Blob.Controllers
/// </summary>
/// </summary>
/// <param name="user">user</param>
/// <param name="user">user</param>
/// <param name="resource">resource</param>
/// <param name="resource">resource</param>
/// <returns>
S
tatuscode 403 if the user has no access</returns>
/// <returns>
s
tatus
code 403 if the user has no access</returns>
public
IActionResult
CheckUser
(
User
user
,
Resource
resource
)
public
IActionResult
CheckUser
(
User
user
,
Resource
resource
)
{
{
if
(
user
==
null
||
!
_resourceModel
.
HasAccess
(
user
,
resource
,
UserRoles
.
Owner
,
UserRoles
.
Member
))
if
(
user
==
null
||
!
_resourceModel
.
HasAccess
(
user
,
resource
,
UserRoles
.
Owner
,
UserRoles
.
Member
))
...
...
This diff is collapsed.
Click to expand it.
src/Blob/Program.cs
+
1
−
1
View file @
7b7b77ba
This diff is collapsed.
Click to expand it.
src/Blob/Startup.cs
+
5
−
5
View file @
7b7b77ba
using
Coscine.
WaterbutlerHelper.Service
s
;
using
Coscine.
ApiCommon
s
;
using
Coscine.
ApiCommon
s
;
using
Coscine.
WaterbutlerHelper.Service
s
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
using
System
;
...
@@ -16,8 +16,9 @@ namespace Coscine.Api.Blob
...
@@ -16,8 +16,9 @@ namespace Coscine.Api.Blob
public
Startup
()
public
Startup
()
{
{
}
}
/// <summary>
/// <summary>
/// Configures custom service extenions
/// Configures custom service exten
s
ions
/// </summary>
/// </summary>
/// <param name="services">services</param>
/// <param name="services">services</param>
public
override
void
ConfigureServicesExtension
(
IServiceCollection
services
)
public
override
void
ConfigureServicesExtension
(
IServiceCollection
services
)
...
@@ -30,6 +31,5 @@ namespace Coscine.Api.Blob
...
@@ -30,6 +31,5 @@ namespace Coscine.Api.Blob
client
.
Timeout
=
TimeSpan
.
FromMinutes
(
30
);
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