]> git.proxmox.com Git - mirror_acme.sh.git/blob - deploy/gitlab.sh
Merge pull request #4334 from sasburg/patch-1
[mirror_acme.sh.git] / deploy / gitlab.sh
1 #!/usr/bin/env sh
2
3 # Script to deploy certificate to a Gitlab hosted page
4
5 # The following variables exported from environment will be used.
6 # If not set then values previously saved in domain.conf file are used.
7
8 # All the variables are required
9
10 # export GITLAB_TOKEN="xxxxxxx"
11 # export GITLAB_PROJECT_ID=012345
12 # export GITLAB_DOMAIN="mydomain.com"
13
14 gitlab_deploy() {
15 _cdomain="$1"
16 _ckey="$2"
17 _ccert="$3"
18 _cca="$4"
19 _cfullchain="$5"
20
21 _debug _cdomain "$_cdomain"
22 _debug _ckey "$_ckey"
23 _debug _ccert "$_ccert"
24 _debug _cca "$_cca"
25 _debug _cfullchain "$_cfullchain"
26
27 if [ -z "$GITLAB_TOKEN" ]; then
28 if [ -z "$Le_Deploy_gitlab_token" ]; then
29 _err "GITLAB_TOKEN not defined."
30 return 1
31 fi
32 else
33 Le_Deploy_gitlab_token="$GITLAB_TOKEN"
34 _savedomainconf Le_Deploy_gitlab_token "$Le_Deploy_gitlab_token"
35 fi
36
37 if [ -z "$GITLAB_PROJECT_ID" ]; then
38 if [ -z "$Le_Deploy_gitlab_project_id" ]; then
39 _err "GITLAB_PROJECT_ID not defined."
40 return 1
41 fi
42 else
43 Le_Deploy_gitlab_project_id="$GITLAB_PROJECT_ID"
44 _savedomainconf Le_Deploy_gitlab_project_id "$Le_Deploy_gitlab_project_id"
45 fi
46
47 if [ -z "$GITLAB_DOMAIN" ]; then
48 if [ -z "$Le_Deploy_gitlab_domain" ]; then
49 _err "GITLAB_DOMAIN not defined."
50 return 1
51 fi
52 else
53 Le_Deploy_gitlab_domain="$GITLAB_DOMAIN"
54 _savedomainconf Le_Deploy_gitlab_domain "$Le_Deploy_gitlab_domain"
55 fi
56
57 string_fullchain=$(_url_encode <"$_cfullchain")
58 string_key=$(_url_encode <"$_ckey")
59
60 body="certificate=$string_fullchain&key=$string_key"
61
62 export _H1="PRIVATE-TOKEN: $Le_Deploy_gitlab_token"
63
64 gitlab_url="https://gitlab.com/api/v4/projects/$Le_Deploy_gitlab_project_id/pages/domains/$Le_Deploy_gitlab_domain"
65
66 _response=$(_post "$body" "$gitlab_url" 0 PUT | _dbase64 "multiline")
67
68 error_response="error"
69
70 if test "${_response#*$error_response}" != "$_response"; then
71 _err "Error in deploying certificate:"
72 _err "$_response"
73 return 1
74 fi
75
76 _debug response "$_response"
77 _info "Certificate successfully deployed"
78
79 return 0
80 }