import requests
import json


def create_secret(api_url, token, scope, secret_name, secret_value):
    """ 
    Creates a secret in Databricks workspace in the given scope.
    This will overwrite any existing secrets with the same name.
    """
    r = requests.post(api_url + 'preview/secret/secrets/write',
                      headers={"Authorization": "Bearer " + token},
                      json={"scope": scope, "key": secret_name, "string_value": secret_value
                            })
    response_body = r.json()
    if r.status_code != 200:
        raise Exception('Error creating scope: ' + json.dumps(response_body))
    return (response_body)