@cloud-copilot/iam-data
Version:
83 lines • 3.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.serviceCategories = serviceCategories;
exports.serviceCategoryExists = serviceCategoryExists;
exports.iamServiceCategoryMap = iamServiceCategoryMap;
exports.iamServicesForCategory = iamServicesForCategory;
exports.categoryForIamService = categoryForIamService;
exports.getServiceCategory = getServiceCategory;
const data_js_1 = require("./data.js");
const services_js_1 = require("./services.js");
/**
* Get all service category keys.
*
* @returns an array of all service category keys
*/
async function serviceCategories() {
return (0, data_js_1.readDataFile)('categories.json');
}
/**
* Check if a service category exists.
*
* @param category the category key to check, is case insensitive
* @returns true if the category exists, false otherwise
*/
async function serviceCategoryExists(category) {
const categoryNames = await (0, data_js_1.readDataFile)('categoryNames.json');
return !!categoryNames[category.toLowerCase()];
}
/**
* Get the IAM service to category mapping.
*
* @returns a map of IAM service keys to category keys
*/
async function iamServiceCategoryMap() {
return (0, data_js_1.readDataFile)('serviceCategories.json');
}
/**
* Get IAM service keys assigned to a service category.
*
* @param category the category key to get IAM services for, is case insensitive
* @throws an error if the category does not exist
* @returns sorted IAM service keys assigned to the category
*/
async function iamServicesForCategory(category) {
const categoryDetails = await getServiceCategory(category);
return categoryDetails.services;
}
/**
* Get the service category key for an IAM service.
*
* @param service the IAM service key to get the category for, is case insensitive
* @throws an error if the service does not exist or has no category mapping
* @returns the category key for the IAM service
*/
async function categoryForIamService(service) {
const serviceKey = service.toLowerCase();
const serviceExists = await (0, services_js_1.iamServiceExists)(serviceKey);
if (!serviceExists) {
throw new Error(`Service ${service} does not exist`);
}
const serviceCategories = await iamServiceCategoryMap();
const category = serviceCategories[serviceKey];
if (!category) {
throw new Error(`Category for service ${service} does not exist`);
}
return category;
}
/**
* Get details for a service category.
*
* @param category the category key to get details for, is case insensitive
* @throws an error if the category does not exist
* @returns details for the service category
*/
async function getServiceCategory(category) {
const categoryKey = category.toLowerCase();
const exists = await serviceCategoryExists(categoryKey);
if (!exists) {
throw new Error(`Category ${category} does not exist`);
}
return (0, data_js_1.readCategoryDetails)(categoryKey);
}
//# sourceMappingURL=categories.js.map