Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Admin
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
Terraform modules
Analyze
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
Admin
Commits
f16cfdb2
Commit
f16cfdb2
authored
3 years ago
by
L. Ellenbeck
Browse files
Options
Downloads
Patches
Plain Diff
New: added analytics logger (coscine/issues#2001)
parent
0c93fe15
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!26
Release: Sprint/2022 05 :robot:
,
!24
New: added analytics logger (coscine/issues#2001)
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Admin/Controllers/AdminController.cs
+60
-29
60 additions, 29 deletions
src/Admin/Controllers/AdminController.cs
with
60 additions
and
29 deletions
src/Admin/Controllers/AdminController.cs
+
60
−
29
View file @
f16cfdb2
...
...
@@ -6,14 +6,15 @@ using Coscine.ApiCommons;
using
Coscine.Configuration
;
using
Coscine.Database.DataModel
;
using
Coscine.Database.Models
;
using
Coscine.Logging
;
using
Coscine.Metadata
;
using
Coscine.ResourceLoader
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Logging
;
using
System
;
using
System.Linq
;
namespace
Coscine.Api.Admin.Controllers
{
/// <summary>
...
...
@@ -33,16 +34,17 @@ namespace Coscine.Api.Admin.Controllers
private
readonly
string
_adminRole
;
private
readonly
ResourceModel
_resourceModel
;
private
readonly
ProjectModel
_projectModel
;
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
ProjectQuotaModel
_projectQuotaModel
;
private
readonly
ResourceTypeModel
_resourceTypeModel
;
private
readonly
Emitter
_emitter
;
private
readonly
float
_oneGb
=
1024
*
1024
*
1024
;
private
readonly
CoscineLogger
_coscineLogger
;
/// <summary>
/// Default Constructor.
/// </summary>
public
AdminController
()
public
AdminController
(
ILogger
<
AdminController
>
logger
)
{
_authenticator
=
new
Authenticator
(
this
,
Program
.
Configuration
);
_configuration
=
Program
.
Configuration
;
...
...
@@ -54,10 +56,11 @@ namespace Coscine.Api.Admin.Controllers
_adminRole
=
"supportAdmin"
;
_resourceModel
=
new
ResourceModel
();
_projectModel
=
new
ProjectModel
();
_projectRoleModel
=
new
ProjectRoleModel
();
_projectQuotaModel
=
new
ProjectQuotaModel
();
_resourceTypeModel
=
new
ResourceTypeModel
();
_emitter
=
new
Emitter
(
Program
.
Configuration
);
_coscineLogger
=
new
CoscineLogger
(
logger
);
}
/// <summary>
...
...
@@ -82,12 +85,7 @@ namespace Coscine.Api.Admin.Controllers
// Get the role based on the blank node and compare it to the requested role
var
roleTriples
=
graph
.
GetTriplesWithSubjectPredicate
(
userSubject
,
graph
.
CreateUriNode
(
new
Uri
(
_roleUrl
)));
if
(
roleTriples
?.
FirstOrDefault
()?.
Object
.
ToString
()
!=
$"
{
_roleUrlPrefix
}{
role
}
"
)
{
return
false
;
}
return
true
;
return
(
roleTriples
?.
FirstOrDefault
()?.
Object
.
ToString
())
==
_roleUrlPrefix
+
role
;
}
/// <summary>
...
...
@@ -129,10 +127,10 @@ namespace Coscine.Api.Admin.Controllers
}
/// <summary>
/// Find the project related to the
the
projectString(G
uid
or slug)
/// Find the project related to the projectString(G
UID
or slug)
/// </summary>
/// <param name="projectString">Either the id (
guid
) of the project or the slug.</param>
/// <returns>J
son
list of all quotas.</returns>
/// <param name="projectString">Either the id (
GUID
) of the project or the slug.</param>
/// <returns>J
SON
list of all quotas.</returns>
[
HttpGet
(
"[controller]/{projectString}"
)]
public
ActionResult
<
ProjectObject
>
GetProject
(
string
projectString
)
{
...
...
@@ -147,7 +145,8 @@ namespace Coscine.Api.Admin.Controllers
if
(
Guid
.
TryParse
(
projectString
,
out
Guid
guid
))
{
project
=
_projectModel
.
GetById
(
guid
);
}
else
}
else
{
project
=
_projectModel
.
GetBySlug
(
projectString
);
}
...
...
@@ -164,7 +163,8 @@ namespace Coscine.Api.Admin.Controllers
GUID
=
project
.
Id
,
Name
=
project
.
ProjectName
,
ShortName
=
project
.
DisplayName
,
Quotas
=
quotas
.
Select
(
x
=>
new
ProjectQuotaObject
{
Quotas
=
quotas
.
Select
(
x
=>
new
ProjectQuotaObject
{
QuotaId
=
x
.
RelationId
,
ResourceType
=
_resourceTypeModel
.
GetById
(
x
.
ResourceTypeId
).
DisplayName
,
Quota
=
x
.
Quota
,
...
...
@@ -178,13 +178,13 @@ namespace Coscine.Api.Admin.Controllers
/// <summary>
/// Update the project quota
/// </summary>
/// <param name="updateQuotaParameter">J
son
object for updatin quota.</param>
/// <returns>NoContent (204) on
d
success.</returns>
/// <param name="updateQuotaParameter">J
SOM
object for updatin
g
quota.</param>
/// <returns>NoContent (204) on success.</returns>
[
HttpPost
(
"[controller]/"
)]
public
IActionResult
UpdateQuota
([
FromBody
]
UpdateQuotaParameterObject
updateQuotaParameter
)
{
var
user
=
_authenticator
.
GetUser
Id
();
if
(!
HasRole
(
user
,
_adminRole
))
var
user
=
_authenticator
.
GetUser
();
if
(!
HasRole
(
user
.
Id
.
ToString
()
,
_adminRole
))
{
return
Unauthorized
(
$@"User has not the role: ""
{
_adminRole
}
""."
);
}
...
...
@@ -203,7 +203,38 @@ namespace Coscine.Api.Admin.Controllers
_emitter
.
EmitQuotaChanged
(
new
AdminEventArgs
(
Program
.
Configuration
)
{
ProjectId
=
projectQuota
.
ProjectId
});
if
(
Request
.
Query
!=
null
&&
Request
.
Query
[
"noanalyticslog"
]
!=
"true"
)
{
var
project
=
_projectModel
.
GetById
(
projectQuota
.
ProjectId
);
LogAnalyticsAdminProjectQuotaChange
(
project
,
user
);
}
return
NoContent
();
}
private
void
LogAnalyticsAdminProjectQuotaChange
(
Project
project
,
User
user
)
{
var
quotas
=
_projectQuotaModel
.
GetAllWhere
(
x
=>
x
.
ProjectId
==
project
.
Id
);
var
quotaObjects
=
quotas
.
Select
(
x
=>
new
ProjectQuotaObject
{
QuotaId
=
x
.
RelationId
,
ResourceType
=
_resourceTypeModel
.
GetById
(
x
.
ResourceTypeId
).
DisplayName
,
Quota
=
x
.
Quota
,
MaxQuota
=
x
.
MaxQuota
,
Used
=
x
.
Quota
,
Allocated
=
CalculateAllocatedForAll
(
_resourceTypeModel
.
GetById
(
x
.
ResourceTypeId
),
project
.
Id
)
}).
ToList
();
_coscineLogger
.
AnalyticsLog
(
new
AnalyticsLogObject
{
Type
=
"Action"
,
Operation
=
"Admin Project Quota Change"
,
RoleId
=
_projectRoleModel
.
GetGetUserRoleForProject
(
project
.
Id
,
user
.
Id
).
ToString
(),
UserId
=
user
.
Id
.
ToString
(),
ProjectId
=
project
.
Id
.
ToString
(),
QuotaSize
=
quotaObjects
.
Select
(
x
=>
$"
{
x
.
ResourceType
}
:
{
x
.
Used
}
/
{
x
.
Allocated
}
"
).
ToList
()
});
}
}
}
\ 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