@aws-amplify/cli-internal
Version:
Amplify CLI
42 lines • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionAssessor = void 0;
const assessment_1 = require("../assessment");
const gen1_app_1 = require("../../_common/gen1-app");
class FunctionAssessor {
constructor(gen1App, resource) {
this.gen1App = gen1App;
this.resource = resource;
}
record(assessment) {
const templatePath = `function/${this.resource.resourceName}/${this.resource.resourceName}-cloudformation-template.json`;
const template = this.gen1App.json(templatePath);
const runtime = template.Resources.LambdaFunction.Properties.Runtime;
assessment.recordResource({
resource: this.resource,
generate: this.isNonJsRuntime(runtime) ? (0, assessment_1.unsupported)('requires adding code after generate') : (0, assessment_1.supported)(),
refactor: (0, assessment_1.notApplicable)(),
});
const customPoliciesPath = `function/${this.resource.resourceName}/custom-policies.json`;
if (this.hasCustomPolicies(customPoliciesPath)) {
assessment.recordFeature({
feature: { name: gen1_app_1.KNOWN_FEATURES.CUSTOM_FUNCTION_POLICIES, path: customPoliciesPath },
generate: (0, assessment_1.unsupported)('requires adding code after generate'),
refactor: (0, assessment_1.notApplicable)(),
});
}
}
isNonJsRuntime(runtime) {
return !runtime.startsWith('nodejs');
}
hasCustomPolicies(filePath) {
if (!this.gen1App.fileExists(filePath))
return false;
const policies = this.gen1App.json(filePath);
if (!Array.isArray(policies))
return true;
return policies.some((p) => (p.Action && p.Action.length > 0) || (p.Resource && p.Resource.length > 0));
}
}
exports.FunctionAssessor = FunctionAssessor;
//# sourceMappingURL=function.assessor.js.map