Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
6b595fa4
Commit
6b595fa4
authored
2 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
more clear HTTP responses on error
parent
3050dadd
No related branches found
No related tags found
1 merge request
!82
7821 improve api error messages
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/api/index.php
+11
-6
11 additions, 6 deletions
public_html/api/index.php
with
11 additions
and
6 deletions
public_html/api/index.php
+
11
−
6
View file @
6b595fa4
...
@@ -59,7 +59,7 @@ function _wd(string $s, string $sLevel = 'info'): bool
...
@@ -59,7 +59,7 @@ function _wd(string $s, string $sLevel = 'info'): bool
}
}
/**
/**
* Abort execution of API requestwith error
* Abort execution of API request
with error
*
*
* @param string $s message
* @param string $s message
* @param integer $iStatus http status code to send
* @param integer $iStatus http status code to send
...
@@ -68,6 +68,7 @@ function _quit(string $s, int $iStatus = 400): void
...
@@ -68,6 +68,7 @@ function _quit(string $s, int $iStatus = 400): void
{
{
$aStatus
=
[
$aStatus
=
[
400
=>
'HTTP/1.0 400 Bad Request'
,
400
=>
'HTTP/1.0 400 Bad Request'
,
401
=>
'HTTP/1.0 401 Unauthorized'
,
403
=>
'HTTP/1.0 403 Access denied'
,
403
=>
'HTTP/1.0 403 Access denied'
,
404
=>
'HTTP/1.0 404 Not found'
,
404
=>
'HTTP/1.0 404 Not found'
,
];
];
...
@@ -105,7 +106,7 @@ function _checkAuth(string $sProjectSecret): bool
...
@@ -105,7 +106,7 @@ function _checkAuth(string $sProjectSecret): bool
$aReqHeaders
=
apache_request_headers
();
$aReqHeaders
=
apache_request_headers
();
_wd
(
'<pre>'
.
print_r
(
$aReqHeaders
,
1
)
.
'</pre>'
);
_wd
(
'<pre>'
.
print_r
(
$aReqHeaders
,
1
)
.
'</pre>'
);
if
(
!
isset
(
$aReqHeaders
[
'Authorization'
]))
{
if
(
!
isset
(
$aReqHeaders
[
'Authorization'
]))
{
_quit
(
'Access denied. Missing authorization.'
,
40
3
);
_quit
(
'Access denied. Missing authorization.'
,
40
1
);
}
}
if
(
!
isset
(
$aReqHeaders
[
'Date'
]))
{
if
(
!
isset
(
$aReqHeaders
[
'Date'
]))
{
_quit
(
'Access denied. Missing field "Date:" in the request header.'
,
403
);
_quit
(
'Access denied. Missing field "Date:" in the request header.'
,
403
);
...
@@ -123,7 +124,7 @@ function _checkAuth(string $sProjectSecret): bool
...
@@ -123,7 +124,7 @@ function _checkAuth(string $sProjectSecret): bool
_wd
(
'Hash: '
.
$sGotHash
.
' -- from header'
);
_wd
(
'Hash: '
.
$sGotHash
.
' -- from header'
);
_wd
(
'Hash: '
.
$sMyHash
.
' -- rebuilt'
);
_wd
(
'Hash: '
.
$sMyHash
.
' -- rebuilt'
);
if
(
$sGotHash
!==
$sMyHash
)
{
if
(
$sGotHash
!==
$sMyHash
)
{
_quit
(
'Access denied. Invalid hash.'
,
40
3
);
_quit
(
'Access denied. Invalid hash.'
,
40
1
);
}
}
$iAge
=
date
(
'U'
)
-
date
(
'U'
,
strtotime
(
$sGotDate
));
$iAge
=
date
(
'U'
)
-
date
(
'U'
,
strtotime
(
$sGotDate
));
...
@@ -216,14 +217,18 @@ switch ($sApiVersion) {
...
@@ -216,14 +217,18 @@ switch ($sApiVersion) {
ob_end_clean
();
ob_end_clean
();
}
catch
(
Exception
$exc
)
{
}
catch
(
Exception
$exc
)
{
_quit
(
'ERROR: project with id ['
.
$sPrjId
.
']
does not exist
.'
,
40
4
);
_quit
(
'ERROR: project with id ['
.
$sPrjId
.
']
cannot be initialized
.'
,
40
0
);
// never reached
}
}
// get secret
// get secret
$aPrjCfg
=
$oProject
->
getConfig
();
$aPrjCfg
=
$oProject
->
getConfig
();
$sProjectSecret
=
isset
(
$aPrjCfg
[
'api'
][
'secret'
])
?
$aPrjCfg
[
'api'
][
'secret'
]
:
false
;
if
(
!
count
(
$aPrjCfg
)){
_quit
(
'ERROR: project with id ['
.
$sPrjId
.
'] does not exist.'
,
404
);
}
$sProjectSecret
=
$aPrjCfg
[
'api'
][
'secret'
]
??
false
;
if
(
!
$sProjectSecret
)
{
if
(
!
$sProjectSecret
)
{
_quit
(
'Access denied. API access is disabled.'
);
_quit
(
'Access denied. API access is disabled.'
,
403
);
}
}
// check authorization
// check authorization
...
...
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