Integrations/AzureCompute_v2/AzureCompute_v2.py
def http_request(method, url_suffix=None, data=None, headers=None,
                 params=None, codes=None, full_url=None, j_son=None):
    """
    A wrapper for requests lib to send our requests and handle requests and responses better

    parameter: (string) method
        A string denoting the http request method to use.
        Can be 'GET', 'POST, 'PUT', 'DELETE', etc.

    parameter: (string) url_suffix
        The API endpoint that determines which data we are trying to access/create/update
        in our call to the API

    parameter: (dict) data
        The key/value pairs to be form-encoded

    parameter: (dict) headers
        The headers to use with the request

    parameter: (dict) params
        The parameters to use with this request

    parameter: (set) codes
        The set of status codes against which the status code of the response should be checked

    parameter: (string) full_url
        The full url to make a request to. Only necessary in the case that you need to make
        an API request to an endpoint which differs in its base url from the majority of
        the API calls in the integration

    parameter: (dict) j_son
        A JSON serializable Python object to send in the body of the request

    returns:
        JSON Response Object
    """
    token = get_access_token()
    if not headers:
        headers = {
            'Authorization': f'Bearer {token}',
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
    try:
        url = full_url if full_url else None
        if not url:
            url = BASE_URL + url_suffix if url_suffix else BASE_URL
        r = requests.request(
            method,
            url,
            headers=headers,
            data=data,
            params=params,
            verify=USE_SSL,
            json=j_son
        )
        green_codes = codes if codes else {200, 201, 202, 204}
        if r.status_code not in green_codes:
            if r.status_code in {401, 403}:
                err_msg = ('Permission error in API call to Azure Compute Integration, make sure the application'
                           ' has access to the relevant resources.')
            else:
                err_msg = 'Error in API call to Azure Compute Integration [{}] - {}'.format(r.status_code, r.reason)
                err = r.json().get('error')
                if err:
                    err_msg1 = '\nError code: {}\nError message: {}'.format(err.get('code'), err.get('message'))
                    err_msg += err_msg1
            raise Exception(err_msg)
        response = json.loads(r.content)
    except ValueError:
        response = r.content

    return response

    A wrapper for requests lib to send our requests and handle requests and responses better

    parameter: (string) method
        A string denoting the http request method to use.
        Can be 'GET', 'POST, 'PUT', 'DELETE', etc.

    parameter: (string) url_suffix
        The API endpoint that determines which data we are trying to access/create/update
        in our call to the API

    parameter: (dict) data
        The key/value pairs to be form-encoded

    parameter: (dict) headers
        The headers to use with the request

    parameter: (dict) params
        The parameters to use with this request

    parameter: (set) codes
        The set of status codes against which the status code of the response should be checked

    parameter: (string) full_url
        The full url to make a request to. Only necessary in the case that you need to make
        an API request to an endpoint which differs in its base url from the majority of
        the API calls in the integration

    parameter: (dict) j_son
        A JSON serializable Python object to send in the body of the request

    returns:
        JSON Response Object
    
A wrapper for requests lib to send our requests and handle requests and responses better
parameter: (string) method
A string denoting the http request method to use.

(string) url_suffix
The API endpoint that determines which data we are trying to access/create/update
in our call to the API

(dict) data
The key/value pairs to be form-encoded

(dict) headers
The headers to use with the request

(dict) params
The parameters to use with this request

(set) codes
The set of status codes against which the status code of the response should be checked

(string) full_url
The full url to make a request to. Only necessary in the case that you need to make
an API request to an endpoint which differs in its base url from the majority of
the API calls in the integration

(dict) j_son
A JSON serializable Python object to send in the body of the request

JSON Response Object
A wrapper for requests lib to send our requests and handle requests and responses better parameter : ( string ) method A string denoting the http request method to use . ( string ) url_suffix The API endpoint that determines which data we are trying to access / create / update in our call to the API ( dict ) data The key / value pairs to be form - encoded ( dict ) headers The headers to use with the request ( dict ) params The parameters to use with this request ( set ) codes The set of status codes against which the status code of the response should be checked ( string ) full_url The full url to make a request to . Only necessary in the case that you need to make an API request to an endpoint which differs in its base url from the majority of the API calls in the integration ( dict ) j_son A JSON serializable Python object to send in the body of the request JSON Response Object
def http_request(method, url_suffix=None, data=None, headers=None,
                 params=None, codes=None, full_url=None, j_son=None):
    token = get_access_token()
    if not headers:
        headers = {
            'Authorization': f'Bearer {token}',
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
    try:
        url = full_url if full_url else None
        if not url:
            url = BASE_URL + url_suffix if url_suffix else BASE_URL
        r = requests.request(
            method,
            url,
            headers=headers,
            data=data,
            params=params,
            verify=USE_SSL,
            json=j_son
        )
        green_codes = codes if codes else {200, 201, 202, 204}
        if r.status_code not in green_codes:
            if r.status_code in {401, 403}:
                err_msg = ('Permission error in API call to Azure Compute Integration, make sure the application'
                           ' has access to the relevant resources.')
            else:
                err_msg = 'Error in API call to Azure Compute Integration [{}] - {}'.format(r.status_code, r.reason)
                err = r.json().get('error')
                if err:
                    err_msg1 = '\nError code: {}\nError message: {}'.format(err.get('code'), err.get('message'))
                    err_msg += err_msg1
            raise Exception(err_msg)
        response = json.loads(r.content)
    except ValueError:
        response = r.content
    return response
def http_request ( method , url_suffix = None , data = None , headers = None , params = None , codes = None , full_url = None , j_son = None ) : token = get_access_token ( ) if not headers : headers = { 'Authorization' : f'Bearer {token}' , 'Content-Type' : 'application/json' , 'Accept' : 'application/json' } try : url = full_url if full_url else None if not url : url = BASE_URL + url_suffix if url_suffix else BASE_URL r = requests . request ( method , url , headers = headers , data = data , params = params , verify = USE_SSL , json = j_son ) green_codes = codes if codes else { 200 , 201 , 202 , 204 } if r . status_code not in green_codes : if r . status_code in { 401 , 403 } : err_msg = ( 'Permission error in API call to Azure Compute Integration, make sure the application' ' has access to the relevant resources.' ) else : err_msg = 'Error in API call to Azure Compute Integration [{}] - {}' . format ( r . status_code , r . reason ) err = r . json ( ) . get ( 'error' ) if err : err_msg1 = '\nError code: {}\nError message: {}' . format ( err . get ( 'code' ) , err . get ( 'message' ) ) err_msg += err_msg1 raise Exception ( err_msg ) response = json . loads ( r . content ) except ValueError : response = r . content return response
A wrapper for requests lib to send our requests and handle requests and responses better
parameter: (string) method
A string denoting the http request method to use.
A wrapper for requests lib to send our requests and handle requests and responses better parameter : ( string ) method A string denoting the http request method to use .
"""
    A wrapper for requests lib to send our requests and handle requests and responses better

    parameter: (string) method
        A string denoting the http request method to use.
        Can be 'GET', 'POST, 'PUT', 'DELETE', etc.

    parameter: (string) url_suffix
        The API endpoint that determines which data we are trying to access/create/update
        in our call to the API

    parameter: (dict) data
        The key/value pairs to be form-encoded

    parameter: (dict) headers
        The headers to use with the request

    parameter: (dict) params
        The parameters to use with this request

    parameter: (set) codes
        The set of status codes against which the status code of the response should be checked

    parameter: (string) full_url
        The full url to make a request to. Only necessary in the case that you need to make
        an API request to an endpoint which differs in its base url from the majority of
        the API calls in the integration

    parameter: (dict) j_son
        A JSON serializable Python object to send in the body of the request

    returns:
        JSON Response Object
    """
method
url_suffix
data
headers
params
codes
full_url
j_son