Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #115 from JupiterOne/add-system-version
Browse files Browse the repository at this point in the history
Add system version to gitlab_account entity
  • Loading branch information
mikiodehartj1 authored May 17, 2024
2 parents e05019c + 736098d commit 27971b0
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 60 deletions.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
27 changes: 27 additions & 0 deletions src/converters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,36 @@ import {
GitLabUser,
GitLabFinding,
GitlabLabel,
GitLabVersion,
} from '../provider/types';
import { getCommitWebLinkFromMergeRequest } from '../util/mergeRequest';

export function createAccountEntity(
tokenOwner: GitLabUser,
systemVersion: GitLabVersion,
): Entity {
return createIntegrationEntity({
entityData: {
source: { systemVersion, tokenOwner },
assign: {
_key: createAccountEntityKey(systemVersion.version),
_type: Entities.ACCOUNT._type,
_class: Entities.ACCOUNT._class,
id: tokenOwner.id.toString(),
name: tokenOwner.name,
version: systemVersion.version,
revision: systemVersion.revision,
enterprise: systemVersion.enterprise,
},
},
});
}

const ACCOUNT_VERSION_PREFIX = 'gitlab-account-version';
export function createAccountEntityKey(version: string): string {
return `${ACCOUNT_VERSION_PREFIX}:${version}`;
}

export function createProjectEntity(project: GitLabProject): Entity {
const { _links, ...source } = project; // drop the _links
const key = createProjectEntityIdentifier(project.id);
Expand Down
7 changes: 6 additions & 1 deletion src/provider/GitlabClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
GitLabUser,
GitLabUserRef,
GitlabLabel,
GitLabVersion,
} from './types';

