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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
172cabb6
Commit
172cabb6
authored
4 years ago
by
hahn
Browse files
Options
Downloads
Patches
Plain Diff
add api shell script for gitlab runner; remove proof of concept script
parent
b3fc8ffb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
shellscripts/api-client.sh
+0
-132
0 additions, 132 deletions
shellscripts/api-client.sh
shellscripts/api-imlciserver.sh
+165
-0
165 additions, 0 deletions
shellscripts/api-imlciserver.sh
with
165 additions
and
132 deletions
shellscripts/api-client.sh
deleted
100644 → 0
+
0
−
132
View file @
b3fc8ffb
#!/bin/bash
# ======================================================================
#
# API CLIENT :: proof of concept
#
# This is a demo api client
#
# ----------------------------------------------------------------------
#
# my projects and secrets
# DATA:ci-webgui:cOiScVAElvcJKmJ1eGrKXZvv6ZROlSgZ9VpSVFK1uxZI8J5ITXuZZb8jIYobuoAB
#
# ----------------------------------------------------------------------
# 2020-06-12 first lines <axel.hahn@iml.unibe.ch>
# ======================================================================
# ----------------------------------------------------------------------
# CONFIG
# ----------------------------------------------------------------------
apiHost
=
"http://dev.ci.iml.unibe.ch:8002"
line
=
"----------------------------------------------------------------------"
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
function
showhelp
(){
echo
"
SYNTAX
projects show projects
buildinfo [project] [branch]
show infos about what happens on build
build [project] [branch]
execute build
phases [project]
show status of phases
PARAMETERS:
project project id in ci; see output or projects
branch name of branch (optional), i.e. origin/feature-123
"
}
function
makeRequest
(){
local
apiMethod
=
$1
local
apiRequest
=
$2
local
secret
=
$3
echo
$apiMethod
${
apiHost
}${
apiRequest
}
echo
$line
if
[
!
-z
"
$secret
"
]
;
then
# --- date in http format
LANG
=
en_EN
# export TZ=GMT
apiTS
=
`
date
"+%a, %d %b %Y %H:%M:%S %Z"
`
# --- generate data to hash: method + uri + timestamp; delimited with line break
data
=
"
${
apiMethod
}
${
apiRequest
}
${
apiTS
}
"
# 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
"
$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
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
if
[
$#
-lt
1
]
;
then
showhelp
exit
1
fi
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
$line
echo
rc
=
$rc
exit
$rc
\ No newline at end of file
This diff is collapsed.
Click to expand it.
shellscripts/api-imlciserver.sh
0 → 100644
+
165
−
0
View file @
172cabb6
#!/usr/bin/env bash
# ======================================================================
#
# API CLIENT :: API REQUEST TO IML CI SERVER
#
# ----------------------------------------------------------------------
# 2020-07-23 first lines <axel.hahn@iml.unibe.ch>
# ======================================================================
# ----------------------------------------------------------------------
# CONFIG
# ----------------------------------------------------------------------
line
=
"----------------------------------------------------------------------"
# LOG_FILE=/tmp/`basename $0`-last.log
# exec > >(tee -a ${LOG_FILE} )
# exec 2> >(tee -a ${LOG_FILE} >&2)
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
function
showhelp
(){
echo
"
SYNTAX:
-a ACTION set name of an action
-b BRANCH set custom branch to access, i.e. origin/feature-123
-p PROJECT project name in the ci server; overrides env variable IMLCI_PROJECT
-s SECRET API secret for the given project; overrides env variable IMLCI_API_SECRET
-u URL URL of iml ci server without trailing /; overrides env variable IMLCI_URL
ACTION:
... without given project and secret
projects show projects
... with project and secret
buildinfo [branch]
show infos about what happens on build
build [branch]
execute build
phases show status of phases
EXAMPLES:
`
basename
$0
`
-u https://ci.example.com -a projects
`
basename
$0
`
-u https://ci.example.com -p myproject -s 12345678 -a buildinfo
`
basename
$0
`
-u https://ci.example.com -p myproject -s 12345678 -a build
"
}
function
makeRequest
(){
local
apiMethod
=
$1
local
apiRequest
=
$2
local
secret
=
$3
echo
$line
echo
$apiMethod
${
apiHost
}${
apiRequest
}
echo
$line
if
[
!
-z
"
$secret
"
]
;
then
# --- date in http format
LANG
=
en_EN
# export TZ=GMT
apiTS
=
`
date
"+%a, %d %b %Y %H:%M:%S %Z"
`
# --- generate data to hash: method + uri + timestamp; delimited with line break
data
=
"
${
apiMethod
}
${
apiRequest
}
${
apiTS
}
"
# 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
"
$myHash
"
|
base64
`
curl
-i
\
-H
"Accept: application/json"
-H
"Content-Type: application/json"
\
-H
"Date:
${
apiTS
}
"
\
-H
"Authorization: demo-bash-client:
${
myHash
}
"
\
-X
$apiMethod
\
${
IMLCI_URL
}${
apiRequest
}
else
curl
-i
\
-H
"Accept: application/json"
-H
"Content-Type: application/json"
\
-X
$apiMethod
\
${
IMLCI_URL
}${
apiRequest
}
fi
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
echo
echo
=====
API CALL TO IML CI SERVER ::
`
date
`
=====
echo
if
[
$#
-lt
1
]
;
then
showhelp
exit
1
fi
while
getopts
"a:b:u:p:s:"
option
;
do
case
${
option
}
in
a
)
apiAction
=
$OPTARG
;;
b
)
branch
=
$OPTARG
;;
u
)
export
IMLCI_URL
=
$OPTARG
;;
p
)
export
IMLCI_PROJECT
=
$OPTARG
;;
s
)
export
IMLCI_API_SECRET
=
$OPTARG
;;
*
)
echo
ERROR: invalid option
[
${
option
}
]
exit
1
esac
done
echo
Params:
$*
echo
"IMLCI_URL =
$IMLCI_URL
"
echo
"IMLCI_PROJECT =
$IMLCI_PROJECT
"
echo
"IMLCI_API_SECRET =
$IMLCI_API_SECRET
"
echo
echo
ACTION:
$apiAction
case
$apiAction
in
# --- projects is an access without autorization
"projects"
)
makeRequest GET /api/v1/projects
;;
# --- access WITH autorization only
"build"
)
makeRequest POST /api/v1/project/
$IMLCI_PROJECT
/build/
$branch
"
$IMLCI_API_SECRET
"
;;
"buildinfo"
)
makeRequest GET /api/v1/project/
$IMLCI_PROJECT
/build/
$branch
"
$IMLCI_API_SECRET
"
;;
"phases"
)
makeRequest GET /api/v1/project/
$IMLCI_PROJECT
/phases
"
$IMLCI_API_SECRET
"
;;
*
)
echo
"ERROR: unknown action [
$apiAction
]"
exit
2
esac
rc
=
$?
echo
echo
$line
date
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