Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Project
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
Project
Commits
61a1f0ee
Commit
61a1f0ee
authored
5 years ago
by
David Schimmel
Committed by
Marcel Nellesen
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Included Server side validation on resource setup step
parent
eb457487
No related branches found
No related tags found
1 merge request
!30
Fix: Included Server side validation on resource setup step
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Project/Controllers/DataSourceController.cs
+63
-2
63 additions, 2 deletions
src/Project/Controllers/DataSourceController.cs
with
63 additions
and
2 deletions
src/Project/Controllers/DataSourceController.cs
+
63
−
2
View file @
61a1f0ee
using
Coscine.Api.Project.Models
;
using
Coscine.Api.Project.ReturnObjects
;
using
Coscine.ApiCommons
;
using
Coscine.ApiCommons.Factories
;
using
Coscine.ApiCommons.Utils
;
using
Coscine.Configuration
;
using
Coscine.Database.Model
;
...
...
@@ -255,6 +256,66 @@ namespace Coscine.Api.Project.Controllers
}
}
[
HttpPost
(
"[controller]/validate"
)]
public
async
Task
<
IActionResult
>
IsResourceValid
()
{
var
path
=
"/"
;
JToken
resource
=
ObjectFactory
<
JToken
>.
DeserializeFromStream
(
Request
.
Body
);
string
authHeader
=
null
;
if
(
resource
[
"type"
][
"displayName"
].
ToString
().
ToLower
()
==
"rds"
)
{
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
);
}
else
if
(
resource
[
"type"
][
"displayName"
].
ToString
().
ToLower
()
==
"gitlab"
)
{
GitlabResourceType
gitlabResourceType
=
new
GitlabResourceType
();
gitlabResourceType
.
RepositoryNumber
=
(
int
)
resource
[
"resourceTypeOption"
][
"RepositoryNumber"
];
gitlabResourceType
.
RepositoryUrl
=
resource
[
"resourceTypeOption"
][
"RepositoryUrl"
].
ToString
();
gitlabResourceType
.
Token
=
resource
[
"resourceTypeOption"
][
"Token"
].
ToString
();
authHeader
=
BuildGitlabAuthHeader
(
gitlabResourceType
);
}
if
(
authHeader
==
null
)
{
return
BadRequest
(
$"No provider for: \"
{
resource
[
"type"
][
"displayName"
].
ToString
()}
\"."
);
}
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
}
"
;
var
request
=
new
HttpRequestMessage
(
HttpMethod
.
Get
,
url
);
request
.
Headers
.
Authorization
=
new
AuthenticationHeaderValue
(
"Bearer"
,
authHeader
);
// Thread safe according to msdn and HttpCompletionOption sets it to get only headers first.
var
response
=
await
Client
.
SendAsync
(
request
,
HttpCompletionOption
.
ResponseHeadersRead
);
if
(
response
.
IsSuccessStatusCode
)
{
if
(
response
.
Content
.
Headers
.
Contains
(
"Content-Disposition"
))
{
return
File
(
await
response
.
Content
.
ReadAsStreamAsync
(),
response
.
Content
.
Headers
.
GetValues
(
"Content-Type"
).
First
());
}
else
{
var
data
=
JObject
.
Parse
(
await
response
.
Content
.
ReadAsStringAsync
())[
"data"
];
return
Ok
(
new
WaterbutlerObject
(
path
,
data
));
}
}
else
{
return
FailedRequest
(
response
,
path
);
}
}
}
private
IActionResult
FailedRequest
(
HttpResponseMessage
response
,
string
path
)
{
if
(
response
.
StatusCode
==
System
.
Net
.
HttpStatusCode
.
NotFound
)
...
...
@@ -395,7 +456,7 @@ namespace Coscine.Api.Project.Controllers
{
{
"owner"
,
"Tester"
},
{
"repo"
,
gitlabResourceType
.
RepositoryUrl
},
{
"repo_id"
,
gitlabResourceType
.
RepositoryNumber
},
{
"repo_id"
,
gitlabResourceType
.
RepositoryNumber
.
ToString
()
},
{
"host"
,
"https://git.rwth-aachen.de"
}
};
...
...
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