Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kedifa
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurel
kedifa
Commits
ae0c991a
Commit
ae0c991a
authored
Oct 23, 2020
by
Aurel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
futurize stage1
parent
36685c06
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
35 deletions
+40
-35
kedifa/_version.py
kedifa/_version.py
+1
-0
kedifa/app.py
kedifa/app.py
+1
-1
kedifa/cli.py
kedifa/cli.py
+7
-5
kedifa/test.py
kedifa/test.py
+8
-7
kedifa/updater.py
kedifa/updater.py
+23
-22
No files found.
kedifa/_version.py
View file @
ae0c991a
...
...
@@ -9,6 +9,7 @@
# versioneer-0.18 (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
from
__future__
import
print_function
import
errno
import
os
...
...
kedifa/app.py
View file @
ae0c991a
...
...
@@ -398,7 +398,7 @@ class Kedifa(object):
request_body
=
environ
[
'wsgi.input'
].
read
(
request_body_size
)
try
:
certificate
=
self
.
checkKeyCertificate
(
request_body
)
except
CertificateError
,
e
:
except
CertificateError
as
e
:
start_response
(
'422 Unprocessable Entity'
,
headers_text_plain
)
return
e
else
:
...
...
kedifa/cli.py
View file @
ae0c991a
from
__future__
import
print_function
from
__future__
import
absolute_import
# Copyright (C) 2018 Nexedi SA
# Lukasz Nowak <luke@nexedi.com>
#
...
...
@@ -22,8 +24,8 @@ import httplib
import
requests
import
sys
import
app
from
updater
import
Updater
from
.
import
app
from
.
updater
import
Updater
def
http
(
*
args
):
...
...
@@ -120,12 +122,12 @@ def getter(*args):
response
=
requests
.
get
(
url
,
verify
=
parsed
.
server_ca_certificate
.
name
,
cert
=
parsed
.
identity
.
name
)
except
Exception
as
e
:
print
'%r not downloaded, problem %s'
%
(
url
,
e
)
print
(
'%r not downloaded, problem %s'
%
(
url
,
e
)
)
sys
.
exit
(
1
)
else
:
if
response
.
status_code
!=
httplib
.
OK
:
print
'%r not downloaded, HTTP code %s'
%
(
url
,
response
.
status_code
)
print
(
'%r not downloaded, HTTP code %s'
%
(
url
,
response
.
status_code
)
)
sys
.
exit
(
1
)
if
len
(
response
.
text
)
>
0
:
with
open
(
parsed
.
out
,
'w'
)
as
out
:
...
...
kedifa/test.py
View file @
ae0c991a
from
__future__
import
absolute_import
# Copyright (C) 2018 Nexedi SA
# Lukasz Nowak <luke@nexedi.com>
#
...
...
@@ -17,7 +18,7 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import
StringIO
from
io
import
StringIO
import
contextlib
import
datetime
import
httplib
...
...
@@ -48,8 +49,8 @@ from cryptography.x509.oid import NameOID
import
caucase.cli
import
caucase.http
import
cli
import
updater
from
.
import
cli
from
.
import
updater
def
findFreeTCPPort
(
ip
=
''
):
...
...
@@ -702,7 +703,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def
test_GET_invalid_yet
(
self
):
from
app
import
SQLite3Storage
from
.
app
import
SQLite3Storage
pocket_db
=
SQLite3Storage
(
self
.
db
)
_
,
key_pem
,
_
,
certificate_pem
=
self
.
generateKeyCertificateData
()
not_valid_before
=
datetime
.
datetime
.
utcnow
()
+
datetime
.
timedelta
(
days
=
10
)
...
...
@@ -770,7 +771,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def
test_GET_expired
(
self
):
from
app
import
SQLite3Storage
from
.
app
import
SQLite3Storage
pocket_db
=
SQLite3Storage
(
self
.
db
)
_
,
key_pem
,
_
,
certificate_pem
=
self
.
generateKeyCertificateData
()
not_valid_before
=
datetime
.
datetime
.
utcnow
()
-
datetime
.
timedelta
(
days
=
10
)
...
...
@@ -1060,7 +1061,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def addExpiredNonvalidyetCertificate(self, key):
from app import SQLite3Storage
from
.
app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
not_valid_before_valid = datetime.datetime.utcnow() -
\
...
...
@@ -1090,7 +1091,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
def _getDBCertificateCount(self):
from app import SQLite3Storage
from
.
app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
return pocket_db._executeSingleRow(
'
SELECT
COUNT
(
*
)
FROM
certificate
')['
COUNT
(
*
)
']
...
...
kedifa/updater.py
View file @
ae0c991a
from
__future__
import
print_function
import
httplib
import
json
import
os
...
...
@@ -38,11 +39,11 @@ class Updater(object):
elif
len
(
line_content
)
==
3
:
url
,
certificate
,
fallback
=
line_content
else
:
print
'Line %r is incorrect'
%
(
line
,
)
print
(
'Line %r is incorrect'
%
(
line
,)
)
continue
if
certificate
in
self
.
mapping
:
print
'Line %r is incorrect, duplicated certificate %r'
%
(
line
,
certificate
)
print
(
'Line %r is incorrect, duplicated certificate %r'
%
(
line
,
certificate
)
)
raise
ValueError
self
.
mapping
[
certificate
]
=
(
url
,
fallback
)
...
...
@@ -53,16 +54,16 @@ class Updater(object):
url
,
verify
=
self
.
server_ca_certificate_file
,
cert
=
self
.
identity_file
,
timeout
=
10
)
except
Exception
as
e
:
print
'Certificate %r: problem with %r not downloaded: %s'
%
(
certificate_file
,
url
,
e
)
print
(
'Certificate %r: problem with %r not downloaded: %s'
%
(
certificate_file
,
url
,
e
)
)
else
:
if
response
.
status_code
!=
httplib
.
OK
:
print
'Certificate %r: %r not downloaded, HTTP code %s'
%
(
certificate_file
,
url
,
response
.
status_code
)
print
(
'Certificate %r: %r not downloaded, HTTP code %s'
%
(
certificate_file
,
url
,
response
.
status_code
)
)
else
:
certificate
=
response
.
text
if
len
(
certificate
)
==
0
:
print
'Certificate %r: %r is empty'
%
(
certificate_file
,
url
,
)
print
(
'Certificate %r: %r is empty'
%
(
certificate_file
,
url
,)
)
return
certificate
def
updateCertificate
(
self
,
certificate_file
,
master_content
=
None
):
...
...
@@ -98,7 +99,7 @@ class Updater(object):
if
current
!=
certificate
:
with
open
(
certificate_file
,
'w'
)
as
fh
:
fh
.
write
(
certificate
)
print
'Certificate %r: updated from %r'
%
(
certificate_file
,
url
)
print
(
'Certificate %r: updated from %r'
%
(
certificate_file
,
url
)
)
return
True
else
:
return
False
...
...
@@ -106,7 +107,7 @@ class Updater(object):
def
callOnUpdate
(
self
):
if
self
.
on_update
is
not
None
:
status
=
os
.
system
(
self
.
on_update
)
print
'Called %r with status %i'
%
(
self
.
on_update
,
status
)
print
(
'Called %r with status %i'
%
(
self
.
on_update
,
status
)
)
def
readState
(
self
):
self
.
state_dict
=
{}
...
...
@@ -137,8 +138,8 @@ class Updater(object):
open
(
self
.
master_certificate_file
,
'w'
).
write
(
open
(
master_certificate_file_fallback
,
'r'
).
read
()
)
print
'Prepare: Used %r for %r'
%
(
master_certificate_file_fallback
,
self
.
master_certificate_file
)
print
(
'Prepare: Used %r for %r'
%
(
master_certificate_file_fallback
,
self
.
master_certificate_file
)
)
master_content
=
None
if
self
.
master_certificate_file
and
os
.
path
.
exists
(
...
...
@@ -150,11 +151,11 @@ class Updater(object):
continue
if
fallback
and
os
.
path
.
exists
(
fallback
):
open
(
certificate
,
'w'
).
write
(
open
(
fallback
,
'r'
).
read
())
print
'Prepare: Used %r for %r'
%
(
fallback
,
certificate
)
print
(
'Prepare: Used %r for %r'
%
(
fallback
,
certificate
)
)
elif
master_content
:
open
(
certificate
,
'w'
).
write
(
master_content
)
print
'Prepare: Used %r for %r'
%
(
self
.
master_certificate_file
,
certificate
)
print
(
'Prepare: Used %r for %r'
%
(
self
.
master_certificate_file
,
certificate
)
)
def
action
(
self
):
self
.
readState
()
...
...
@@ -170,8 +171,8 @@ class Updater(object):
with
open
(
self
.
master_certificate_file
,
'r'
)
as
fh
:
master_content
=
fh
.
read
()
or
None
if
master_content
:
print
'Using master certificate from %r'
%
(
self
.
master_certificate_file
,)
print
(
'Using master certificate from %r'
%
(
self
.
master_certificate_file
,)
)
except
IOError
:
pass
...
...
@@ -189,12 +190,12 @@ class Updater(object):
if
not
self
.
prepare_only
:
lock
=
zc
.
lockfile
.
LockFile
(
self
.
state_lock_file
)
except
zc
.
lockfile
.
LockError
as
e
:
print
e
,
print
(
e
,
end
=
' '
)
if
self
.
once
or
self
.
prepare_only
:
print
'...exiting.'
print
(
'...exiting.'
)
sys
.
exit
(
1
)
else
:
print
"...will try again later."
print
(
"...will try again later."
)
else
:
try
:
self
.
prepare
()
...
...
@@ -206,8 +207,8 @@ class Updater(object):
try
:
os
.
unlink
(
self
.
state_lock_file
)
except
Exception
as
e
:
print
'Problem while unlinking %r'
%
(
self
.
state_lock_file
,
)
print
(
'Problem while unlinking %r'
%
(
self
.
state_lock_file
,)
)
if
self
.
once
or
self
.
prepare_only
:
break
print
'Sleeping for %is'
%
(
self
.
sleep
,
)
print
(
'Sleeping for %is'
%
(
self
.
sleep
,)
)
time
.
sleep
(
self
.
sleep
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment