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

Commit

Permalink
Merge pull request #556 from JupiterOne/storage-constants-refactor
Browse files Browse the repository at this point in the history
Refactor storage bucket constants
  • Loading branch information
gastonyelmini authored Nov 11, 2022
2 parents 0d9e262 + 2dd5a03 commit 29ace9b
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 268 deletions.
6 changes: 3 additions & 3 deletions src/getStepStartStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ import {
STEP_SPANNER_INSTANCE_DATABASES,
} from './steps/spanner/constants';
import { SqlAdminSteps, STEP_SQL_ADMIN_INSTANCES } from './steps/sql-admin';
import { STEP_CLOUD_STORAGE_BUCKETS } from './steps/storage';
import { StorageStepsSpec } from './steps/storage/constants';
import { IntegrationConfig, SerializedIntegrationConfig } from './types';
import { deserializeIntegrationConfig } from './utils/integrationConfig';
import { isMasterOrganizationInstance } from './utils/isMasterOrganizationInstance';
Expand Down Expand Up @@ -305,7 +305,7 @@ function getDefaultStepStartStates(params: {
[STEP_CLOUD_FUNCTIONS_SERVICE_ACCOUNT_RELATIONSHIPS]: { disabled: false },
[STEP_CLOUD_FUNCTIONS_SOURCE_REPO_RELATIONSHIPS]: { disabled: false },
[STEP_CLOUD_FUNCTIONS_STORAGE_BUCKET_RELATIONSHIPS]: { disabled: false },
[STEP_CLOUD_STORAGE_BUCKETS]: { disabled: false },
[StorageStepsSpec.FETCH_STORAGE_BUCKETS.id]: { disabled: false },
[STEP_IAM_CUSTOM_ROLES]: { disabled: false },
[STEP_IAM_CUSTOM_ROLE_SERVICE_API_RELATIONSHIPS]: { disabled: false },
[STEP_IAM_MANAGED_ROLES]: { disabled: false },
Expand Down Expand Up @@ -601,7 +601,7 @@ async function getStepStartStatesUsingServiceEnablements(params: {
[STEP_CLOUD_FUNCTIONS_STORAGE_BUCKET_RELATIONSHIPS]: createStepStartState(
ServiceUsageName.CLOUD_FUNCTIONS,
),
[STEP_CLOUD_STORAGE_BUCKETS]: createStepStartState(
[StorageStepsSpec.FETCH_STORAGE_BUCKETS.id]: createStepStartState(
ServiceUsageName.STORAGE,
ServiceUsageName.STORAGE_COMPONENT,
ServiceUsageName.STORAGE_API,
Expand Down
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ import {
STEP_SPANNER_INSTANCE_DATABASES,
} from './steps/spanner/constants';
import { SqlAdminSteps, STEP_SQL_ADMIN_INSTANCES } from './steps/sql-admin';
import { STEP_CLOUD_STORAGE_BUCKETS } from './steps/storage';
import { IntegrationConfig } from './types';
import {
STEP_CLOUD_FUNCTIONS,
STEP_CLOUD_FUNCTIONS_SERVICE_ACCOUNT_RELATIONSHIPS,
STEP_CLOUD_FUNCTIONS_SOURCE_REPO_RELATIONSHIPS,
STEP_CLOUD_FUNCTIONS_STORAGE_BUCKET_RELATIONSHIPS,
} from './steps/functions';
import { StorageStepsSpec } from './steps/storage/constants';

interface ValidateInvocationInvalidConfigTestParams {
instanceConfig?: Partial<IntegrationConfig>;
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('#getStepStartStates success', () => {
[STEP_CLOUD_FUNCTIONS_STORAGE_BUCKET_RELATIONSHIPS]: {
disabled: false,
},
[STEP_CLOUD_STORAGE_BUCKETS]: {
[StorageStepsSpec.FETCH_STORAGE_BUCKETS.id]: {
disabled: false,
},
[STEP_IAM_CUSTOM_ROLES]: {
Expand Down
12 changes: 6 additions & 6 deletions src/steps/app-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ import {
createAppEngineVersionEntity,
} from './converters';
import { getCloudStorageBucketKey } from '../storage/converters';
import {
CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
STEP_CLOUD_STORAGE_BUCKETS,
} from '../storage';
import {
IAM_SERVICE_ACCOUNT_ENTITY_TYPE,
GOOGLE_USER_ENTITY_TYPE,
STEP_IAM_SERVICE_ACCOUNTS,
} from '../iam/constants';
import { isServiceAccountEmail } from '../../utils/iam';
import { StorageEntitiesSpec, StorageStepsSpec } from '../storage/constants';

async function withAppEngineErrorHandling<T>(
logger: IntegrationLogger,
Expand Down Expand Up @@ -404,10 +401,13 @@ export const appEngineSteps: IntegrationStep<IntegrationConfig>[] = [
_class: RelationshipClass.USES,
_type: RELATIONSHIP_TYPE_APP_ENGINE_APPLICATION_USES_BUCKET,
sourceType: ENTITY_TYPE_APP_ENGINE_APPLICATION,
targetType: CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
targetType: StorageEntitiesSpec.STORAGE_BUCKET._type,
},
],
dependsOn: [STEP_APP_ENGINE_APPLICATION, STEP_CLOUD_STORAGE_BUCKETS],
dependsOn: [
STEP_APP_ENGINE_APPLICATION,
StorageStepsSpec.FETCH_STORAGE_BUCKETS.id,
],
executionHandler: buildAppEngineApplicationUsesBucketRelationships,
},
{
Expand Down
8 changes: 3 additions & 5 deletions src/steps/cloud-asset/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ import {
fetchBigQueryDatasets,
BIG_QUERY_DATASET_ENTITY_TYPE,
} from '../big-query';
import {
fetchStorageBuckets,
CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
} from '../storage';
import { fetchStorageBuckets } from '../storage';
import { CLOUD_FUNCTION_ENTITY_TYPE, fetchCloudFunctions } from '../functions';
import { IAM_MANAGED_ROLES_DATA_JOB_STATE_KEY } from '../../utils/iam';
import { fetchApiServices } from '../service-usage';
import { StorageEntitiesSpec } from '../storage/constants';

/* eslint-disable no-console */
expect.extend({
Expand Down Expand Up @@ -660,7 +658,7 @@ describe('#fetchIamBindings', () => {

await fetchStorageBuckets(context);
const storageBuckets = context.jobState.collectedEntities.filter(
(e) => e._type === CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
(e) => e._type === StorageEntitiesSpec.STORAGE_BUCKET._type,
);
expect(storageBuckets.length).toBeGreaterThan(0);

Expand Down
4 changes: 2 additions & 2 deletions src/steps/cloud-build/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RelationshipClass } from '@jupiterone/integration-sdk-core';
import { CloudSourceRepositoriesEntitiesSpec } from '../cloud-source-repositories/constants';
import { CLOUD_STORAGE_BUCKET_ENTITY_TYPE } from '../storage';
import { StorageEntitiesSpec } from '../storage/constants';

export const CloudBuildEntitiesSpec = {
BUILD: {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const CloudBuildRelationshipsSpec = {
_type: 'google_cloud_build_uses_storage_bucket',
_class: RelationshipClass.USES,
sourceType: CloudBuildEntitiesSpec.BUILD._type,
targetType: CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
targetType: StorageEntitiesSpec.STORAGE_BUCKET._type,
},
BUILD_USES_SOURCE_REPOSITORY: {
_type: 'google_cloud_build_uses_source_repository',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@jupiterone/integration-sdk-core';
import { cloudbuild_v1 } from 'googleapis';
import { IntegrationConfig, IntegrationStepContext } from '../../../types';
import { STEP_CLOUD_STORAGE_BUCKETS } from '../../storage';
import { StorageStepsSpec } from '../../storage/constants';
import {
CloudBuildEntitiesSpec,
CloudBuildRelationshipsSpec,
Expand All @@ -20,7 +20,7 @@ export const buildCloudBuildUsesStorageBucketRelationshipsStep: IntegrationStep<
relationships: [CloudBuildRelationshipsSpec.BUILD_USES_STORAGE_BUCKET],
dependsOn: [
CloudBuildStepsSpec.FETCH_BUILDS.id,
STEP_CLOUD_STORAGE_BUCKETS,
StorageStepsSpec.FETCH_STORAGE_BUCKETS.id,
],
executionHandler: async function (context: IntegrationStepContext) {
const { jobState } = context;
Expand Down
8 changes: 3 additions & 5 deletions src/steps/compute/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import {
buildComputeBackendBucketHasBucketRelationships,
buildImageUsesKmsRelationships,
} from '.';
import {
CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
fetchStorageBuckets,
} from '../storage';
import { fetchStorageBuckets } from '../storage';
import { integrationConfig } from '../../../test/config';
import {
ENTITY_TYPE_COMPUTE_DISK,
Expand Down Expand Up @@ -109,6 +106,7 @@ import { fetchIamServiceAccounts } from '../iam';
import { fetchKmsCryptoKeys, fetchKmsKeyRings } from '../kms';
import { filterGraphObjects } from '../../../test/helpers/filterGraphObjects';
import { separateDirectMappedRelationships } from '../../../test/helpers/separateDirectMappedRelationships';
import { StorageEntitiesSpec } from '../storage/constants';

const tempNewAccountConfig = {
...integrationConfig,
Expand Down Expand Up @@ -1510,7 +1508,7 @@ describe('#fetchComputeBackendBuckets', () => {

expect(
context.jobState.collectedEntities.filter(
(e) => e._type === CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
(e) => e._type === StorageEntitiesSpec.STORAGE_BUCKET._type,
),
).toMatchGraphObjectSchema({
_class: ['DataStore'],
Expand Down
14 changes: 7 additions & 7 deletions src/steps/compute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ import {
getFirewallRelationshipDirection,
processFirewallRuleRelationshipTargets,
} from '../../utils/firewall';
import {
CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
STEP_CLOUD_STORAGE_BUCKETS,
} from '../storage';
import { getCloudStorageBucketKey } from '../storage/converters';
import { publishMissingPermissionEvent } from '../../utils/events';
import { parseRegionNameFromRegionUrl } from '../../google-cloud/regions';
Expand All @@ -201,6 +197,7 @@ import {
setNetworkPeerings,
setPeeredNetworks,
} from '../../utils/jobState';
import { StorageEntitiesSpec, StorageStepsSpec } from '../storage/constants';

export * from './constants';

Expand Down Expand Up @@ -1028,7 +1025,7 @@ export async function fetchComputeAddresses(

await client.iterateComputeAddresses(async (address) => {
const addressEntity = await jobState.addEntity(
createComputeAddressEntity(address, client.projectId)
createComputeAddressEntity(address, client.projectId),
);

// Subnetwork -> HAS -> Compute Address
Expand Down Expand Up @@ -2578,10 +2575,13 @@ export const computeSteps: IntegrationStep<IntegrationConfig>[] = [
_class: RelationshipClass.HAS,
_type: RELATIONSHIP_TYPE_BACKEND_BUCKET_HAS_STORAGE_BUCKET,
sourceType: ENTITY_TYPE_COMPUTE_BACKEND_BUCKET,
targetType: CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
targetType: StorageEntitiesSpec.STORAGE_BUCKET._type,
},
],
dependsOn: [STEP_COMPUTE_BACKEND_BUCKETS, STEP_CLOUD_STORAGE_BUCKETS],
dependsOn: [
STEP_COMPUTE_BACKEND_BUCKETS,
StorageStepsSpec.FETCH_STORAGE_BUCKETS.id,
],
executionHandler: buildComputeBackendBucketHasBucketRelationships,
},
{
Expand Down
8 changes: 3 additions & 5 deletions src/steps/dataproc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import {
RELATIONSHIP_TYPE_DATAPROC_CLUSTER_USES_STORAGE_BUCKET,
} from './constants';
import { fetchKmsCryptoKeys, fetchKmsKeyRings } from '../kms';
import {
CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
fetchStorageBuckets,
} from '../storage';
import { fetchStorageBuckets } from '../storage';
import { ENTITY_TYPE_COMPUTE_IMAGE, fetchComputeImages } from '../compute';
import { separateDirectMappedRelationships } from '../../../test/helpers/separateDirectMappedRelationships';
import { omitNewRegionsFromTests } from '../../../test/regions';
import { StorageEntitiesSpec } from '../storage/constants';

beforeAll(() => omitNewRegionsFromTests());

Expand Down Expand Up @@ -416,7 +414,7 @@ describe('#createClusterStorageRelationships', () => {

expect(
context.jobState.collectedEntities.filter(
(e) => e._type === CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
(e) => e._type === StorageEntitiesSpec.STORAGE_BUCKET._type,
),
).toMatchGraphObjectSchema({
_class: ['DataStore'],
Expand Down
12 changes: 6 additions & 6 deletions src/steps/dataproc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { IntegrationConfig, IntegrationStepContext } from '../../types';
import { getKmsGraphObjectKeyFromKmsKeyName } from '../../utils/kms';
import { ENTITY_TYPE_COMPUTE_IMAGE, STEP_COMPUTE_IMAGES } from '../compute';
import { ENTITY_TYPE_KMS_KEY, STEP_CLOUD_KMS_KEYS } from '../kms';
import {
CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
STEP_CLOUD_STORAGE_BUCKETS,
} from '../storage';
import { StorageEntitiesSpec, StorageStepsSpec } from '../storage/constants';
import { getCloudStorageBucketKey } from '../storage/converters';
import { DataProcClient } from './client';
import {
Expand Down Expand Up @@ -240,10 +237,13 @@ export const dataprocSteps: IntegrationStep<IntegrationConfig>[] = [
_class: RelationshipClass.USES,
_type: RELATIONSHIP_TYPE_DATAPROC_CLUSTER_USES_STORAGE_BUCKET,
sourceType: ENTITY_TYPE_DATAPROC_CLUSTER,
targetType: CLOUD_STORAGE_BUCKET_ENTITY_TYPE,
targetType: StorageEntitiesSpec.STORAGE_BUCKET._type,
},
],
dependsOn: [STEP_DATAPROC_CLUSTERS, STEP_CLOUD_STORAGE_BUCKETS],
dependsOn: [
STEP_DATAPROC_CLUSTERS,
StorageStepsSpec.FETCH_STORAGE_BUCKETS.id,
],
executionHandler: createClusterStorageRelationships,
},
];
Loading

0 comments on commit 29ace9b

Please sign in to comment.