Skip to content

Commit

Permalink
Remove ID from agent info
Browse files Browse the repository at this point in the history
We'll make on server side
Also a dependency we can drop
  • Loading branch information
hansott committed Feb 14, 2024
1 parent 2a0ae10 commit 322b5ad
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 101 deletions.
3 changes: 1 addition & 2 deletions library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
},
"dependencies": {
"require-in-the-middle": "^7.2.0",
"shimmer": "^1.2.1",
"ulid": "^2.3.0"
"shimmer": "^1.2.1"
}
}
3 changes: 0 additions & 3 deletions library/src/agent/API.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function generateAttackEvent(): Event {
metadata: {},
},
agent: {
id: "id",
version: "1.0.0",
dryMode: false,
hostname: "hostname",
Expand Down Expand Up @@ -74,7 +73,6 @@ function generateStartedEvent(): Event {
type: "started",
time: Date.now(),
agent: {
id: "id",
version: "1.0.0",
dryMode: false,
hostname: "hostname",
Expand Down Expand Up @@ -121,7 +119,6 @@ function generateHeartbeatEvent(): Event {
time: Date.now(),
stats: {},
agent: {
id: "id",
version: "1.0.0",
dryMode: false,
hostname: "hostname",
Expand Down
1 change: 0 additions & 1 deletion library/src/agent/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class Token {
}

export type AgentInfo = {
id: string;
dryMode: boolean;
hostname: string;
version: string;
Expand Down
56 changes: 7 additions & 49 deletions library/src/agent/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,22 @@ import { hostname, platform, release } from "node:os";
import * as t from "tap";
import { Agent } from "./Agent";
import { APIForTesting, Token } from "./API";
import { IDGeneratorFixed } from "./IDGenerator";
import { LoggerNoop } from "./Logger";
import { address } from "ip";

t.test("it sends started event", async (t) => {
const logger = new LoggerNoop();
const api = new APIForTesting();
const token = new Token("123");
const agent = new Agent(
true,
logger,
api,
token,
new IDGeneratorFixed("id"),
false,
{
mongodb: "1.0.0",
}
);
const agent = new Agent(true, logger, api, token, false, {
mongodb: "1.0.0",
});
agent.start();

t.match(api.getEvents(), [
{
type: "started",
agent: {
id: "id",
dryMode: false,
hostname: hostname(),
version: "1.0.0",
Expand All @@ -52,15 +42,7 @@ t.test("when prevent prototype pollution is enabled", async (t) => {
const logger = new LoggerNoop();
const api = new APIForTesting();
const token = new Token("123");
const agent = new Agent(
true,
logger,
api,
token,
new IDGeneratorFixed("id"),
true,
{}
);
const agent = new Agent(true, logger, api, token, true, {});
agent.onPrototypePollutionPrevented();
agent.start();
t.match(api.getEvents(), [
Expand All @@ -76,15 +58,7 @@ t.test("it does not start interval in serverless mode", async () => {
const logger = new LoggerNoop();
const api = new APIForTesting();
const token = new Token("123");
const agent = new Agent(
true,
logger,
api,
token,
new IDGeneratorFixed("id"),
true,
{}
);
const agent = new Agent(true, logger, api, token, true, {});

// This would otherwise keep the process running
agent.start();
Expand All @@ -94,15 +68,7 @@ t.test("it keeps track of stats", async () => {
const logger = new LoggerNoop();
const api = new APIForTesting();
const token = new Token("123");
const agent = new Agent(
true,
logger,
api,
token,
new IDGeneratorFixed("id"),
true,
{}
);
const agent = new Agent(true, logger, api, token, true, {});

agent.start();
agent.onInspectedCall({
Expand Down Expand Up @@ -158,15 +124,7 @@ t.test("it keeps tracks of stats in dry mode", async () => {
const logger = new LoggerNoop();
const api = new APIForTesting();
const token = new Token("123");
const agent = new Agent(
false,
logger,
api,
token,
new IDGeneratorFixed("id"),
true,
{}
);
const agent = new Agent(false, logger, api, token, true, {});

agent.start();

Expand Down
3 changes: 0 additions & 3 deletions library/src/agent/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { hostname, platform, release } from "node:os";
import { API, AgentInfo, Token, Stats, Kind } from "./API";
import { IDGenerator } from "./IDGenerator";
import { Logger } from "./Logger";
import { Context } from "./Context";
import { resolve } from "path";
Expand All @@ -18,7 +17,6 @@ export class Agent {
private readonly logger: Logger,
private readonly api: API,
private readonly token: Token | undefined,
private readonly idGenerator: IDGenerator,
private readonly serverless: boolean,
private readonly wrappedPackages: Record<string, string>
) {}
Expand Down Expand Up @@ -182,7 +180,6 @@ export class Agent {

private getAgentInfo(): AgentInfo {
return {
id: this.idGenerator.generate(),
dryMode: !this.block,
hostname: hostname() || "",
version: this.getAgentVersion(),
Expand Down
6 changes: 0 additions & 6 deletions library/src/agent/IDGenerator.test.ts

This file was deleted.

20 changes: 0 additions & 20 deletions library/src/agent/IDGenerator.ts

This file was deleted.

3 changes: 1 addition & 2 deletions library/src/agent/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { satisfiesVersion } from "../helpers/satisfiesVersion";
import { Agent } from "./Agent";
import { getInstance, setInstance } from "./AgentSingleton";
import { API, APIFetch, APIThrottled, Token } from "./API";
import { IDGeneratorULID } from "./IDGenerator";
import { Express } from "../sources/Express";
import { createLambdaWrapper } from "../sources/Lambda";
import { MongoDB } from "../sinks/MongoDB";
Expand Down Expand Up @@ -109,7 +108,6 @@ function getAgent({
logger,
api,
token,
new IDGeneratorULID(),
serverless,
installed
);
Expand Down Expand Up @@ -156,6 +154,7 @@ export function lambda(
options: getOptions(options),
serverless: true,
});

agent.start();

return createLambdaWrapper(handler);
Expand Down
2 changes: 0 additions & 2 deletions library/src/sinks/MongoDB.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as t from "tap";
import { Agent } from "../agent/Agent";
import { setInstance } from "../agent/AgentSingleton";
import { APIForTesting, Token } from "../agent/API";
import { IDGeneratorFixed } from "../agent/IDGenerator";
import { LoggerNoop } from "../agent/Logger";
import { Context, runWithContext } from "../agent/Context";
import { MongoDB } from "./MongoDB";
Expand All @@ -29,7 +28,6 @@ t.test("we can highjack the MongoDB library", async (t) => {
new LoggerNoop(),
new APIForTesting(),
new Token("123"),
new IDGeneratorFixed("id"),
false,
{
mongodb: "1.0.0",
Expand Down
14 changes: 1 addition & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 322b5ad

Please sign in to comment.