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
55e46a4f
Commit
55e46a4f
authored
5 years ago
by
hahn
Browse files
Options
Downloads
Patches
Plain Diff
task#3869 - update sws class; initial stuff for API
parent
43a4cd28
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
public_html/api/index.php
+138
-0
138 additions, 0 deletions
public_html/api/index.php
public_html/deployment/classes/sws.class.php
+1
-1
1 addition, 1 deletion
public_html/deployment/classes/sws.class.php
with
139 additions
and
1 deletion
public_html/api/index.php
0 → 100644
+
138
−
0
View file @
55e46a4f
<?php
/*
* IDEA TO REALIZE:
*
* /api/v1/projects/
* /api/v1/project/[Name]/[token]/build[/[name-of-branch]]
* /api/v1/project/[Name]/[token]/accept/[phase]
*
*/
$bDebug
=
true
;
ini_set
(
'display_errors'
,
1
);
ini_set
(
'display_startup_errors'
,
1
);
error_reporting
(
E_ALL
);
require_once
(
"../../config/inc_projects_config.php"
);
require_once
(
__DIR__
.
'/../deployment/classes/project.class.php'
);
$aApiItems
=
array
(
'project'
,
'projects'
,
'help'
,
);
// ----------------------------------------------------------------------
// FUNCTIONS
// ----------------------------------------------------------------------
function
_wd
(
$s
,
$sLevel
=
'info'
){
global
$bDebug
;
if
(
$bDebug
){
echo
'<div class="debug ">DEBUG: '
.
$s
.
'</div>'
;
}
return
true
;
}
function
_quit
(
$s
,
$iStatus
=
400
){
$aStatus
=
array
(
400
=>
'HTTP/1.0 400 Bad Request'
,
404
=>
'HTTP/1.0 403 Access denied'
,
);
header
(
$aStatus
[
$iStatus
]);
_done
(
array
(
'status'
=>
$iStatus
,
'info'
=>
$aStatus
[
$iStatus
],
'message'
=>
$s
));
}
function
_done
(
$Data
){
echo
is_array
(
$Data
)
?
json_encode
(
$Data
,
1
,
JSON_PRETTY_PRINT
)
:
$Data
;
die
();
}
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
_wd
(
'Start: '
.
date
(
'Y-m-d H:i:s'
)
.
'<style>body{background:#eee; color:#456;}
.debug{background:#ddd; margin-bottom: 2px;}
</style>'
);
_wd
(
'request uri is '
.
$_SERVER
[
"REQUEST_URI"
]);
_wd
(
'<pre>GET: '
.
print_r
(
$_GET
,
1
)
.
'</pre>'
);
// ---------- SPLIT URL
$aUriSplit
=
explode
(
'/'
,
preg_replace
(
'/\?.*$/'
,
''
,
$_SERVER
[
"REQUEST_URI"
]));
array_shift
(
$aUriSplit
);
array_shift
(
$aUriSplit
);
_wd
(
'<pre>$aUriSplit: '
.
print_r
(
$aUriSplit
,
1
)
.
'</pre>'
);
/*
/api/v1/projects/ci/my-token/build?auth=123
$aUriSplit: Array
(
[0] => v1
[1] => projects
[2] => ci
[3] => my-token
[4] => build
)
*/
$sApiVersion
=
isset
(
$aUriSplit
[
0
])
?
$aUriSplit
[
0
]
:
false
;
$sApiItem
=
isset
(
$aUriSplit
[
1
])
?
$aUriSplit
[
1
]
:
false
;
if
(
!
$sApiVersion
){
_quit
(
'no paramm for api version was found.'
);
}
if
(
!
$sApiItem
){
_quit
(
'ERROR: no paramm for item was found.'
);
}
if
(
!
in_array
(
$sApiItem
,
$aApiItems
)){
_quit
(
'ERROR: item ['
.
$sApiItem
.
'] is invalid.'
);
}
switch
(
$sApiVersion
){
case
'v1'
:
switch
(
$sApiItem
){
case
'projects'
:
$oProject
=
new
project
();
$aList
=
$oProject
->
getProjects
();
_wd
(
'<pre>'
.
print_r
(
$aList
,
1
)
.
'</pre>'
);
_done
(
$aList
);
break
;;
case
'project'
:
$sPrjId
=
isset
(
$aUriSplit
[
2
])
?
$aUriSplit
[
2
]
:
false
;
$sPrjToken
=
isset
(
$aUriSplit
[
3
])
?
$aUriSplit
[
3
]
:
false
;
$sPrjAction
=
isset
(
$aUriSplit
[
4
])
?
$aUriSplit
[
4
]
:
false
;
_wd
(
'$sPrjId = '
.
$sPrjId
);
_wd
(
'$sPrjToken = '
.
$sPrjToken
);
_wd
(
'$sPrjAction = '
.
$sPrjAction
);
$oProject
=
new
project
();
if
(
!
in_array
(
$sPrjId
,
$oProject
->
getProjects
())){
_quit
(
'ERROR: project with id ['
.
$sPrjId
.
'] does not exist.'
);
}
$oProject
->
setProjectById
(
$sPrjId
);
_wd
(
'TODO: verify given token with that in the config.'
);
$aPrjCfg
=
$oProject
->
getConfig
();
_wd
(
'<pre>'
.
print_r
(
$aPrjCfg
,
1
)
.
'</pre>'
);
break
;;
default
:
_quit
(
'ERROR: Wrong item ['
.
$sApiItem
.
'].'
);
}
break
;
default
:
_quit
(
'ERROR: Wrong (unsupported) api version.'
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
public_html/deployment/classes/sws.class.php
+
1
−
1
View file @
55e46a4f
...
@@ -344,7 +344,7 @@ class sws {
...
@@ -344,7 +344,7 @@ class sws {
* @param type $sError
* @param type $sError
*/
*/
private
function
_quit
(
$sError
,
$sMore
=
""
)
{
private
function
_quit
(
$sError
,
$sMore
=
""
)
{
header
(
"
Status:
400 Bad Request"
);
header
(
"
HTTP1.0
400 Bad Request"
);
echo
$this
->
_wrapAsWebpage
(
echo
$this
->
_wrapAsWebpage
(
$sMore
,
'<div class="error">'
.
$sError
.
'</div>'
$sMore
,
'<div class="error">'
.
$sError
.
'</div>'
);
);
...
...
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