Skip to content

Commit c294945

Browse files
authored
Merge pull request #92 from skalenetwork/fix-ssl-certs-uploading
Fix ssl certs uploading
2 parents b6335d1 + c639fc6 commit c294945

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

cli/ssl.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
# You should have received a copy of the GNU Affero General Public License
1818
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1919

20-
import json
2120
import click
2221
from terminaltables import SingleTable
2322

24-
from core.helper import login_required, get, post, safe_load_texts, load_ssl_files
23+
from core.helper import login_required, get, safe_load_texts, upload_certs
2524

2625

2726
TEXTS = safe_load_texts()
@@ -69,9 +68,7 @@ def status():
6968
@click.option('--force', '-f', is_flag=True, help='Overwrite existing certificates')
7069
@login_required
7170
def upload(key_path, cert_path, force):
72-
files = load_ssl_files(key_path, cert_path)
73-
files['json'] = (None, json.dumps({'force': force}), 'application/json')
74-
response = post('ssl_upload', files=files)
71+
response = upload_certs(key_path, cert_path, force)
7572
if not response:
7673
print('Someting went wrong, sorry')
7774
return

core/helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU Affero General Public License
1818
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1919

20+
import json
2021
import os
2122
import re
2223
import pickle
@@ -265,3 +266,18 @@ def load_ssl_files(key_path, cert_path):
265266
def read_file(path, mode='rb'):
266267
with open(path, mode) as f:
267268
return f
269+
270+
271+
def upload_certs(key_path, cert_path, force):
272+
with open(key_path, 'rb') as key_file, open(cert_path, 'rb') as cert_file:
273+
files_data = {
274+
'ssl_key': (os.path.basename(key_path), key_file,
275+
'application/octet-stream'),
276+
'ssl_cert': (os.path.basename(cert_path), cert_file,
277+
'application/octet-stream')
278+
}
279+
files_data['json'] = (
280+
None, json.dumps({'force': force}),
281+
'application/json'
282+
)
283+
return post('ssl_upload', files=files_data)

text.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ ssl:
1919
No SSL certificates on the node.
2020
Run < skale ssl upload > to add new certificates.
2121
uploaded: |-
22-
Certificates are sucsesfully uploaded.
23-
You can check status by running < skale ssl status >
22+
Certificates are successfully uploaded.
23+
You can check status by running < skale ssl status >

0 commit comments

Comments
 (0)