@atomist/sdm-pack-spring
Version:
Atomist software delivery machine extension pack for Spring and Spring Boot applications
89 lines • 3.9 kB
JavaScript
;
/*
* Copyright © 2019 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const automation_client_1 = require("@atomist/automation-client");
const _ = require("lodash");
const reviewCategories_1 = require("../../common/review/reviewCategories");
const propertiesParser_1 = require("../../properties/propertiesParser");
const pushTests_1 = require("../pushtest/pushTests");
const PropertyKeysToCheck = [
"server.port",
"spring.datasource.url",
"spring.datasource.username",
"spring.datasource.password",
];
exports.HardcodePropertyCategory = "Hardcoded properties";
/**
* Reviewer that finds hard-coded properties
*/
exports.HardcodedPropertyReviewer = {
name: exports.HardcodePropertyCategory,
pushTest: pushTests_1.HasSpringBootApplicationClass,
inspection: (project) => __awaiter(void 0, void 0, void 0, function* () {
return {
repoId: project.id,
comments: yield badPropertiesStrings(project),
};
}),
};
function badPropertiesStrings(p) {
return __awaiter(this, void 0, void 0, function* () {
const arrArr = automation_client_1.projectUtils.gatherFromFiles(p, "src/main/resources/*.properties", f => badPropertiesIn(p, f));
return _.flatten(yield arrArr);
});
}
function badPropertiesIn(p, f) {
return __awaiter(this, void 0, void 0, function* () {
const comments = [];
const parsed = yield propertiesParser_1.parseProperties(p, f.path);
for (const prop of parsed.properties) {
if (PropertyKeysToCheck.includes(prop.key) && !!prop.value) {
if (hardcoded(prop.value)) {
automation_client_1.logger.info("Value of %s: '%s' is hard coded", prop.key, prop.value);
comments.push({
severity: "info",
category: reviewCategories_1.CloudNative,
subcategory: exports.HardcodePropertyCategory,
detail: `Hardcoded property ${prop.key} should be sourced from environment`,
sourceLocation: {
path: f.path,
lineFrom1: 1,
offset: -1,
},
});
}
else {
automation_client_1.logger.info("Value of %s: '%s' is not hard coded", prop.key, prop.value);
}
}
}
return comments;
});
}
function hardcoded(value) {
return !value.includes("${");
}
//# sourceMappingURL=hardcodedPropertyReviewer.js.map