Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include invalid values for env name checks. #154 #155

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public void execute(final AnalyserTaskContext context) throws Exception {
* Enumeration for the violations
*/
private enum Usage {
ENV("Value for property '{}' must not use env vars prefixed with INTERNAL_ or ADOBE_"),
ENV_PATTERN("Value for property '{}' uses env var not following the required naming scheme of " + NAME_PATTERN.toString()),
ENV_SIZE("Value for property '{}' uses env var not following naming length restrictions (>= 2 and <= 100)"),
SECRET("Value for property '{}' must not use secrets prefixed with INTERNAL_ or ADOBE_"),
SECRET_PATH("Value for property '{}' must not use prefix " + SECRETS_PATH + ". Please remove the prefix", false),
SECRET_PATTERN("Value for property '{}' uses env var not following the required naming scheme of " + NAME_PATTERN.toString()),
SECRET_SIZE("Value for property '{}' uses env var not following naming length restrictions (>= 2 and <= 100)");
ENV("Value for property '{}' must not use env vars prefixed with INTERNAL_ or ADOBE_ : "),
ENV_PATTERN("Value for property '{}' uses env var not following the required naming scheme of " + NAME_PATTERN.toString() + " : "),
ENV_SIZE("Value for property '{}' uses env var not following naming length restrictions (>= 2 and <= 100) : "),
SECRET("Value for property '{}' must not use secrets prefixed with INTERNAL_ or ADOBE_ : "),
SECRET_PATH("Value for property '{}' must not use prefix " + SECRETS_PATH + ". Please remove the prefix : ", false),
SECRET_PATTERN("Value for property '{}' uses env var not following the required naming scheme of " + NAME_PATTERN.toString() + " : "),
SECRET_SIZE("Value for property '{}' uses env var not following naming length restrictions (>= 2 and <= 100) : ");

private final String message;

Expand All @@ -94,8 +94,27 @@ public boolean isError() {
* @param propertyName The property name
* @return The message
*/
public String getMessageFor(final String propertyName) {
return message.replace("{}", propertyName);
public String getMessageFor(final String propertyName, final String value) {
return message.replace("{}", propertyName).concat(value);
}
}

/**
* Print the usage warnings and errors
* @param usage The usage set
* @param context The context
* @param cfg The configureation
* @param propName The property name
* @param value The property value
*/
private void reportErrorOrWarning(final EnumSet<Usage> usage,
final AnalyserTaskContext context, final Configuration cfg, final String propName, final String value) {
for(final Usage u : usage) {
if ( u.isError() ) {
context.reportConfigurationError(cfg, u.getMessageFor(propName, value));
} else {
context.reportConfigurationWarning(cfg, u.getMessageFor(propName, value));
}
}
}

Expand All @@ -108,21 +127,12 @@ private void check(final AnalyserTaskContext context, final Configuration cfg) {
final Dictionary<String, Object> properties = cfg.getConfigurationProperties();
for(final String propName : Collections.list(properties.keys())) {
final Object value = properties.get(propName);
EnumSet<Usage> usage = EnumSet.noneOf(Usage.class);
if (value instanceof String) {
usage = checkValue(value.toString());
reportErrorOrWarning(checkValue(value.toString()), context, cfg, propName, value.toString());
} else if (value instanceof String[]) {
final String[] array = (String[]) value;
for(final String val : array) {
usage.addAll(checkValue(val));
}
}

for(final Usage u : usage) {
if ( u.isError() ) {
context.reportConfigurationError(cfg, u.getMessageFor(propName));
} else {
context.reportConfigurationWarning(cfg, u.getMessageFor(propName));
reportErrorOrWarning(checkValue(val), context, cfg, propName, val);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion aemanalyser-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ governing permissions and limitations under the License.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>aemanalyser-core</artifactId>
<version>1.1.14</version>
<version>1.1.15-SNAPSHOT</version>
</dependency>

<!-- Feature Model -->
Expand Down