コード例 #1
0
def get_paasta_oapi_client(
    cluster: str = None,
    system_paasta_config: SystemPaastaConfig = None,
    http_res: bool = False,
) -> Optional[PaastaOApiClient]:
    if not system_paasta_config:
        system_paasta_config = load_system_paasta_config()

    if not cluster:
        cluster = system_paasta_config.get_cluster()

    api_endpoints = system_paasta_config.get_api_endpoints()
    if cluster not in api_endpoints:
        log.error("Cluster %s not in paasta-api endpoints config", cluster)
        return None

    parsed = urlparse(api_endpoints[cluster])
    cert_file = key_file = ssl_ca_cert = None
    if parsed.scheme == "https":
        opts = get_paasta_ssl_opts(cluster, system_paasta_config)
        if opts:
            cert_file = opts["cert"]
            key_file = opts["key"]
            ssl_ca_cert = opts["ca"]

    return get_paasta_oapi_client_by_url(parsed, cert_file, key_file,
                                         ssl_ca_cert)
コード例 #2
0
def get_paasta_api_client(
    cluster: str = None,
    system_paasta_config: SystemPaastaConfig = None,
    http_res: bool = False,
) -> Any:
    if not system_paasta_config:
        system_paasta_config = load_system_paasta_config()

    if not cluster:
        cluster = system_paasta_config.get_cluster()

    api_endpoints = system_paasta_config.get_api_endpoints()
    if cluster not in api_endpoints:
        log.error("Cluster %s not in paasta-api endpoints config", cluster)
        return None

    url = str(api_endpoints[cluster])
    parsed = urlparse(url)
    if not parsed:
        log.error("Unsupported paasta-api url %s", url)
        return None
    api_server = parsed.netloc

    # Get swagger spec from file system instead of the api server
    paasta_api_path = os.path.dirname(paasta_tools.api.__file__)
    swagger_file = os.path.join(paasta_api_path, "api_docs/swagger.json")
    if not os.path.isfile(swagger_file):
        log.error("paasta-api swagger spec %s does not exist", swagger_file)
        return None

    with open(swagger_file) as f:
        spec_dict = json.load(f)
    # replace localhost in swagger.json with actual api server
    spec_dict["host"] = api_server
    spec_dict["schemes"] = [parsed.scheme]

    # sometimes we want the status code
    requests_client = PaastaRequestsClient(
        scheme=parsed.scheme,
        cluster=cluster,
        system_paasta_config=system_paasta_config)
    if http_res:
        config = {"also_return_response": True}
        c = SwaggerClient.from_spec(spec_dict=spec_dict,
                                    config=config,
                                    http_client=requests_client)
    else:
        c = SwaggerClient.from_spec(spec_dict=spec_dict,
                                    http_client=requests_client)
    return paasta_tools.api.auth_decorator.AuthClientDecorator(
        c, cluster_name=cluster)
コード例 #3
0
ファイル: client.py プロジェクト: xcorail/paasta
def get_paasta_api_client(
    cluster: str = None,
    system_paasta_config: SystemPaastaConfig = None,
    http_res: bool = False,
) -> Any:
    if not system_paasta_config:
        system_paasta_config = load_system_paasta_config()

    if not cluster:
        cluster = system_paasta_config.get_cluster()

    api_endpoints = system_paasta_config.get_api_endpoints()
    if cluster not in api_endpoints:
        log.error('Cluster %s not in paasta-api endpoints config', cluster)
        return None

    url = str(api_endpoints[cluster])
    parsed = urlparse(url)
    if not parsed:
        log.error('Unsupported paasta-api url %s', url)
        return None
    api_server = parsed.netloc

    # Get swagger spec from file system instead of the api server
    paasta_api_path = os.path.dirname(paasta_tools.api.__file__)
    swagger_file = os.path.join(paasta_api_path, 'api_docs/swagger.json')
    if not os.path.isfile(swagger_file):
        log.error('paasta-api swagger spec %s does not exist', swagger_file)
        return None

    with open(swagger_file) as f:
        spec_dict = json.load(f)
    # replace localhost in swagger.json with actual api server
    spec_dict['host'] = api_server

    # sometimes we want the status code
    if http_res:
        config = {'also_return_response': True}
        return SwaggerClient.from_spec(spec_dict=spec_dict, config=config)
    else:
        return SwaggerClient.from_spec(spec_dict=spec_dict)