-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from cloudgraphdev/feature/subs
feat: Create azureSubscription service to contain all the data under one subscription
- Loading branch information
Showing
11 changed files
with
431 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import services from './services' | ||
|
||
export default { | ||
[services.actionGroup]: 'actionGroups', | ||
[services.activityLogAlerts]: 'activityLogAlerts', | ||
[services.aksManagedCluster]: 'aksManagedClusters', | ||
[services.appServiceEnvironment]: 'appServiceEnvironments', | ||
[services.appInsights]: 'appInsights', | ||
[services.appServicePlan]: 'appServicePlans', | ||
[services.appServiceWebApp]: 'appServiceWebApps', | ||
[services.arcConnectedCluster]: 'arcConnectedClusters', | ||
[services.authRoleAssignment]: 'authRoleAssignments', | ||
[services.authRoleDefinition]: 'authRoleDefinitions', | ||
[services.autoProvisioningSettings]: 'autoProvisioningSettings', | ||
[services.backupVault]: 'backupVaults', | ||
[services.backupInstance]: 'backupInstances', | ||
[services.backupPolicy]: 'backupPolicies', | ||
[services.cdnCustomDomains]: 'cdnCustomDomains', | ||
[services.cdnEndpoints]: 'cdnEndpoints', | ||
[services.cdnOriginGroups]: 'cdnOriginGroups', | ||
[services.cdnOrigins]: 'cdnOrigins', | ||
[services.cdnProfiles]: 'cdnProfiles', | ||
[services.cognitiveServicesAccount]: 'cognitiveServicesAccounts', | ||
[services.containerRegistry]: 'containerRegistries', | ||
[services.cosmosDb]: 'cosmosDbs', | ||
[services.dataCollectionRule]: 'dataCollectionRules', | ||
[services.dataFactory]: 'dataFactories', | ||
[services.databaseManagedSqlInstance]: 'databaseManagedSqlInstances', | ||
[services.databaseMySql]: 'databaseMySql', | ||
[services.databasePostgreSql]: 'databasePostgreSql', | ||
[services.databaseSqlVm]: 'databaseSqlVm', | ||
[services.databaseSql]: 'databaseSql', | ||
[services.dataLakeStorageAccounts]: 'dataLakeStorageAccounts', | ||
[services.diagnosticSettings]: 'diagnosticSettings', | ||
[services.disk]: 'disks', | ||
[services.dns]: 'dnsZones', | ||
[services.eventGrid]: 'eventGrids', | ||
[services.eventHub]: 'eventHubs', | ||
[services.expressRouteGateways]: 'expressRouteGateways', | ||
[services.fileShare]: 'fileShares', | ||
[services.firewall]: 'firewalls', | ||
[services.functionApp]: 'functionApps', | ||
[services.integrationRuntime]: 'integrationRuntimes', | ||
[services.keyVault]: 'keyVaults', | ||
[services.loadBalancer]: 'loadBalancers', | ||
[services.logAnalyticsSolution]: 'logAnalyticsSolutions', | ||
[services.logAnalyticsWorkspace]: 'logAnalyticsWorkspaces', | ||
[services.logProfiles]: 'logProfiles', | ||
[services.machineLearningWorkspaces]: 'machineLearningWorkspaces', | ||
[services.metricAlert]: 'metricAlerts', | ||
[services.mySqlServers]: 'mySqlServers', | ||
[services.networkInterface]: 'networkInterfaces', | ||
[services.policyAssignment]: 'policyAssignments', | ||
[services.postgreSqlServers]: 'postgreSqlServers', | ||
[services.privateDns]: 'privateDnsZones', | ||
[services.publicIp]: 'publicIps', | ||
[services.recoveryVaults]: 'recoveryVaults', | ||
[services.redisCaches]: 'redisCaches', | ||
[services.replicationAppliances]: 'replicationAppliances', | ||
[services.replicationCenters]: 'replicationCenters', | ||
[services.replicationNetworks]: 'replicationNetworks', | ||
[services.replicationPolicies]: 'replicationPolicies', | ||
[services.resourceGroup]: 'resourceGroups', | ||
[services.securityAssesments]: 'securityAssesments', | ||
[services.securityContacts]: 'securityContacts', | ||
[services.securityGroup]: 'securityGroups', | ||
[services.securityPricings]: 'securityPricings', | ||
[services.securitySettings]: 'securitySettings', | ||
[services.serviceBus]: 'serviceBuses', | ||
[services.sqlServers]: 'sqlServers', | ||
[services.storageAccount]: 'storageAccounts', | ||
[services.storageBlob]: 'storageBlobs', | ||
[services.storageContainer]: 'storageContainers', | ||
[services.synapseBigDataPools]: 'synapseBigDataPools', | ||
[services.synapseSqlPools]: 'synapseSqlPools', | ||
[services.synapseWorkspaces]: 'synapseWorkspaces', | ||
[services.trafficManagerProfile]: 'trafficManagerProfiles', | ||
[services.virtualMachineScaleSet]: 'virtualMachineScaleSets', | ||
[services.virtualMachine]: 'virtualMachines', | ||
[services.virtualNetwork]: 'virtualNetworks', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ProviderData } from '@cloudgraph/sdk' | ||
import { rawDataInterface } from '../../types' | ||
import { checkAndMergeConnections } from '../../utils' | ||
import addSubscriptionConnections from '../subscription/connections' | ||
|
||
/** | ||
* Data Enhancers | ||
*/ | ||
export interface EnhancerConfig { | ||
rawData: rawDataInterface[] | ||
subscriptions: { id: string; accountId: string; regions: string[] }[] | ||
configuredRegions: string | ||
data: ProviderData | ||
} | ||
|
||
/** | ||
* Generates Azure services connections to Scanned subscriptions | ||
* @param {EnhancerConfig} subscriptions Scanned subscriptions | ||
* @param {EnhancerConfig} data Azure Services fetched data | ||
* @returns {ProviderData} | ||
*/ | ||
export const connectAzureServicesToSubscription = ({ | ||
subscriptions, | ||
data, | ||
}: EnhancerConfig): ProviderData => { | ||
let subscriptionsConnections = {} | ||
for (const account of subscriptions) { | ||
const connections = addSubscriptionConnections({ | ||
service: account, | ||
data: data.entities, | ||
}) | ||
subscriptionsConnections = { | ||
...subscriptionsConnections, | ||
...connections, | ||
} | ||
} | ||
return { | ||
entities: data.entities, | ||
connections: checkAndMergeConnections( | ||
data.connections, | ||
subscriptionsConnections | ||
), | ||
} | ||
} | ||
|
||
export default [ | ||
{ name: 'subscription', enhancer: connectAzureServicesToSubscription }, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Entity, ServiceConnection } from '@cloudgraph/sdk' | ||
import { flatMap } from 'lodash' | ||
import services from '../../enums/services' | ||
import aliases from '../../enums/serviceAliases' | ||
|
||
export default ({ | ||
service, | ||
data, | ||
}: { | ||
service: { id: string; regions: string[] } | ||
data: Entity[] | ||
}): { | ||
[property: string]: ServiceConnection[] | ||
} => { | ||
const { id: subscriptionId } = service | ||
const connections: ServiceConnection[] = [] | ||
const connectTo = Object.values(services) | ||
|
||
for (const serviceName of connectTo) { | ||
const instances: { | ||
name: string | ||
data: { [property: string]: any[] } | ||
} = data.find(({ name }) => name === serviceName) | ||
|
||
if (instances?.data) { | ||
const filtered = flatMap(instances.data).filter( | ||
i => i.subscriptionId === subscriptionId | ||
) | ||
|
||
for (const instance of filtered) { | ||
if (instance) { | ||
connections.push({ | ||
id: instance.id, | ||
resourceType: serviceName, | ||
relation: 'child', | ||
field: aliases[serviceName] ? aliases[serviceName] : serviceName, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return { | ||
[subscriptionId]: connections, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Service } from '@cloudgraph/sdk' | ||
import BaseService from '../base' | ||
import mutation from './mutation' | ||
|
||
export default class AzureSubscription extends BaseService implements Service { | ||
format = ({ service }: { service: any }): any => service | ||
|
||
getData | ||
|
||
mutation = mutation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default `mutation($input: [AddazureSubscriptionInput!]!) { | ||
addazureSubscription(input: $input, upsert: true) { | ||
numUids | ||
} | ||
}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
type azureSubscription implements azureBaseResource @key(fields: "id") { | ||
regions: [String] @search(by: [hash]) | ||
actionGroups: [azureActionGroup] | ||
activityLogAlerts: [azureActivityLogAlert], | ||
aksManagedClusters: [azureAksManagedCluster] | ||
appInsights: [azureAppInsights] | ||
appServiceEnvironments: [azureAppServiceEnvironment] | ||
appServicePlans: [azureAppServicePlan] | ||
appServiceWebApps: [azureAppServiceWebApp] | ||
arcConnectedClusters: [azureArcConnectedCluster] | ||
authRoleAssignments: [azureAuthRoleAssignment] | ||
authRoleDefinitions: [azureAuthRoleDefinition] | ||
autoProvisioningSettings: [azureAutoProvisioningSetting] | ||
backupVaults: [azureBackupVault] | ||
backupInstances: [azureBackupInstance] | ||
backupPolicies: [azureBackupPolicy] | ||
billing: [azureBilling] | ||
cdnCustomDomains: [azureCdnCustomDomain] | ||
cdnEndpoints: [azureCdnEndpoint] | ||
cdnProfiles: [azureCdnProfile] | ||
cognitiveServicesAccounts: [azureCognitiveServicesAccount] | ||
containerRegistries: [azureContainerRegistry] | ||
cosmosDbs: [azureCosmosDb] | ||
databaseManagedSqlInstances: [azureDatabaseManagedSqlInstance] | ||
databaseMySql: [azureDatabaseMySql] | ||
databasePostgreSql: [azureDatabasePostgreSql] | ||
databaseSql: [azureDatabaseSql] | ||
databaseSqlVm: [azureDatabaseSqlVm] | ||
dataCollectionRules: [azureDataCollectionRule] | ||
dataFactories: [azureDataFactory] | ||
dataLakeStorageAccounts: [azureDataLakeStorageAccount] | ||
diagnosticSettings: [azureDiagnosticSetting] | ||
disks: [azureDisk] | ||
dnsZoneRecordSets: [azureDnsZoneRecordSet] | ||
dnsZones: [azureDnsZone] | ||
eventGrids: [azureEventGrid], | ||
eventHubs: [azureEventHub], | ||
expressRouteGateways: [azureExpressRouteGateway] | ||
fileShares: [azureFileShare] | ||
firewalls: [azureFirewall] | ||
functionApps: [azureFunctionApp] | ||
integrationRuntimes: [azureIntegrationRuntime], | ||
keyVaults: [azureKeyVault] | ||
loadBalancers: [azureLoadBalancer] | ||
logAnalyticsSolutions: [azureLogAnalyticsSolution] | ||
logAnalyticsWorkspaces: [azureLogAnalyticsWorkspace] | ||
logProfiles: [azureLogProfile] | ||
machineLearningWorkspaces: [azureMachineLearningWorkspace] | ||
metricAlerts: [azureMetricAlert] | ||
mySqlServers: [azureMySqlServer] | ||
networkInterfaces: [azureNetworkInterface] | ||
networkSecurityGroups: [azureNetworkSecurityGroup] | ||
policyAssignments: [azurePolicyAssignment] | ||
postgreSqlServers: [azurePostgreSqlServer] | ||
privateDnsZones: [azurePrivateDnsZone] | ||
publicIps: [azurePublicIp] | ||
recoveryVaults: [azureRecoveryVault] | ||
redisCaches: [azureRedisCache] | ||
replicationAppliances: [azureReplicationAppliance] | ||
replicationCenters: [azureReplicationCenter] | ||
replicationNetworks: [azureReplicationNetwork] | ||
replicationPolicies: [azureReplicationPolicy] | ||
resourceGroups: [azureResourceGroup] | ||
securityAssesments: [azureSecurityAssesment], | ||
securityContacts: [azureSecurityContact] | ||
securityGroups: [azureNetworkSecurityGroup] | ||
securityPricings: [azureSecurityPricing] | ||
securitySettings: [azureSecuritySetting] | ||
serviceBuses: [azureServiceBus] | ||
sqlServers: [azureSqlServer] | ||
storageAccounts: [azureStorageAccount] | ||
storageBlobs: [azureStorageBlob] | ||
storageContainers: [azureStorageContainer] | ||
synapseBigDataPools: [azureSynapseBigDataPool] | ||
synapseSqlPools: [azureSynapseSqlPool] | ||
synapseWorkspaces: [azureSynapseWorkspace] | ||
trafficManagerProfiles: [azureTrafficManagerProfile] | ||
virtualMachines: [azureVirtualMachine] | ||
virtualMachineScaleSets: [azureVirtualMachineScaleSet] | ||
virtualNetworks: [azureVirtualNetwork] | ||
} |
Oops, something went wrong.