Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

censys ipv4 - use axios for getting data instead of got #187

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions backend/src/tasks/censysIpv4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as readline from 'readline';
import got from 'got';
import PQueue from 'p-queue';
import pRetry from 'p-retry';
import axios from 'axios';

interface IpToDomainsMap {
[ip: string]: Domain[];
Expand All @@ -20,6 +21,7 @@ const auth = {
username: process.env.CENSYS_API_ID!,
password: process.env.CENSYS_API_SECRET!
};

const CENSYS_IPV4_ENDPOINT = 'https://censys.io/api/v1/data/ipv4_2018/';

const downloadPath = async (
Expand Down Expand Up @@ -96,10 +98,11 @@ const downloadPath = async (
console.log(
`censysipv4 - processed file ${i} of ${numFiles}: got no results`
);
} else {
console.log(
`censysipv4 - processed file ${i} of ${numFiles}: got some results: ${domains.length} domains and ${services.length} services`
);
}
console.log(
`censysipv4 - processed file ${i} of ${numFiles}: got some results: ${domains.length} domains and ${services.length} services`
);

await saveDomainsToDb(domains);
await saveServicesToDb(services);
Expand All @@ -112,9 +115,13 @@ export const handler = async (commandOptions: CommandOptions) => {
throw new Error('Chunks not specified.');
}

const { results } = await got(CENSYS_IPV4_ENDPOINT, { ...auth }).json();
const {
data: { results }
} = await axios.get(CENSYS_IPV4_ENDPOINT, { auth });

const { files } = await got(results.latest.details_url, { ...auth }).json();
const {
data: { files }
} = await axios.get(results.latest.details_url, { auth });

const allDomains = await getAllDomains();

Expand Down