Commit 96963291 by Rafael Monnerat

slapos.cli: Update API for get person certificates and register computer

  The API uses code which is part of the new VIFIB 2.0 API, and
  uses simpler scripts and JSON for the exchange of information.

  This API may change again in futher future, but backward compatibility will be kept with the current implementaion
1 parent 8e80a4ae
......@@ -30,11 +30,12 @@
import re
import os
import sys
import json
import requests
from slapos.cli.config import ClientConfigCommand
from slapos.util import mkdir_p, parse_certificate_key_pair
from slapos.util import mkdir_p
class ConfigureClientCommand(ClientConfigCommand):
......@@ -70,7 +71,7 @@ class ConfigureClientCommand(ClientConfigCommand):
def get_certificate_key_pair(logger, master_url_web, token):
req = requests.post('/'.join([master_url_web, 'myspace/my_account/request-a-certificate/WebSection_requestNewCertificate']),
req = requests.post('/'.join([master_url_web, 'Person_getCertificate']),
data={},
headers={'X-Access-Token': token},
verify=False)
......@@ -82,8 +83,8 @@ def get_certificate_key_pair(logger, master_url_web, token):
req.raise_for_status()
return parse_certificate_key_pair(req.text)
json_dict = json.loads(req.text)
return json_dict["certificate"], json_dict["key"]
def fetch_configuration_template():
# XXX: change to local version.
......
......@@ -35,9 +35,9 @@ import stat
import sys
import pkg_resources
import requests
import json
from slapos.cli.command import Command, must_be_root
from slapos.util import parse_certificate_key_pair
class RegisterCommand(Command):
......@@ -147,12 +147,12 @@ def get_certificate_key_pair(logger, master_url_web, node_name, token=None, logi
"""Download certificates from SlapOS Master"""
if token:
req = requests.post('/'.join([master_url_web, 'add-a-server/WebSection_registerNewComputer']),
req = requests.post('/'.join([master_url_web, 'Person_requestComputer']),
data={'title': node_name},
headers={'X-Access-Token': token},
verify=False)
else:
register_server_url = '/'.join([master_url_web, ("add-a-server/WebSection_registerNewComputer?title={}".format(node_name))])
register_server_url = '/'.join([master_url_web, ("Person_requestComputer?title={}".format(node_name))])
req = requests.get(register_server_url, auth=(login, password), verify=False)
if not req.ok and 'Certificate still active.' in req.text:
......@@ -178,8 +178,8 @@ def get_certificate_key_pair(logger, master_url_web, node_name, token=None, logi
else:
req.raise_for_status()
return parse_certificate_key_pair(req.text)
json_dict = json.loads(req.text)
return json_dict["certificate"], json_dict["key"]
def get_computer_name(certificate):
"""Parse certificate to get computer name and return it"""
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!