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
Hide 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 @@
...
@@ -9,6 +9,7 @@
# versioneer-0.18 (https://github.com/warner/python-versioneer)
# versioneer-0.18 (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
"""Git implementation of _version.py."""
from
__future__
import
print_function
import
errno
import
errno
import
os
import
os
...
...
kedifa/app.py
View file @
ae0c991a
...
@@ -398,7 +398,7 @@ class Kedifa(object):
...
@@ -398,7 +398,7 @@ class Kedifa(object):
request_body
=
environ
[
'wsgi.input'
].
read
(
request_body_size
)
request_body
=
environ
[
'wsgi.input'
].
read
(
request_body_size
)
try
:
try
:
certificate
=
self
.
checkKeyCertificate
(
request_body
)
certificate
=
self
.
checkKeyCertificate
(
request_body
)
except
CertificateError
,
e
:
except
CertificateError
as
e
:
start_response
(
'422 Unprocessable Entity'
,
headers_text_plain
)
start_response
(
'422 Unprocessable Entity'
,
headers_text_plain
)
return
e
return
e
else
:
else
:
...
...
kedifa/cli.py
View file @
ae0c991a
from
__future__
import
print_function
from
__future__
import
absolute_import
# Copyright (C) 2018 Nexedi SA
# Copyright (C) 2018 Nexedi SA
# Lukasz Nowak <luke@nexedi.com>
# Lukasz Nowak <luke@nexedi.com>
#
#
...
@@ -22,8 +24,8 @@ import httplib
...
@@ -22,8 +24,8 @@ import httplib
import
requests
import
requests
import
sys
import
sys
import
app
from
.
import
app
from
updater
import
Updater
from
.
updater
import
Updater
def
http
(
*
args
):
def
http
(
*
args
):
...
@@ -120,12 +122,12 @@ def getter(*args):
...
@@ -120,12 +122,12 @@ def getter(*args):
response
=
requests
.
get
(
url
,
verify
=
parsed
.
server_ca_certificate
.
name
,
response
=
requests
.
get
(
url
,
verify
=
parsed
.
server_ca_certificate
.
name
,
cert
=
parsed
.
identity
.
name
)
cert
=
parsed
.
identity
.
name
)
except
Exception
as
e
:
except
Exception
as
e
:
print
'%r not downloaded, problem %s'
%
(
url
,
e
)
print
(
'%r not downloaded, problem %s'
%
(
url
,
e
)
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
else
:
if
response
.
status_code
!=
httplib
.
OK
:
if
response
.
status_code
!=
httplib
.
OK
:
print
'%r not downloaded, HTTP code %s'
%
(
print
(
'%r not downloaded, HTTP code %s'
%
(
url
,
response
.
status_code
)
url
,
response
.
status_code
)
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
if
len
(
response
.
text
)
>
0
:
if
len
(
response
.
text
)
>
0
:
with
open
(
parsed
.
out
,
'w'
)
as
out
:
with
open
(
parsed
.
out
,
'w'
)
as
out
:
...
...
kedifa/test.py
View file @
ae0c991a
from
__future__
import
absolute_import
# Copyright (C) 2018 Nexedi SA
# Copyright (C) 2018 Nexedi SA
# Lukasz Nowak <luke@nexedi.com>
# Lukasz Nowak <luke@nexedi.com>
#
#
...
@@ -17,7 +18,7 @@
...
@@ -17,7 +18,7 @@
# See COPYING file for full licensing terms.
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# See https://www.nexedi.com/licensing for rationale and options.
import
StringIO
from
io
import
StringIO
import
contextlib
import
contextlib
import
datetime
import
datetime
import
httplib
import
httplib
...
@@ -48,8 +49,8 @@ from cryptography.x509.oid import NameOID
...
@@ -48,8 +49,8 @@ from cryptography.x509.oid import NameOID
import
caucase.cli
import
caucase.cli
import
caucase.http
import
caucase.http
import
cli
from
.
import
cli
import
updater
from
.
import
updater
def
findFreeTCPPort
(
ip
=
''
):
def
findFreeTCPPort
(
ip
=
''
):
...
@@ -702,7 +703,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
...
@@ -702,7 +703,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
)
def
test_GET_invalid_yet
(
self
):
def
test_GET_invalid_yet
(
self
):
from
app
import
SQLite3Storage
from
.
app
import
SQLite3Storage
pocket_db
=
SQLite3Storage
(
self
.
db
)
pocket_db
=
SQLite3Storage
(
self
.
db
)
_
,
key_pem
,
_
,
certificate_pem
=
self
.
generateKeyCertificateData
()
_
,
key_pem
,
_
,
certificate_pem
=
self
.
generateKeyCertificateData
()
not_valid_before
=
datetime
.
datetime
.
utcnow
()
+
datetime
.
timedelta
(
days
=
10
)
not_valid_before
=
datetime
.
datetime
.
utcnow
()
+
datetime
.
timedelta
(
days
=
10
)
...
@@ -770,7 +771,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
...
@@ -770,7 +771,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
)
def
test_GET_expired
(
self
):
def
test_GET_expired
(
self
):
from
app
import
SQLite3Storage
from
.
app
import
SQLite3Storage
pocket_db
=
SQLite3Storage
(
self
.
db
)
pocket_db
=
SQLite3Storage
(
self
.
db
)
_
,
key_pem
,
_
,
certificate_pem
=
self
.
generateKeyCertificateData
()
_
,
key_pem
,
_
,
certificate_pem
=
self
.
generateKeyCertificateData
()
not_valid_before
=
datetime
.
datetime
.
utcnow
()
-
datetime
.
timedelta
(
days
=
10
)
not_valid_before
=
datetime
.
datetime
.
utcnow
()
-
datetime
.
timedelta
(
days
=
10
)
...
@@ -1060,7 +1061,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
...
@@ -1060,7 +1061,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
)
def addExpiredNonvalidyetCertificate(self, key):
def addExpiredNonvalidyetCertificate(self, key):
from app import SQLite3Storage
from
.
app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
pocket_db = SQLite3Storage(self.db)
not_valid_before_valid = datetime.datetime.utcnow() -
\
not_valid_before_valid = datetime.datetime.utcnow() -
\
...
@@ -1090,7 +1091,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
...
@@ -1090,7 +1091,7 @@ class KedifaIntegrationTest(KedifaMixinCaucase, unittest.TestCase):
)
)
def _getDBCertificateCount(self):
def _getDBCertificateCount(self):
from app import SQLite3Storage
from
.
app import SQLite3Storage
pocket_db = SQLite3Storage(self.db)
pocket_db = SQLite3Storage(self.db)
return pocket_db._executeSingleRow(
return pocket_db._executeSingleRow(
'
SELECT
COUNT
(
*
)
FROM
certificate
')['
COUNT
(
*
)
']
'
SELECT
COUNT
(
*
)
FROM
certificate
')['
COUNT
(
*
)
']
...
...
kedifa/updater.py
View file @
ae0c991a
from
__future__
import
print_function
import
httplib
import
httplib
import
json
import
json
import
os
import
os
...
@@ -38,11 +39,11 @@ class Updater(object):
...
@@ -38,11 +39,11 @@ class Updater(object):
elif
len
(
line_content
)
==
3
:
elif
len
(
line_content
)
==
3
:
url
,
certificate
,
fallback
=
line_content
url
,
certificate
,
fallback
=
line_content
else
:
else
:
print
'Line %r is incorrect'
%
(
line
,
)
print
(
'Line %r is incorrect'
%
(
line
,)
)
continue
continue
if
certificate
in
self
.
mapping
:
if
certificate
in
self
.
mapping
:
print
'Line %r is incorrect, duplicated certificate %r'
%
(
print
(
'Line %r is incorrect, duplicated certificate %r'
%
(
line
,
certificate
)
line
,
certificate
)
)
raise
ValueError
raise
ValueError
self
.
mapping
[
certificate
]
=
(
url
,
fallback
)
self
.
mapping
[
certificate
]
=
(
url
,
fallback
)
...
@@ -53,16 +54,16 @@ class Updater(object):
...
@@ -53,16 +54,16 @@ class Updater(object):
url
,
verify
=
self
.
server_ca_certificate_file
,
cert
=
self
.
identity_file
,
url
,
verify
=
self
.
server_ca_certificate_file
,
cert
=
self
.
identity_file
,
timeout
=
10
)
timeout
=
10
)
except
Exception
as
e
:
except
Exception
as
e
:
print
'Certificate %r: problem with %r not downloaded: %s'
%
(
print
(
'Certificate %r: problem with %r not downloaded: %s'
%
(
certificate_file
,
url
,
e
)
certificate_file
,
url
,
e
)
)
else
:
else
:
if
response
.
status_code
!=
httplib
.
OK
:
if
response
.
status_code
!=
httplib
.
OK
:
print
'Certificate %r: %r not downloaded, HTTP code %s'
%
(
print
(
'Certificate %r: %r not downloaded, HTTP code %s'
%
(
certificate_file
,
url
,
response
.
status_code
)
certificate_file
,
url
,
response
.
status_code
)
)
else
:
else
:
certificate
=
response
.
text
certificate
=
response
.
text
if
len
(
certificate
)
==
0
:
if
len
(
certificate
)
==
0
:
print
'Certificate %r: %r is empty'
%
(
certificate_file
,
url
,
)
print
(
'Certificate %r: %r is empty'
%
(
certificate_file
,
url
,)
)
return
certificate
return
certificate
def
updateCertificate
(
self
,
certificate_file
,
master_content
=
None
):
def
updateCertificate
(
self
,
certificate_file
,
master_content
=
None
):
...
@@ -98,7 +99,7 @@ class Updater(object):
...
@@ -98,7 +99,7 @@ class Updater(object):
if
current
!=
certificate
:
if
current
!=
certificate
:
with
open
(
certificate_file
,
'w'
)
as
fh
:
with
open
(
certificate_file
,
'w'
)
as
fh
:
fh
.
write
(
certificate
)
fh
.
write
(
certificate
)
print
'Certificate %r: updated from %r'
%
(
certificate_file
,
url
)
print
(
'Certificate %r: updated from %r'
%
(
certificate_file
,
url
)
)
return
True
return
True
else
:
else
:
return
False
return
False
...
@@ -106,7 +107,7 @@ class Updater(object):
...
@@ -106,7 +107,7 @@ class Updater(object):
def
callOnUpdate
(
self
):
def
callOnUpdate
(
self
):
if
self
.
on_update
is
not
None
:
if
self
.
on_update
is
not
None
:
status
=
os
.
system
(
self
.
on_update
)
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
):
def
readState
(
self
):
self
.
state_dict
=
{}
self
.
state_dict
=
{}
...
@@ -137,8 +138,8 @@ class Updater(object):
...
@@ -137,8 +138,8 @@ class Updater(object):
open
(
self
.
master_certificate_file
,
'w'
).
write
(
open
(
self
.
master_certificate_file
,
'w'
).
write
(
open
(
master_certificate_file_fallback
,
'r'
).
read
()
open
(
master_certificate_file_fallback
,
'r'
).
read
()
)
)
print
'Prepare: Used %r for %r'
%
(
print
(
'Prepare: Used %r for %r'
%
(
master_certificate_file_fallback
,
self
.
master_certificate_file
)
master_certificate_file_fallback
,
self
.
master_certificate_file
)
)
master_content
=
None
master_content
=
None
if
self
.
master_certificate_file
and
os
.
path
.
exists
(
if
self
.
master_certificate_file
and
os
.
path
.
exists
(
...
@@ -150,11 +151,11 @@ class Updater(object):
...
@@ -150,11 +151,11 @@ class Updater(object):
continue
continue
if
fallback
and
os
.
path
.
exists
(
fallback
):
if
fallback
and
os
.
path
.
exists
(
fallback
):
open
(
certificate
,
'w'
).
write
(
open
(
fallback
,
'r'
).
read
())
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
:
elif
master_content
:
open
(
certificate
,
'w'
).
write
(
master_content
)
open
(
certificate
,
'w'
).
write
(
master_content
)
print
'Prepare: Used %r for %r'
%
(
print
(
'Prepare: Used %r for %r'
%
(
self
.
master_certificate_file
,
certificate
)
self
.
master_certificate_file
,
certificate
)
)
def
action
(
self
):
def
action
(
self
):
self
.
readState
()
self
.
readState
()
...
@@ -170,8 +171,8 @@ class Updater(object):
...
@@ -170,8 +171,8 @@ class Updater(object):
with
open
(
self
.
master_certificate_file
,
'r'
)
as
fh
:
with
open
(
self
.
master_certificate_file
,
'r'
)
as
fh
:
master_content
=
fh
.
read
()
or
None
master_content
=
fh
.
read
()
or
None
if
master_content
:
if
master_content
:
print
'Using master certificate from %r'
%
(
print
(
'Using master certificate from %r'
%
(
self
.
master_certificate_file
,)
self
.
master_certificate_file
,)
)
except
IOError
:
except
IOError
:
pass
pass
...
@@ -189,12 +190,12 @@ class Updater(object):
...
@@ -189,12 +190,12 @@ class Updater(object):
if
not
self
.
prepare_only
:
if
not
self
.
prepare_only
:
lock
=
zc
.
lockfile
.
LockFile
(
self
.
state_lock_file
)
lock
=
zc
.
lockfile
.
LockFile
(
self
.
state_lock_file
)
except
zc
.
lockfile
.
LockError
as
e
:
except
zc
.
lockfile
.
LockError
as
e
:
print
e
,
print
(
e
,
end
=
' '
)
if
self
.
once
or
self
.
prepare_only
:
if
self
.
once
or
self
.
prepare_only
:
print
'...exiting.'
print
(
'...exiting.'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
else
:
print
"...will try again later."
print
(
"...will try again later."
)
else
:
else
:
try
:
try
:
self
.
prepare
()
self
.
prepare
()
...
@@ -206,8 +207,8 @@ class Updater(object):
...
@@ -206,8 +207,8 @@ class Updater(object):
try
:
try
:
os
.
unlink
(
self
.
state_lock_file
)
os
.
unlink
(
self
.
state_lock_file
)
except
Exception
as
e
:
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
:
if
self
.
once
or
self
.
prepare_only
:
break
break
print
'Sleeping for %is'
%
(
self
.
sleep
,
)
print
(
'Sleeping for %is'
%
(
self
.
sleep
,)
)
time
.
sleep
(
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