export function findCfnTypeAssets()

in packages/aws-arch/src/internal/mapping/helpers.ts [43:88]


export function findCfnTypeAssets(
  cfnType: CfnSpec.ResourceType
): CfnTypeAssets {
  const cfn = parseCfnType(cfnType);

  let serviceName: AwsAsset.Service | undefined;
  let resourceName: AwsAsset.Resource | undefined;

  // handle edge cases (eg: EC2::VPCxxx is vpc:xxx in assets)
  if (cfn.serviceName === "EC2") {
    if (cfn.resourceName.startsWith("VPC")) {
      serviceName = "vpc";
      cfn.resourceName = cfn.resourceName.replace(/^VPC/, "");
    } else if (
      normalizeComparisonString(cfn.resourceName) in VpcAssetComparables
    ) {
      serviceName = "vpc";
      cfn.resourceName = normalizeComparisonString(cfn.resourceName);
    }
  }

  if (serviceName == null) {
    try {
      serviceName = resolveServiceName(cfn.serviceName);
    } catch (e) {
      console.warn((e as Error).message, cfnType);
    }
  }

  if (resourceName == null) {
    // There are lots of low-level cfn resource definitions without mappings to other systems,
    // for this reason we just ignore unresolved resources without spamming the console or
    // bubbling the error as this is expected in large percent of cases.
    try {
      resourceName = resolveResourceName(cfn.resourceName, serviceName);
    } catch {}
  }

  const generalIcon = resolveGeneralIcon(cfn.resourceName);

  return {
    serviceName,
    resourceName,
    generalIcon,
  };
}