Skip to content
    DataInMotion@evantobin8
    index.js
    Packager files
    package-lock.json
    package.json
    Config files
    .replit
    replit.nix
    const fetch = require('node-fetch');

    // Host settings
    let instance = {
    host: "https://sandbox.mybigid.com/api/v1",
    user: "bigid",
    pass: "learner"
    };

    // Since all data sources need to have a unique name, we've added a number
    const random = (Math.floor(Math.random() * 1000)).toString();
    // DS Settings
    const datasource = {
    "name": "Kinesis" + random,
    "owners": [
    ""
    ],
    "differential": false,
    "rdb_is_sample_data": false,
    "aws_key_id": "",
    "aws_key_secret": "",
    "isIamRoleAuth": true,
    "region": "us-east-1",
    "stream_name": "StockTradeStream",
    "type": "kinesis",
    "security_tier": "1",
    "ocr_languages": "eng",
    "scanner_strategy": "SCAN_ALL",
    "enabled": "yes",
    "keyDeserializer": "String",
    "valueDeserializer": "String"
    };

    //Scan Profile Settings
    const profile = {
    "scanType": "dataInMotion",
    "allEnabledIdSor": true,
    "allEnabledDs": false,
    "skipIdScan": true,
    "isClassificationsAsPiiFindings": false,
    "labelFramework": {
    "id": "mip",
    "name": "Labels"
    },
    "dataSourceList": [
    "Kinesis" + random
    ],
    "name": "Kinesis" + random,
    "owners": [],
    "isCustomScanProfile": true
    }

    addDataInMotion(instance, datasource, profile);

    async function addDataInMotion(instance, datasource, profile) {
    // Get token with user/pass. See https://developer.bigid.com/wiki/BigID_API/API_Tutorial for other auth options
    instance.token = await getToken(instance.user, instance.pass, instance.host);

    // Test if Kinesis is enabled
    if (await checkConnectorEnabled('Kinesis', instance) === false) {
    return console.log('Kinesis is not enabled in this system.');
    }
    console.log('Kinesis connector is enabled.');

    // Test if we can connect to described data source
    if (await testDataSource(datasource, instance) === false) {
    return console.log('Cannot contact data source');
    }
    console.log('Test connection succeeded.');

    // Save data source
    if (await saveDataSource(datasource, instance) !== true) {
    return console.log('Data source could not be saved.')
    }
    console.log('Data source saved.')
    // Save profile
    if (await saveProfile(profile, instance) === false) {
    return console.log('Scan profile could not be saved.')
    }
    console.log('Scan profile saved.');

    // Run Scan - commented out to conserve power
    //await startDIMScan(profile,instance);
    console.log('Scan running.');
    }

    async function getToken(user, pass, host) {
    // Get a token
    const tokenRequest = await fetch(host + '/sessions', {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ username: user, password: pass })
    });
    const tokenJSON = await tokenRequest.json();
    return tokenJSON.auth_token;
    }

    async function checkConnectorEnabled(type, instance) {
    // Check if Kinesis is enabled
    const connectorsRequest = await fetch(instance.host + '/ds-connections-types', {
    method: 'GET',
    headers: {
    'content-type': 'application/json',
    'authorization': instance.token
    }
    });
    const connectorsJSON = await connectorsRequest.json();
    return connectorsJSON.data.some((item) => item.name === type);
    }

    async function testDataSource(ds, instance) {
    const testRequest = await fetch(instance.host + '/ds-connection-test', {
    method: 'POST',
    headers: {
    'content-type': 'application/json',
    'authorization': instance.token
    },
    body: JSON.stringify({ isNewPassword: true, 'ds_connection': ds })
    });
    const testJSON = await testRequest.json();
    return testJSON.operationStatus === "SUCCESS";
    }

    async function saveDataSource(ds, instance) {
    const saveRequest = await fetch(instance.host + '/ds_connections', {
    method: 'POST',
    headers: {
    'content-type': 'application/json',
    'authorization': instance.token
    },
    body: JSON.stringify({ 'ds_connection': ds })
    });
    const saveJSON = await saveRequest.json();
    return saveJSON.name === ds.name;
    }

    async function saveProfile(profile, instance) {
    const profileRequest = await fetch(instance.host + '/scanProfiles', {
    method: 'POST',
    headers: {
    'content-type': 'application/json',
    'authorization': instance.token
    },
    body: JSON.stringify(profile)
    });
    const profileJSON = await profileRequest.json();
    return profileJSON.scanProfile.name === profile.name;
    }

    async function startDIMScan(profile, instance) {
    await fetch(instance.host + '/scans', {
    method: 'POST',
    headers: {
    'content-type': 'application/json',
    'authorization': instance.token
    },
    body: JSON.stringify({
    "scanType": "dataInMotion",
    "scanProfileName": profile.name,
    "scanOrigin": "Invoked manually"
    })
    });
    return true;
    }