Files
floci-ui/packages/api/src/cloudProxy.ts
T
Zakaria 70cfd4bc96
CI / checks (pull_request) Successful in 26m54s
feat(api): add EC2 Auto Scaling groups to the cloud explorer
Create groups from a launch template (in the default subnets unless given),
change their minimum, desired and maximum capacity, replace or remove an
instance, and follow the launches and terminations TheCloud's reconciler makes.
Deleting a group terminates its instances. Scaling policies are not offered:
the runtime stores them but its alarms only drive ECS scaling.
2026-10-25 13:02:49 -04:00

149 lines
7.9 KiB
TypeScript

import {CloudAdapterRegistry} from './registry/CloudAdapterRegistry'
import {AwsComputeAdapter} from './adapter-aws/AwsComputeAdapter'
import {AwsNetworkingAdapter} from './adapter-aws/AwsNetworkingAdapter'
import {AwsDatabaseAdapter} from './adapter-aws/AwsDatabaseAdapter'
import {AwsEksAdapter} from './adapter-aws/AwsEksAdapter'
import {AwsStorageAdapter} from './adapter-aws/AwsStorageAdapter'
import {AwsLogsAdapter} from './adapter-aws/AwsLogsAdapter'
import {AzureNoSqlAdapter} from './adapter-azure/AzureNoSqlAdapter'
import {AwsDynamoDbAdapter} from './adapter-aws/AwsDynamoDbAdapter'
import {AzureDatabaseAdapter} from './adapter-azure/AzureDatabaseAdapter'
import {AzureServiceBusAdapter} from './adapter-azure/AzureServiceBusAdapter'
import {AzureStorageAdapter} from './adapter-azure/AzureStorageAdapter'
import {AzureAksAdapter} from './adapter-azure/AzureAksAdapter'
import {AzureComputeAdapter} from './adapter-azure/AzureComputeAdapter'
import {GcpStorageAdapter} from './adapter-gcp/GcpStorageAdapter'
import {GcpCloudFunctionsAdapter} from './adapter-gcp/GcpCloudFunctionsAdapter'
import {GcpCloudSqlAdapter} from './adapter-gcp/GcpCloudSqlAdapter'
import {GcpGkeAdapter} from './adapter-gcp/GcpGkeAdapter'
import {GcpCloudRunAdapter} from './adapter-gcp/GcpCloudRunAdapter'
import {GcpPubSubAdapter} from './adapter-gcp/GcpPubSubAdapter'
import {GcpSecretManagerAdapter} from './adapter-gcp/GcpSecretManagerAdapter'
import {GcpSchedulerAdapter} from './adapter-gcp/GcpSchedulerAdapter'
import {AwsSqsAdapter} from './adapter-aws/AwsSqsAdapter'
import {CloudProxyService} from './service/CloudProxyService'
import {AzureServerlessAdapter} from './adapter-azure/AzureServerlessAdapter'
import {AzureKeyVaultAdapter} from './adapter-azure/AzureKeyVaultAdapter'
import {AwsServerlessAdapter} from './adapter-aws/AwsServerlessAdapter'
import {AwsParameterStoreAdapter} from './adapter-aws/AwsParameterStoreAdapter'
import {AwsKmsAdapter} from './adapter-aws/AwsKmsAdapter'
import {AwsStepFunctionsAdapter} from './adapter-aws/AwsStepFunctionsAdapter'
import {AwsLoadBalancingAdapter} from './adapter-aws/AwsLoadBalancingAdapter'
import {AwsTargetGroupAdapter} from './adapter-aws/AwsTargetGroupAdapter'
import {AwsEventBridgeAdapter} from './adapter-aws/AwsEventBridgeAdapter'
import {AwsIamAdapter} from './adapter-aws/AwsIamAdapter'
import {AwsApiGatewayAdapter} from './adapter-aws/AwsApiGatewayAdapter'
import {AwsCloudFormationAdapter} from './adapter-aws/AwsCloudFormationAdapter'
import {AwsSecretsAdapter} from './adapter-aws/AwsSecretsAdapter'
import {AwsSesAdapter} from './adapter-aws/AwsSesAdapter'
import {AwsAppConfigAdapter} from './adapter-aws/AwsAppConfigAdapter'
import {AwsSnsAdapter} from './adapter-aws/AwsSnsAdapter'
import {AwsEcrAdapter} from './adapter-aws/AwsEcrAdapter'
import {AwsCodeBuildAdapter} from './adapter-aws/AwsCodeBuildAdapter'
import {AwsCodePipelineAdapter} from './adapter-aws/AwsCodePipelineAdapter'
import {AwsCodeDeployAdapter} from './adapter-aws/AwsCodeDeployAdapter'
import {AwsEcsAdapter} from './adapter-aws/AwsEcsAdapter'
import {AwsFargateAdapter} from './adapter-aws/AwsFargateAdapter'
import {AwsKinesisAdapter} from './adapter-aws/AwsKinesisAdapter'
import {AwsElastiCacheAdapter} from './adapter-aws/AwsElastiCacheAdapter'
import {AwsLightsailAdapter} from './adapter-aws/AwsLightsailAdapter'
import {AwsUserPoolsAdapter} from './adapter-aws/AwsUserPoolsAdapter'
import {AwsDnsAdapter} from './adapter-aws/AwsDnsAdapter'
import {AwsCdnAdapter} from './adapter-aws/AwsCdnAdapter'
import {AwsAutoScalingAdapter} from './adapter-aws/AwsAutoScalingAdapter'
import {AwsCertificatesAdapter} from './adapter-aws/AwsCertificatesAdapter'
import {AwsPipesAdapter} from './adapter-aws/AwsPipesAdapter'
import {AwsMonitoringAdapter} from './adapter-aws/AwsMonitoringAdapter'
import {awsClientsForAccount, resolveAccountId} from './aws'
import {createEc2Service} from './services/ec2'
import {createEksService} from './services/eks'
import {createRdsService} from './services/rds'
/**
* Build the adapter registry for an account. The account id drives the AWS SDK
* credentials (see aws.ts), so every AWS call is isolated to that account; Azure
* and GCP adapters use their own runtime auth model and are account-neutral.
*
* Exported separately from the service so tests can assert registry contents —
* notably that every adapter implements what its schema advertises — without
* reaching into private state.
*/
export function createCloudAdapterRegistry(accountId?: string | null): CloudAdapterRegistry {
const clients = awsClientsForAccount(accountId)
const ec2Service = createEc2Service(clients.ec2)
return new CloudAdapterRegistry([
new AwsStorageAdapter(clients.s3, clients.lambda, resolveAccountId(accountId)),
new AwsDynamoDbAdapter(clients.dynamodb),
new AwsEksAdapter(createEksService(clients.eks)),
new AwsDatabaseAdapter(createRdsService(clients.rds), clients.rds, clients.rdsData),
new AwsComputeAdapter(ec2Service),
new AwsNetworkingAdapter(ec2Service),
new AwsServerlessAdapter(clients.lambda, clients.eventbridge),
new AwsLogsAdapter(clients.logs),
new AwsParameterStoreAdapter(clients.ssm),
new AwsKmsAdapter(clients.kms),
new AwsStepFunctionsAdapter(clients.sfn),
new AwsLoadBalancingAdapter(clients.elbv2, clients.ec2),
new AwsTargetGroupAdapter(clients.elbv2, clients.ec2),
new AwsEventBridgeAdapter(clients.eventbridge, clients.lambda),
new AwsIamAdapter(clients.iam),
new AwsApiGatewayAdapter(clients.apiGateway, clients.lambda, resolveAccountId(accountId), undefined, clients.apiGatewayV2),
new AwsCloudFormationAdapter(clients.cloudformation),
new AwsSecretsAdapter(clients.secretsManager),
new AwsSesAdapter(),
new AwsAppConfigAdapter(clients.appConfig),
new AwsSnsAdapter(clients.sns),
new AwsEcrAdapter(clients.ecr),
new AwsCodeBuildAdapter(clients.codebuild),
new AwsCodePipelineAdapter(clients.codepipeline),
new AwsCodeDeployAdapter(clients.codedeploy, clients.lambda),
new AwsEcsAdapter(clients.ecs, clients.elbv2),
new AwsFargateAdapter(new AwsEcsAdapter(clients.ecs, clients.elbv2)),
new AwsKinesisAdapter(clients.kinesis),
new AwsElastiCacheAdapter(clients.elasticache),
new AwsLightsailAdapter(clients.lightsail),
new AwsUserPoolsAdapter(clients.cognito),
new AwsDnsAdapter(clients.route53),
new AwsCdnAdapter(clients.cloudfront, clients.s3),
new AwsAutoScalingAdapter(clients.autoscaling, clients.ec2),
new AwsCertificatesAdapter(clients.acm, resolveAccountId(accountId)),
new AwsPipesAdapter(clients.pipes),
new AwsMonitoringAdapter(clients.cloudwatch),
new AzureStorageAdapter(),
new AzureServiceBusAdapter(),
new AzureDatabaseAdapter(),
new AzureAksAdapter(),
new AzureNoSqlAdapter(),
new AzureComputeAdapter(),
new GcpStorageAdapter(),
new GcpCloudFunctionsAdapter(),
new GcpCloudSqlAdapter(),
new GcpGkeAdapter(),
new GcpCloudRunAdapter(),
new GcpPubSubAdapter(),
new GcpSecretManagerAdapter(),
new GcpSchedulerAdapter(),
new AwsSqsAdapter(clients.sqs),
new AzureServerlessAdapter(),
new AzureKeyVaultAdapter(),
])
}
export function createCloudProxyService(accountId?: string | null): CloudProxyService {
return new CloudProxyService(createCloudAdapterRegistry(accountId))
}
const serviceCache = new Map<string, CloudProxyService>()
/** Return a cached account-scoped CloudProxyService, building it on first use. */
export function serviceForAccount(accountId?: string | null): CloudProxyService {
const id = resolveAccountId(accountId)
let service = serviceCache.get(id)
if (!service) {
service = createCloudProxyService(id)
serviceCache.set(id, service)
}
return service
}