Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geant_acme
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Massimiliano Adamo
geant_acme
Commits
ab75f287
Unverified
Commit
ab75f287
authored
6 years ago
by
Max Adamo
Browse files
Options
Downloads
Patches
Plain Diff
compare local key with upstream key
parent
caa4999f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
files/geant_acme.py
+2
-3
2 additions, 3 deletions
files/geant_acme.py
files/geant_acme_uploader.py
+32
-11
32 additions, 11 deletions
files/geant_acme_uploader.py
files/upload_wildcards.py
+31
-9
31 additions, 9 deletions
files/upload_wildcards.py
with
65 additions
and
23 deletions
files/geant_acme.py
+
2
−
3
View file @
ab75f287
...
@@ -119,8 +119,8 @@ def run_certbot(cbot_domain, wild_card=None):
...
@@ -119,8 +119,8 @@ def run_certbot(cbot_domain, wild_card=None):
msg
=
decoded_msg
[:
decoded_msg
.
rfind
(
'
\n
'
)]
msg
=
decoded_msg
[:
decoded_msg
.
rfind
(
'
\n
'
)]
print
(
msg
)
print
(
msg
)
if
msg
.
find
(
'
Certificate not yet due for renewal
'
)
!=
-
1
:
#
if msg.find('Certificate not yet due for renewal') != -1:
os_exit
()
#
os_exit()
return
msg
return
msg
...
@@ -177,7 +177,6 @@ if __name__ == "__main__":
...
@@ -177,7 +177,6 @@ if __name__ == "__main__":
domain_item
,
DEL_STATUS
))
domain_item
,
DEL_STATUS
))
os_exit
()
os_exit
()
# if we are here, everything went fine and we can upload the certificates
# if we are here, everything went fine and we can upload the certificates
if
WILDCARD
:
if
WILDCARD
:
UPLOADER
=
'
/root/bin/upload_wildcards.py -d {}
'
.
format
(
DOMAIN
[
0
])
UPLOADER
=
'
/root/bin/upload_wildcards.py -d {}
'
.
format
(
DOMAIN
[
0
])
...
...
This diff is collapsed.
Click to expand it.
files/geant_acme_uploader.py
+
32
−
11
View file @
ab75f287
...
@@ -20,6 +20,19 @@ import requests
...
@@ -20,6 +20,19 @@ import requests
from
requests.packages.urllib3.exceptions
import
InsecureRequestWarning
#pylint: disable=E0401
from
requests.packages.urllib3.exceptions
import
InsecureRequestWarning
#pylint: disable=E0401
def
redis_download
(
redis_host
,
redis_token
,
key
):
"""
download a key
"""
r_client
=
redis
.
StrictRedis
(
host
=
redis_host
,
password
=
redis_token
,
port
=
6379
,
db
=
0
)
try
:
redis_value
=
r_client
.
get
(
key
).
decode
(
'
utf-8
'
)
except
Exception
as
err
:
redis_value
=
err
return
redis_value
def
redis_upload
(
redis_host
,
redis_token
,
key
,
value
):
def
redis_upload
(
redis_host
,
redis_token
,
key
,
value
):
"""
upload a key
"""
"""
upload a key
"""
r_client
=
redis
.
StrictRedis
(
r_client
=
redis
.
StrictRedis
(
...
@@ -82,17 +95,25 @@ if __name__ == "__main__":
...
@@ -82,17 +95,25 @@ if __name__ == "__main__":
BASEDIR
=
'
/etc/letsencrypt/live
'
BASEDIR
=
'
/etc/letsencrypt/live
'
for
certname
in
[
'
cert.pem
'
,
'
chain.pem
'
,
'
fullchain.pem
'
]:
for
certname
in
[
'
cert.pem
'
,
'
chain.pem
'
,
'
fullchain.pem
'
]:
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
certname
),
'
r
'
)
as
certfile
:
if
os
.
access
(
certname
,
os
.
W_OK
):
certdata
=
certfile
.
read
()
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
certname
),
'
r
'
)
as
certfile
:
domain_underscored
=
DOMAIN
.
replace
(
'
.
'
,
'
_
'
)
certdata_downstream
=
certfile
.
read
()
# let's rename everything to .crt, which is what we normally use
domain_underscored
=
DOMAIN
.
replace
(
'
.
'
,
'
_
'
)
certname_renamed
=
certname
.
replace
(
# let's rename everything to .crt, which is what we normally use
'
cert.pem
'
,
'
crt
'
).
replace
(
'
chain.pem
'
,
'
chain_crt
'
)
certname_renamed
=
certname
.
replace
(
redis_full_path
=
'
{}:redis_{}_{}
'
.
format
(
'
cert.pem
'
,
'
crt
'
).
replace
(
'
chain.pem
'
,
'
chain_crt
'
)
CLIENT
,
domain_underscored
,
certname_renamed
)
redis_full_path
=
'
{}:redis_{}_{}
'
.
format
(
CLIENT
,
domain_underscored
,
certname_renamed
)
print
(
'
uploading to Redis: {}
'
.
format
(
redis_full_path
))
certdata_upstream
=
redis_download
(
REDIS_HOST
,
REDIS_TOKEN
,
redis_full_path
)
redis_upload
(
REDIS_HOST
,
REDIS_TOKEN
,
redis_full_path
,
certdata
)
if
certdata_downstream
!=
certdata_upstream
:
print
(
'
uploading to Redis: {}
'
.
format
(
redis_full_path
))
redis_upload
(
REDIS_HOST
,
REDIS_TOKEN
,
redis_full_path
,
certdata_downstream
)
else
:
print
(
'
key {} did not change: skipping
'
)
else
:
print
(
'
could not access {}: giving up...
'
.
format
(
certname
))
os
.
sys
.
exit
(
1
)
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
'
privkey.pem
'
),
'
r
'
)
as
keyfile
:
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
'
privkey.pem
'
),
'
r
'
)
as
keyfile
:
KEYDATA
=
keyfile
.
read
()
KEYDATA
=
keyfile
.
read
()
...
...
This diff is collapsed.
Click to expand it.
files/upload_wildcards.py
+
31
−
9
View file @
ab75f287
...
@@ -19,6 +19,19 @@ import requests
...
@@ -19,6 +19,19 @@ import requests
from
requests.packages.urllib3.exceptions
import
InsecureRequestWarning
#pylint: disable=E0401
from
requests.packages.urllib3.exceptions
import
InsecureRequestWarning
#pylint: disable=E0401
def
redis_download
(
redis_host
,
redis_token
,
key
):
"""
download a key
"""
r_client
=
redis
.
StrictRedis
(
host
=
redis_host
,
password
=
redis_token
,
port
=
6379
,
db
=
0
)
try
:
redis_value
=
r_client
.
get
(
key
).
decode
(
'
utf-8
'
)
except
Exception
as
err
:
redis_value
=
err
return
redis_value
def
redis_upload
(
redis_host
,
redis_token
,
key
,
value
):
def
redis_upload
(
redis_host
,
redis_token
,
key
,
value
):
"""
upload a key
"""
"""
upload a key
"""
r_client
=
redis
.
StrictRedis
(
r_client
=
redis
.
StrictRedis
(
...
@@ -82,15 +95,24 @@ if __name__ == "__main__":
...
@@ -82,15 +95,24 @@ if __name__ == "__main__":
os
.
sys
.
stdout
=
os
.
sys
.
stderr
=
open
(
'
/var/log/acme/acme.log
'
,
'
a
'
,
1
)
os
.
sys
.
stdout
=
os
.
sys
.
stderr
=
open
(
'
/var/log/acme/acme.log
'
,
'
a
'
,
1
)
# upload certificates to Redis
# upload certificates to Redis
for
keyname
in
[
'
cert.pem
'
,
'
chain.pem
'
,
'
fullchain.pem
'
]:
for
certname
in
[
'
cert.pem
'
,
'
chain.pem
'
,
'
fullchain.pem
'
]:
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
keyname
),
'
r
'
)
as
certfile
:
if
os
.
access
(
certname
,
os
.
W_OK
):
keydata
=
certfile
.
read
()
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
certname
),
'
r
'
)
as
certfile
:
domain_underscored
=
DOMAIN
.
replace
(
'
.
'
,
'
_
'
)
certdata_downstream
=
certfile
.
read
()
keyname_underscored
=
keyname
.
replace
(
'
.
'
,
'
_
'
)
domain_underscored
=
DOMAIN
.
replace
(
'
.
'
,
'
_
'
)
redis_full_path
=
'
common:redis_{}_{}
'
.
format
(
certname_underscored
=
certname
.
replace
(
'
.
'
,
'
_
'
)
domain_underscored
,
keyname_underscored
)
redis_full_path
=
'
common:redis_{}_{}
'
.
format
(
print
(
'
uploading to Redis: {}
'
.
format
(
redis_full_path
))
domain_underscored
,
certname_underscored
)
redis_upload
(
REDIS_HOST
,
REDIS_TOKEN
,
redis_full_path
,
keydata
)
certdata_upstream
=
redis_download
(
REDIS_HOST
,
REDIS_TOKEN
,
redis_full_path
)
if
certdata_downstream
!=
certdata_upstream
:
print
(
'
uploading to Redis: {}
'
.
format
(
redis_full_path
))
redis_upload
(
REDIS_HOST
,
REDIS_TOKEN
,
redis_full_path
,
certdata_downstream
)
else
:
print
(
'
key {} did not change: skipping
'
)
else
:
print
(
'
could not access {}: giving up...
'
.
format
(
certname
))
os
.
sys
.
exit
(
1
)
# upload keys to Vault
# upload keys to Vault
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
'
privkey.pem
'
),
'
r
'
)
as
keyfile
:
with
open
(
os
.
path
.
join
(
BASEDIR
,
DOMAIN
,
'
privkey.pem
'
),
'
r
'
)
as
keyfile
:
...
...
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