Header文件示例

介绍需要导入的ucwi_configucwi_auth头部文件结构。

Python示例(ucwi_config)

以下示例显示了作为头部文件的统一内容安全审查平台UCWI配置文件ucwi_config文件示例。
class UCWIConfig:
    access_key = "<access_key>"
    secret_key = "<secret_key>"
    protocol = "https"
    ucwi_host = "<ip address of ucwi_host>"
    ucwi_port = <port_number>
    callback_url = "http://<ip address of callback url>:<port number>/callback"
    base_url = "{0}://{1}:{2}".format(protocol, ucwi_host, ucwi_port)

Python示例(ucwi_auth)

以下示例显示了作为头部文件的统一内容安全审查平台UCWI配置文件ucwi_auth文件示例。
import time
import hmac
import hashlib
from ucwi_config import UCWIConfig

def get_auth(access_key, secret_key, timestamp):
    token_source = secret_key + timestamp
    token = hmac.new(
        secret_key.encode('utf-8'),
        token_source.encode('utf-8'),
        hashlib.sha256).hexdigest()
    return "SKG {0}:{1}".format(access_key, token)

def get_headers():
    timestamp = "{0:.0f}".format(time.time())
    auth = get_auth(
        UCWIConfig.access_key,
        UCWIConfig.secret_key,
        timestamp)

    headers = {
        "x-skg-timestamp": timestamp,
        "Authorization": auth,
    }

    return headers