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

Pull request from main #663

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SERVICE_ACCOUNT_KEY_FILE={}
PROJECT_ID=""
ORGANIZATION_ID=""
CONFIGURE_ORGANIZATION_PROJECTS=false
FOLDER_ID=""
FOLDER_ID=""
COMPUTE_INSTANCE_METADATA_FIELDS_TO_INGEST=""
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v3.3.4 (Fri May 03 2024)

#### 🐛 Bug Fix

- INT-8094: ingest compute instance metadata fields [#659](https://github.com/JupiterOne/graph-google-cloud/pull/659) ([@gastonyelmini](https://github.com/gastonyelmini))

#### Authors: 1

- Gaston Yelmini ([@gastonyelmini](https://github.com/gastonyelmini))

---

# v3.3.3 (Tue Apr 09 2024)

#### 🐛 Bug Fix
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupiterone/graph-google-cloud",
"version": "3.3.3",
"version": "3.3.4",
"description": "A graph conversion tool for https://cloud.google.com/",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export const invocationConfig: IntegrationInvocationConfig<IntegrationConfig> =
type: 'boolean',
optional: true,
},
computeInstanceMetadataFieldsToIngest: {
type: 'string',
optional: true,
},
},
getStepStartStates,
integrationSteps: steps,
Expand Down
40 changes: 40 additions & 0 deletions src/steps/compute/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
ENTITY_TYPE_COMPUTE_TARGET_SSL_PROXY,
MAPPED_RELATIONSHIP_FIREWALL_RULE_TYPE,
} from './constants';
import { camelCase } from 'lodash';

export function createComputeProjectEntity(data: compute_v1.Schema$Project) {
return createGoogleCloudIntegrationEntity(data, {
Expand Down Expand Up @@ -434,10 +435,45 @@ function isShieldedVM(
: false;
}

function getComputeInstanceMetadataFieldsToIngest(
computeInstanceMetadataFieldsToIngest: string | undefined,
computeInstanceMetadata:
| { key?: string | undefined; value?: string | undefined }[]
| null
| undefined,
) {
const parsedcomputeInstanceMetadataFieldsToIngest: string[] | undefined =
computeInstanceMetadataFieldsToIngest?.split(',');

if (
!parsedcomputeInstanceMetadataFieldsToIngest ||
!parsedcomputeInstanceMetadataFieldsToIngest.length ||
!computeInstanceMetadata ||
!computeInstanceMetadata.length
) {
return {};
}

const metadataObject = {};

for (const metadata of computeInstanceMetadata) {
if (
metadata.key &&
parsedcomputeInstanceMetadataFieldsToIngest.includes(metadata.key)
) {
const parsedKey = `metadata.${camelCase(metadata.key)}`;
metadataObject[parsedKey] = metadata.value;
}
}

return metadataObject;
}

export function createComputeInstanceEntity(
data: compute_v1.Schema$Instance,
instanceInventory: osconfig_v1.Schema$Inventory | undefined,
projectId: string,
computeInstanceMetadataFieldsToIngest: string | undefined,
) {
const ipAddresses = getIpAddressesForComputeInstance(data);
const zone = getLastUrlPart(data.zone!);
Expand Down Expand Up @@ -501,6 +537,10 @@ export function createComputeInstanceEntity(
webLink: getGoogleCloudConsoleWebLink(
`/compute/instancesDetail/zones/${zone}/instances/${data.name}?project=${projectId}`,
),
...getComputeInstanceMetadataFieldsToIngest(
computeInstanceMetadataFieldsToIngest,
data.metadata?.items,
),
osHostname: instanceInventory?.osInfo?.hostname,
osLongName: instanceInventory?.osInfo?.longName,
osShortName: instanceInventory?.osInfo?.shortName,
Expand Down
1 change: 1 addition & 0 deletions src/steps/compute/steps/fetch-compute-instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export async function fetchComputeInstances(
computeInstance,
instanceInventory,
client.projectId,
context.instance.config.computeInstanceMetadataFieldsToIngest,
),
);

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface SerializedIntegrationConfig extends IntegrationInstanceConfig {
configureOrganizationProjects?: boolean;
folderId?: string;
useEnablementsForStepStartStates?: boolean;
computeInstanceMetadataFieldsToIngest?: string;
}

export interface IntegrationConfig extends SerializedIntegrationConfig {
Expand Down
Loading