Ejemplo n.º 1
0
def call_aladdin_service(query):
    context = {
        'session_id':
        telemetry_core._session._get_base_properties()['Reserved.SessionId'],  # pylint: disable=protected-access
        'subscription_id':
        telemetry_core._get_azure_subscription_id(),  # pylint: disable=protected-access
        'client_request_id':
        telemetry_core._session.application.data['headers']
        ['x-ms-client-request-id'],  # pylint: disable=protected-access
        'installation_id':
        telemetry_core._get_installation_id()  # pylint: disable=protected-access
    }

    if (query and query.startswith("az ")):
        query = '"' + query + '"'

    service_input = {
        'paragraphText': "<div id='dummyHeader'></div>",
        'currentPageUrl': "",
        'query': "ALADDIN-CLI:" + query,
        'context': context
    }

    api_url = 'https://aladdinservice-staging.azurewebsites.net/api/aladdin/generateCards'
    headers = {'Content-Type': 'application/json'}

    response = requests.post(api_url, headers=headers, json=service_input)

    return response
Ejemplo n.º 2
0
def call_aladdin_service(query):
    client_request_id = ''
    if telemetry_core._session.application:  # pylint: disable=protected-access
        client_request_id = telemetry_core._session.application.data[
            'headers']['x-ms-client-request-id']  # pylint: disable=protected-access

    session_id = telemetry_core._session._get_base_properties()[
        'Reserved.SessionId']  # pylint: disable=protected-access
    subscription_id = telemetry_core._get_azure_subscription_id()  # pylint: disable=protected-access
    client_request_id = client_request_id  # pylint: disable=protected-access
    installation_id = telemetry_core._get_installation_id()  # pylint: disable=protected-access
    version = str(parse_version(core_version))

    context = {
        "sessionId": session_id,
        "subscriptionId": subscription_id,
        "clientRequestId": client_request_id,
        "installationId": installation_id,
        "versionNumber": version
    }

    api_url = 'https://app.aladdin.microsoft.com/api/v1.0/examples'
    headers = {'Content-Type': 'application/json'}

    response = requests.get(api_url,
                            params={
                                'query': query,
                                'clientType': 'AzureCli',
                                'context': json.dumps(context),
                                'commandOnly': True,
                                'numberOfExamples': 5
                            },
                            headers=headers)

    return response
Ejemplo n.º 3
0
def call_aladdin_service(query):
    version = str(parse(core_version))
    correlation_id = telemetry_core._session.correlation_id  # pylint: disable=protected-access
    subscription_id = telemetry_core._get_azure_subscription_id()  # pylint: disable=protected-access

    # Used for DDOS protection and rate limiting
    user_id = telemetry_core._get_installation_id()  # pylint: disable=protected-access
    hashed_user_id = hashlib.sha256(user_id.encode('utf-8')).hexdigest()

    context = {
        "versionNumber": version,
    }

    # Only pull in the contextual values if we have consent
    if telemetry_core.is_telemetry_enabled():
        context['correlationId'] = correlation_id

    if telemetry_core.is_telemetry_enabled() and subscription_id is not None:
        context['subscriptionId'] = subscription_id

    api_url = 'https://app.aladdin.microsoft.com/api/v1.0/examples'
    headers = {'Content-Type': 'application/json', 'X-UserId': hashed_user_id}

    response = requests.get(api_url,
                            params={
                                'query': query,
                                'clientType': 'AzureCli',
                                'context': json.dumps(context)
                            },
                            headers=headers)

    return response
Ejemplo n.º 4
0
def call_aladdin_service(query):
    client_request_id = ''
    if telemetry_core._session.application:  # pylint: disable=protected-access
        client_request_id = telemetry_core._session.application.data['headers']['x-ms-client-request-id']  # pylint: disable=protected-access

    context = {
        'session_id': telemetry_core._session._get_base_properties()['Reserved.SessionId'],  # pylint: disable=protected-access
        'subscription_id': telemetry_core._get_azure_subscription_id(),  # pylint: disable=protected-access
        'client_request_id': client_request_id,  # pylint: disable=protected-access
        'installation_id': telemetry_core._get_installation_id(),  # pylint: disable=protected-access
        'version_number': str(parse_version(core_version))
    }

    service_input = {
        'paragraphText': "<div id='dummyHeader'></div>",
        'currentPageUrl': "",
        'query': "ALADDIN-CLI:" + query,
        'context': context
    }

    api_url = 'https://aladdinservice-prod.azurewebsites.net/api/aladdin/generateCards'
    headers = {'Content-Type': 'application/json'}

    response = requests.post(api_url, headers=headers, json=service_input)

    return response
Ejemplo n.º 5
0
def set_custom_properties(prop, name, value):
    if name and value is not None:
        # 10 characters limit for strings
        prop['{}{}'.format(
            FIND_EXTENSION_PREFIX,
            name)] = value[:10] if isinstance(value, str) else value
        prop['{}{}'.format(
            FIND_EXTENSION_PREFIX,
            'session_id')] = telemetry_core._session._get_base_properties()[  # pylint: disable=protected-access
                'Reserved.SessionId']  # pylint: disable=protected-access
        prop['{}{}'.format(
            FIND_EXTENSION_PREFIX,
            'subscription_id')] = telemetry_core._get_azure_subscription_id()  # pylint: disable=protected-access
        prop['{}{}'.format(
            FIND_EXTENSION_PREFIX,
            'client_request_id')] = telemetry_core._session.application.data[  # pylint: disable=protected-access
                'headers']['x-ms-client-request-id']  # pylint: disable=protected-access
        prop['{}{}'.format(
            FIND_EXTENSION_PREFIX,
            'installation_id')] = telemetry_core._get_installation_id()  # pylint: disable=protected-access