/**
Expand Down Expand Up @@ -71,10 +72,14 @@ export class GitlabClient {
});
}

async fetchAccount(): Promise<GitLabUser> {
async fetchTokenOwner(): Promise<GitLabUser> {
return this.makeSingularRequest(HttpMethod.GET, '/user');
}

async fetchSystemVersion(): Promise<GitLabVersion> {
return this.makeSingularRequest(HttpMethod.GET, '/version');
}

async fetchUser(id: number): Promise<GitLabUser> {
return this.makeSingularRequest(HttpMethod.GET, `/users/${id}`);
}
Expand Down
6 changes: 6 additions & 0 deletions src/provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export interface GitLabFinding {
blob_path?: string;
}

export type GitLabVersion = {
version: string;
revision: string;
enterprise: boolean;
};

export type GitLabProject = Opaque<any, 'GitLabProject'>;

export type GitLabMergeRequest = Opaque<any, 'GitLabMergeRequest'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@
"response": {
"bodySize": 1043,
"content": {
"encoding": "hex",
"mimeType": "application/json",
"size": 1043,
"text": "[\"1f8b08000000000000038452db6ee32010fd97797613ecc4b58354ed7ec3aa0fd55e84309e38d360888671d26ed57f5f112755db872e4fcc01ce658617a01e74ddb64dd5d605043b2268c007611cf1010a9812f227f4071490c44ac6ac133a2214608f562c9b893d68d8891c925e2e13ba897131f07cba70715ccedb65bd6eca756d558d8d43d7b5eab62c3bbb5575bda9eab2adbea5bb56fd9e94aa6efb3bea3108b918a08013769f5406126fbb33f97b8b8ed10af6c60a68a854a56ed4faa66aefcb4aaf56baaa175553ff84023a8aa0c3e47d013e3a2b14c3b53e4c9d276770b4940573eefdf301e7ada7b0c79ec25cc9894490e7e2845d22c18b4f2820f26003fdfd40fe183b2324fe42778abc3714b691c70fd7bc4d62120dc150789fa5be51ed7d59ea72a3d57ab1524dce\",\"e262d8128f5fa65e9d539f69cfd323793659ee8db7aca0806b66177bccd6f8fb9091dce59c7687239afc75ca2cea239be4de63078e8fe824194f2309e852e555809b98317c11a8d1aad6ebcda2d9dc669bf3e4853081fef592698fd49fdb3c90eca62e3b7d12e460a6ac0c2bb5aa36aa69f2a8ece8cdf5c1d9576ee8eb9f029c0d66fe1d66e0381d400b4ff801bff8bf9ec8299aad7512d960b09dc71ef4d6fa845779ebdf8003d3f142b1a53cdd0b9e7696b1373c85809ccc4861127c6bd03c6c7c12b6e6ff375fff010000ffff0300cb1e1260b8030000\"]"
"text": "{\"id\":5887285,\"name\":\"eXtremeX\",\"username\":\"eXtremeXR\",\"state\":\"active\",\"avatar_url\":\"https://secure.gravatar.com/avatar/547145a05e7cecb80611baf055925182?s=80\\u0026d=identicon\",\"web_url\":\"https://gitlab.com/eXtremeXR\",\"created_at\":\"2020-04-28T12:33:25.275Z\",\"bio\":null,\"location\":null,\"public_email\":\"\",\"skype\":\"\",\"linkedin\":\"\",\"twitter\":\"\",\"website_url\":\"\",\"organization\":null,\"job_title\":\"\",\"work_information\":null,\"last_sign_in_at\":\"2020-05-08T11:19:04.307Z\",\"confirmed_at\":\"2020-04-28T12:33:25.235Z\",\"last_activity_on\":\"2020-05-12\",\"email\":\"[email protected]\",\"theme_id\":1,\"color_scheme_id\":1,\"projects_limit\":100000,\"current_sign_in_at\":\"2020-05-08T17:05:49.796Z\",\"identities\":[{\"provider\":\"github\",\"extern_uid\":\"30329077\",\"saml_provider_id\":null}],\"can_create_group\":true,\"can_create_project\":true,\"two_factor_enabled\":false,\"external\":false,\"private_profile\":false,\"shared_runners_minutes_limit\":null,\"extra_shared_runners_minutes_limit\":null}"
},
"cookies": [
{
Expand All @@ -80,10 +79,6 @@
"name": "content-type",
"value": "application/json"
},
{
"name": "transfer-encoding",
"value": "chunked"
},
{
"name": "connection",
"value": "close"
Expand Down Expand Up @@ -173,10 +168,6 @@
"name": "cf-ray",
"value": "5923e377fbbffe20-HEL"
},
{
"name": "content-encoding",
"value": "gzip"
},
{
"name": "cf-request-id",
"value": "02aa4c7ef70000fe2045085200000001"
Expand All @@ -199,6 +190,177 @@
"ssl": -1,
"wait": 270
}
},
{
"_id": "4e5df97a9f6166992b9b16cadc5bf47f",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "private-token",
"value": "[REDACTED]"
},
{
"_fromType": "array",
"name": "accept",
"value": "*/*"
},
{
"_fromType": "array",
"name": "user-agent",
"value": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
},
{
"_fromType": "array",
"name": "accept-encoding",
"value": "gzip,deflate"
},
{
"_fromType": "array",
"name": "connection",
"value": "close"
},
{
"name": "host",
"value": "gitlab.com"
}
],
"headersSize": 242,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [],
"url": "https://gitlab.com/api/v4/version"
},
"response": {
"bodySize": 187,
"content": {
"mimeType": "application/json",
"size": 187,
"text": "{\"version\":\"17.0.0-pre\",\"revision\":\"41e5f397063\",\"kas\":{\"enabled\":true,\"externalUrl\":\"wss://kas.gitlab.com\",\"version\":\"17.0.0-rc4\"},\"enterprise\":true}"
},
"cookies": [
{
"domain": ".gitlab.com",
"httpOnly": true,
"name": "_cfuvid",
"path": "/",
"sameSite": "None",
"secure": true,
"value": "[REDACTED]"
}
],
"headers": [
{
"name": "date",
"value": "Mon, 13 May 2024 20:30:54 GMT"
},
{
"name": "content-type",
"value": "application/json"
},
{
"name": "connection",
"value": "close"
},
{
"name": "cache-control",
"value": "max-age=0, private, must-revalidate"
},
{
"name": "content-security-policy",
"value": "default-src 'none'"
},
{
"name": "etag",
"value": "W/\"2ceb7c2d9ade2111b6bf841906e7f413\""
},
{
"name": "vary",
"value": "Origin, Accept-Encoding"
},
{
"name": "x-content-type-options",
"value": "nosniff"
},
{
"name": "x-frame-options",
"value": "SAMEORIGIN"
},
{
"name": "x-gitlab-meta",
"value": "{\"correlation_id\":\"c07a0ff65585b585977076babb543731\",\"version\":\"1\"}"
},
{
"name": "x-request-id",
"value": "c07a0ff65585b585977076babb543731"
},
{
"name": "x-runtime",
"value": "0.036264"
},
{
"name": "strict-transport-security",
"value": "max-age=31536000"
},
{
"name": "referrer-policy",
"value": "strict-origin-when-cross-origin"
},
{
"name": "gitlab-lb",
"value": "haproxy-main-32-lb-gprd"
},
{
"name": "gitlab-sv",
"value": "api-gke-us-east1-d"
},
{
"name": "cf-cache-status",
"value": "MISS"
},
{
"name": "report-to",
"value": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=t00XJG3zSsPVNXiAey8oQJ%2B%2F8uTmLU4H9r8Yw%2FDPuOlfZ6Hb07%2FgyrrXdudswqMvZbbuBKc%2Fu73ddJObv1AoVoU%2FNxrxift3CYElUF4ArSTUHD6a8dkURxFxphg%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}"
},
{
"name": "nel",
"value": "{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}"
},
{
"_fromType": "array",
"name": "set-cookie",
"value": "[REDACTED]"
},
{
"name": "server",
"value": "cloudflare"
},
{
"name": "cf-ray",
"value": "883568b83ab627c8-SLC"
}
],
"headersSize": 1248,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-05-13T20:30:54.261Z",
"time": 598,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 598
}
}
],
"pages": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`step data collection 1`] = `
Array [
Object {
"_class": Array [
"Account",
],
"_key": "gitlab-account-version:17.0.0-pre",
"_rawData": Array [
Object {
"name": "default",
"rawData": Object {
"systemVersion": Object {
"enterprise": true,
"kas": Object {
"enabled": true,
"externalUrl": "wss://kas.gitlab.com",
"version": "17.0.0-rc4",
},
"revision": "41e5f397063",
"version": "17.0.0-pre",
},
"tokenOwner": Object {
"avatar_url": "https://secure.gravatar.com/avatar/547145a05e7cecb80611baf055925182?s=80&d=identicon",
"bio": null,
"can_create_group": true,
"can_create_project": true,
"color_scheme_id": 1,
"confirmed_at": "2020-04-28T12:33:25.235Z",
"created_at": "2020-04-28T12:33:25.275Z",
"current_sign_in_at": "2020-05-08T17:05:49.796Z",
"email": "[email protected]",
"external": false,
"extra_shared_runners_minutes_limit": null,
"id": 5887285,
"identities": Array [
Object {
"extern_uid": "30329077",
"provider": "github",
"saml_provider_id": null,
},
],
"job_title": "",
"last_activity_on": "2020-05-12",
"last_sign_in_at": "2020-05-08T11:19:04.307Z",
"linkedin": "",
"location": null,
"name": "eXtremeX",
"organization": null,
"private_profile": false,
"projects_limit": 100000,
"public_email": "",
"shared_runners_minutes_limit": null,
"skype": "",
"state": "active",
"theme_id": 1,
"twitter": "",
"two_factor_enabled": false,
"username": "eXtremeXR",
"web_url": "https://gitlab.com/eXtremeXR",
"website_url": "",
"work_information": null,
},
},
},
],
"_type": "gitlab_account",
"createdOn": undefined,
"displayName": "eXtremeX",
"enterprise": true,
"id": "5887285",
"name": "eXtremeX",
"revision": "41e5f397063",
"version": "17.0.0-pre",
},
]
`;
Loading

0 comments on commit 27971b0

Please sign in to comment.