Esempio n. 1
0
 def timed(*args, **kwargs):  # type: ignore
     stats_client = get_stats_client(method.__module__)
     if stats_client.is_enabled():
         timer = stats_client.timer(method.__name__)
         timer.start()
         result = method(*args, **kwargs)
         timer.stop()
         return result
     else:
         # statsd is disabled, so don't time anything
         return method(*args, **kwargs)
Esempio n. 2
0
 def timed(*args, **kwargs):
     stats_client = get_stats_client(None)
     if stats_client.is_enabled():
         # Example metric name "cartography.intel.aws.iam.get_group_membership_data"
         metric_name = f"{method.__module__}.{method.__name__}"
         timer = stats_client.timer(metric_name)
         timer.start()
         result = method(*args, **kwargs)
         timer.stop()
         return result
     else:
         # statsd is disabled, so don't time anything
         return method(*args, **kwargs)
Esempio n. 3
0
def test_merge_module_sync_metadata(mock_stat_incr, neo4j_session):
    # Arrange
    group_type = 'AWSAccount'
    group_id = TEST_ACCOUNT_ID
    synced_type = 'S3Bucket'
    stat_handler = get_stats_client(__name__)
    expected_nodes = {
        (
            f'AWSAccount_{TEST_ACCOUNT_ID}_S3Bucket',
            'AWSAccount',
            TEST_ACCOUNT_ID,
            'S3Bucket',
            TEST_UPDATE_TAG,
        ),
    }
    # Act
    merge_module_sync_metadata(
        neo4j_session=neo4j_session,
        group_type=group_type,
        group_id=group_id,
        synced_type=synced_type,
        update_tag=TEST_UPDATE_TAG,
        stat_handler=stat_handler,
    )
    # Assert
    nodes = neo4j_session.run(f"""
        MATCH (m:ModuleSyncMetadata{{id:'AWSAccount_{TEST_ACCOUNT_ID}_S3Bucket'}})
        RETURN
            m.id,
            m.syncedtype,
            m.grouptype,
            m.groupid,
            m.lastupdated
    """)
    # Assert
    actual_nodes = {(
        n['m.id'],
        n['m.grouptype'],
        n['m.groupid'],
        n['m.syncedtype'],
        n['m.lastupdated'],
    )
                    for n in nodes}
    assert actual_nodes == expected_nodes
    mock_stat_incr.assert_called_once_with(
        f'{group_type}_{group_id}_{synced_type}_lastupdated',
        TEST_UPDATE_TAG,
    )
Esempio n. 4
0
import logging
from typing import Dict
from typing import List
from typing import Tuple

import neo4j

from cartography.intel.github.util import fetch_all
from cartography.stats import get_stats_client
from cartography.util import merge_module_sync_metadata
from cartography.util import run_cleanup_job
from cartography.util import timeit

logger = logging.getLogger(__name__)
stat_handler = get_stats_client(__name__)


GITHUB_ORG_USERS_PAGINATED_GRAPHQL = """
    query($login: String!, $cursor: String) {
    organization(login: $login)
        {
            url
            login
            membersWithRole(first:100, after: $cursor){
                edges {
                    hasTwoFactorEnabled
                    node {
                        url
                        login
                        name
                        isSiteAdmin