firebase-tools
Version:
Command-Line Interface for Firebase
31 lines (30 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getServiceSpec = getServiceSpec;
const clc = require("colorette");
const error_1 = require("../../error");
const run = require("../../gcp/run");
const runv2 = require("../../gcp/runv2");
const util_1 = require("./util");
async function getServiceSpec(projectId, serviceId, region) {
let matches = (await runv2.listServices(projectId, false)).filter((s) => {
const name = (0, util_1.parseServiceName)(s.name);
return name.serviceId === serviceId && (!region || name.region === region);
});
if (matches.length > 1) {
const unmanaged = matches.filter((s) => !(0, util_1.isManagedByAnotherProduct)(s));
if (unmanaged.length) {
matches = unmanaged;
}
}
if (!matches.length) {
throw new error_1.FirebaseError(`Cloud Run service ${serviceId} doesn't exist in ${region ?? `project ${projectId}`}. ` +
`See your services with ${clc.bold("firebase run:services:list")}.`);
}
if (matches.length > 1) {
const regions = matches.map((s) => (0, util_1.parseServiceName)(s.name).region);
throw new error_1.FirebaseError(`Cloud Run service ${serviceId} exists in more than one region: ${regions.join(", ")}. ` +
`Choose one with --region.`);
}
return run.getService(matches[0].name);
}