Ejemplo n.º 1
0
    def call_repo_confirm_api(self, pincode_dict, request_id, client_md5,
                              repo_title):
        api_reg_pattern = "1/repo/claim_confirm"
        api_url = "https://%s/%s" % (options.api_hostname, api_reg_pattern)

        confirm_dict = self.prepare_confirm_json_body()
        confirm_dict['sn'] = pincode_dict['sn']
        confirm_dict['pincode'] = pincode_dict['pincode']
        confirm_dict['request_id'] = request_id
        confirm_dict['client_md5'] = client_md5
        confirm_dict['repo_title'] = repo_title
        json_body = json.dumps(confirm_dict)
        #print "json_body", json_body

        http_obj = libHttp.Http()
        (new_html_string,
         http_code) = http_obj.get_http_response_core(api_url, data=json_body)
        json_obj = None
        if http_code >= 200 and http_code <= 403:
            # direct read the string to json.
            try:
                json_obj = json.loads(new_html_string)
            except Exception, err:
                # not is json format.
                pass
Ejemplo n.º 2
0
def call_claimed_repo_update_api(repo_token):
    api_reg_pattern = "1/repo/update"
    api_url = "https://%s/%s" % (options.api_hostname, api_reg_pattern)
    body_dict = prepare_reg_json_body()
    body_dict['repo_token'] = repo_token
    json_body = json.dumps(body_dict)
    #print json_body

    http_obj = libHttp.Http()
    (new_html_string,
     http_code) = http_obj.get_http_response_core(api_url, data=json_body)
    json_obj = None
    #print "server code: %d" % (http_code,)
    #print "server message: %s" % (new_html_string,)
    if http_code == 200:
        # direct read the string to json.
        json_obj = json.loads(new_html_string)
    else:
        if http_code == 400:
            json_obj = None
            try:
                json_obj = json.loads(new_html_string)
            except ValueError as err:  # includes simplejson.decoder.JSONDecodeError
                json_obj = None
            except Exception as err:
                json_obj = None
    return http_code, json_obj
Ejemplo n.º 3
0
def call_repo_register_api():
    api_reg_pattern = "1/repo/reg"
    api_url = "https://%s/%s" % (options.api_hostname, api_reg_pattern)

    json_body = json.dumps(prepare_reg_json_body())
    #print json_body

    http_obj = libHttp.Http()
    (new_html_string,
     http_code) = http_obj.get_http_response_core(api_url, data=json_body)
    json_obj = None
    if http_code == 200:
        # direct read the string to json.
        json_obj = json.loads(new_html_string)
    else:
        #print "server return error code: %d" % (http_code,)
        #print "server return error message: %s" % (new_html_string,)
        if http_code == 400:
            json_obj = None
            try:
                json_obj = json.loads(new_html_string)
            except ValueError as err:  # includes simplejson.decoder.JSONDecodeError
                json_obj = None
            except Exception as err:
                json_obj = None
    return http_code, json_obj
Ejemplo n.º 4
0
    def call_repo_sharing_confirm_api(self, share_code, request_id):
        api_reg_pattern = "1/repo/share/confirm"
        api_url = "https://%s/%s" % (options.api_hostname, api_reg_pattern)

        send_dict = {}
        repo_dbo = DboRepo(self.application.sql_client)
        repo_dict = repo_dbo.first()
        if not repo_dict is None:
            send_dict['repo_token'] = repo_dict['repo_token']
        send_dict['share_code'] = share_code
        send_dict['request_id'] = request_id
        json_body = json.dumps(send_dict)
        #print "json_body", json_body

        http_obj = libHttp.Http()
        (new_html_string,
         http_code) = http_obj.get_http_response_core(api_url, data=json_body)
        json_obj = None
        if http_code >= 200 and http_code <= 403:
            # direct read the string to json.
            try:
                json_obj = json.loads(new_html_string)
            except Exception, err:
                # not is json format.
                pass