Beispiel #1
0
    def test_http_connector(self):
        """ should create proper http connector in case api_proxy is set  """
        cert_kwargs = {
            'cert_reqs': 'CERT_NONE',
        }

        conf = cloudinary.config(api_proxy=None)
        http = utils.get_http_connector(conf, cert_kwargs)
        self.assertIsInstance(http, PoolManager)

        conf = cloudinary.config(api_proxy='http://www.example.com:3128')
        http = utils.get_http_connector(conf, cert_kwargs)
        cloudinary.reset_config()

        self.assertIsInstance(http, ProxyManager)
Beispiel #2
0
import json

import cloudinary
from cloudinary.api_client.execute_request import execute_request
from cloudinary.utils import get_http_connector

logger = cloudinary.logger
_http = get_http_connector(cloudinary.config(), cloudinary.CERT_KWARGS)


def call_metadata_api(method, uri, params, **options):
    """Private function that assists with performing an API call to the
    metadata_fields part of the Admin API
    :param method: The HTTP method. Valid methods: get, post, put, delete
    :param uri: REST endpoint of the API (without 'metadata_fields')
    :param params: Query/body parameters passed to the method
    :param options: Additional options
    :rtype: Response
    """
    uri = ["metadata_fields"] + (uri or [])
    return call_json_api(method, uri, params, **options)


def call_json_api(method, uri, jsonBody, **options):
    logger.debug(jsonBody)
    data = json.dumps(jsonBody).encode('utf-8')
    return _call_api(method,
                     uri,
                     body=data,
                     headers={'Content-Type': 'application/json'},
                     **options)
Beispiel #3
0
import cloudinary
from cloudinary.api_client.execute_request import execute_request
from cloudinary.provisioning.account_config import account_config
from cloudinary.utils import get_http_connector


PROVISIONING_SUB_PATH = "provisioning"
ACCOUNT_SUB_PATH = "accounts"
_http = get_http_connector(account_config(), cloudinary.CERT_KWARGS)


def _call_account_api(method, uri, params=None, headers=None, **options):
    prefix = options.pop("upload_prefix",
                         cloudinary.config().upload_prefix) or "https://api.cloudinary.com"
    account_id = options.pop("account_id", account_config().account_id)
    if not account_id:
        raise Exception("Must supply account_id")
    provisioning_api_key = options.pop("provisioning_api_key", account_config().provisioning_api_key)
    if not provisioning_api_key:
        raise Exception("Must supply provisioning_api_key")
    provisioning_api_secret = options.pop("provisioning_api_secret",
                                          account_config().provisioning_api_secret)
    if not provisioning_api_secret:
        raise Exception("Must supply provisioning_api_secret")
    provisioning_api_url = "/".join(
        [prefix, cloudinary.API_VERSION, PROVISIONING_SUB_PATH, ACCOUNT_SUB_PATH, account_id] + uri)
    auth = {"key": provisioning_api_key, "secret": provisioning_api_secret}

    return execute_request(http_connector=_http,
                           method=method,
                           params=params,