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
1c4e255a
Commit
1c4e255a
authored
4 years ago
by
hahn
Browse files
Options
Downloads
Patches
Plain Diff
task#3869 - initial stuff for API
parent
c1d3313b
Branches
Branches containing commit
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
+16
-11
16 additions, 11 deletions
public_html/api/index.php
shellscripts/api-client.sh
+81
-66
81 additions, 66 deletions
shellscripts/api-client.sh
with
97 additions
and
77 deletions
public_html/api/index.php
+
16
−
11
View file @
1c4e255a
<?php
<?php
/*
/* ======================================================================
* IDEA TO REALIZE:
*
*
* /api/v1/projects/
* A P I F O R C I S E R V E R
* /api/v1/project/[Name]/build/[name-of-branch]]
* /api/v1/project/[Name]/accept/[phase]
*
*
* GET /api/v1/projects/
* GET /api/v1/project/[ID]/build/[name-of-branch]
* POST /api/v1/project/[ID]/build/[name-of-branch]
* get /api/v1/project/[ID]/phases
*
* ----------------------------------------------------------------------
* 2020-06-16 v0.9 <axel.hahn@iml.unibe.ch>
* ======================================================================
*/
*/
$bDebug
=
false
;
$bDebug
=
false
;
...
@@ -171,6 +176,7 @@
...
@@ -171,6 +176,7 @@
$sPrjId
=
isset
(
$aUriSplit
[
2
])
?
$aUriSplit
[
2
]
:
false
;
$sPrjId
=
isset
(
$aUriSplit
[
2
])
?
$aUriSplit
[
2
]
:
false
;
$sPrjAction
=
isset
(
$aUriSplit
[
3
])
?
$aUriSplit
[
3
]
:
false
;
$sPrjAction
=
isset
(
$aUriSplit
[
3
])
?
$aUriSplit
[
3
]
:
false
;
$sParam4
=
isset
(
$aUriSplit
[
4
])
?
$aUriSplit
[
4
]
:
false
;
$sParam4
=
isset
(
$aUriSplit
[
4
])
?
$aUriSplit
[
4
]
:
false
;
$sParam5
=
isset
(
$aUriSplit
[
5
])
?
$aUriSplit
[
5
]
:
false
;
$sMethod
=
$_SERVER
[
'REQUEST_METHOD'
];
$sMethod
=
$_SERVER
[
'REQUEST_METHOD'
];
_wd
(
'$sPrjId = '
.
$sPrjId
);
_wd
(
'$sPrjId = '
.
$sPrjId
);
_wd
(
'$sPrjAction = '
.
$sPrjAction
);
_wd
(
'$sPrjAction = '
.
$sPrjAction
);
...
@@ -205,14 +211,12 @@
...
@@ -205,14 +211,12 @@
switch
(
$sPrjAction
){
switch
(
$sPrjAction
){
case
"build"
:
case
"build"
:
if
(
$sParam4
){
if
(
$sParam4
){
$aResult
=
$oProject
->
setBranchname
(
"origin/"
.
$sParam4
);
$aResult
=
$oProject
->
setBranchname
(
$sParam4
.
(
$sParam5
?
'/'
.
$sParam5
:
''
));
// echo "branch was set.\n";
}
}
$sBranchname
=
$oProject
->
getBranchname
();
$sBranchname
=
$oProject
->
getBranchname
();
$aRepodata
=
$oProject
->
getRemoteBranches
(
true
);
$aRepodata
=
$oProject
->
getRemoteBranches
(
true
);
if
(
!
isset
(
$aRepodata
[
$sBranchname
])){
if
(
!
isset
(
$aRepodata
[
$sBranchname
])){
_quit
(
'ERROR: branch not found '
.
$sBranchname
);
_quit
(
'ERROR: branch not found
:
'
.
$sBranchname
,
404
);
}
}
...
@@ -228,10 +232,11 @@
...
@@ -228,10 +232,11 @@
if
(
$sMethod
===
'POST'
){
if
(
$sMethod
===
'POST'
){
echo
"starting build() ..."
;
echo
"starting build() ..."
;
flush
();
flush
();
die
(
"ABORT"
);
echo
$oProject
->
build
();
echo
$oProject
->
build
();
}
}
break
;;
case
"phases"
:
_done
(
$oProject
->
getAllPhaseInfos
());
break
;;
break
;;
default
:
default
:
_quit
(
'ERROR: Wrong action ['
.
$sApiItem
.
'].'
);
_quit
(
'ERROR: Wrong action ['
.
$sApiItem
.
'].'
);
...
...
This diff is collapsed.
Click to expand it.
shellscripts/api-client.sh
+
81
−
66
View file @
1c4e255a
...
@@ -6,6 +6,11 @@
...
@@ -6,6 +6,11 @@
# This is a demo api client
# This is a demo api client
#
#
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#
# my projects and secrets
# DATA:ci-webgui:cOiScVAElvcJKmJ1eGrKXZvv6ZROlSgZ9VpSVFK1uxZI8J5ITXuZZb8jIYobuoAB
#
# ----------------------------------------------------------------------
# 2020-06-12 first lines <axel.hahn@iml.unibe.ch>
# 2020-06-12 first lines <axel.hahn@iml.unibe.ch>
# ======================================================================
# ======================================================================
...
@@ -13,78 +18,50 @@
...
@@ -13,78 +18,50 @@
# CONFIG
# CONFIG
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
myProject
=
ci-webgui
secret
=
"cOiScVAElvcJKmJ1eGrKXZvv6ZROlSgZ9VpSVFK1uxZI8J5ITXuZZb8jIYobuoAB"
myAction
=
build
myBranch
=
# myBranch=helloworld
# myBranch="task3869-api"
apiHost
=
"http://dev.ci.iml.unibe.ch:8002"
apiHost
=
"http://dev.ci.iml.unibe.ch:8002"
apiBaseUrl
=
"/api/v1"
apiMethod
=
GET
line
=
"----------------------------------------------------------------------"
line
=
"----------------------------------------------------------------------"
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# FUNCTIONS
# FUNCTIONS
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
function
showhelp
(){
function
showhelp
(){
echo
"
echo
"
SYNTAX
SYNTAX
projects show projects
projects show projects
list list branches
info [branch] show infos about what happens on build
build [branch] build
PARAMETERS
buildinfo [project] [branch]
branch name of branch (optional), i.e. feature-123 (without "
origin/
")
show infos about what happens on build
"
}
build [project] [branch]
execute build
# ----------------------------------------------------------------------
phases [project]
# MAIN
show status of phases
# ----------------------------------------------------------------------
if
[
$#
-lt
1
]
;
then
PARAMETERS:
showhelp
project project id in ci; see output or projects
exit
1
branch name of branch (optional), i.e. origin/feature-123
fi
"
}
# ----------------------------------------------------------------------
function
makeRequest
(){
# REQ #1 - list project ids
# ----------------------------------------------------------------------
echo
"[1] GET Request
${
apiHost
}${
apiBaseUrl
}
/projects"
local
apiMethod
=
$1
echo
$line
local
apiRequest
=
$2
curl
-i
\
local
secret
=
$3
-H
"Accept: application/json"
-H
"Content-Type: application/json"
\
-H
"Date:
${
apiTS
}
"
\
-H
"Authorization: demo-bash-client:
${
myHash
}
"
\
-X
$apiMethod
\
${
apiHost
}${
apiBaseUrl
}
/projects
echo
echo
$line
echo
echo
# ----------------------------------------------------------------------
echo
$apiMethod
${
apiHost
}${
apiRequest
}
# REQ #2 - build ci webgui
echo
$line
# ----------------------------------------------------------------------
# --- build url
if
[
!
-z
$secret
]
;
then
apiRequest
=
"
${
apiBaseUrl
}
/project/
${
myProject
}
/
${
myAction
}
"
test
-z
$myBranch
||
apiRequest
=
"
${
apiRequest
}
/
${
myBranch
}
"
# --- date in http format
# --- date in http format
LANG
=
en_EN
LANG
=
en_EN
# export TZ=GMT
# export TZ=GMT
apiTS
=
`
date
"+%a, %d %b %Y %H:%M:%S %Z"
`
apiTS
=
`
date
"+%a, %d %b %Y %H:%M:%S %Z"
`
# --- generate data to hash: method + uri + timestamp; delimited with line break
# --- generate data to hash: method + uri + timestamp; delimited with line break
...
@@ -93,25 +70,63 @@ ${apiRequest}
...
@@ -93,25 +70,63 @@ ${apiRequest}
${
apiTS
}
${
apiTS
}
"
"
# generate hash - split in 2 commands (piping "cut" sends additional line break)
# generate hash - split in 2 commands (piping "cut" sends additional line break)
myHash
=
`
echo
-n
"
$data
"
| openssl sha1
-hmac
"
${
secret
}
"
|
cut
-f
2
-d
" "
`
myHash
=
`
echo
-n
"
$data
"
| openssl sha1
-hmac
"
${
secret
}
"
|
cut
-f
2
-d
" "
`
myHash
=
`
echo
-n
"
$myHash
"
|
base64
`
myHash
=
`
echo
-n
"
$myHash
"
|
base64
`
curl
-i
\
-H
"Accept: application/json"
-H
"Content-Type: application/json"
\
-H
"Date:
${
apiTS
}
"
\
-H
"Authorization: demo-bash-client:
${
myHash
}
"
\
-X
$apiMethod
\
${
apiHost
}${
apiRequest
}
else
curl
-i
\
-H
"Accept: application/json"
-H
"Content-Type: application/json"
\
-X
$apiMethod
\
${
apiHost
}${
apiRequest
}
fi
}
# ---
send htp request
# ---
-------------------------------------------------------------------
echo
"[2]
$apiMethod
Request
${
apiHost
}${
apiRequest
}
"
# MAIN
echo
$line
# ----------------------------------------------------------------------
curl
-i
\
if
[
$#
-lt
1
]
;
then
-H
"Accept: application/json"
-H
"Content-Type: application/json"
\
showhelp
-H
"Date:
${
apiTS
}
"
\
exit
1
-H
"Authorization: demo-bash-client:
${
myHash
}
"
\
fi
-X
$apiMethod
\
${
apiHost
}${
apiRequest
}
rc
=
$?
myProject
=
$2
secret
=
`
grep
"^#
\
DATA:
${
myProject
}
:"
$0
|
cut
-f
3-
-d
":"
`
case
$1
in
# --- projects is an access without autorization
"projects"
)
makeRequest GET /api/v1/projects
;;
# --- access WITH autorization only
"build"
)
makeRequest POST /api/v1/project/
$myProject
/build/
$3
"
$secret
"
;;
"buildinfo"
)
makeRequest GET /api/v1/project/
$myProject
/build/
$3
"
$secret
"
;;
"phases"
)
makeRequest GET /api/v1/project/
$myProject
/phases
"
$secret
"
;;
*
)
echo
"ERROR: unknown parameter
$1
"
exit
2
esac
rc
=
$?
echo
echo
echo
$line
echo
$line
echo
rc
=
$rc
echo
rc
=
$rc
exit
$rc
\ 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