Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Remove a possible NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Czernek committed Jun 17, 2020
1 parent 44c9f71 commit ebe9450
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/redhat/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ public class Constants {
public static final String CREDENTIALS_PATH_ENV_PROPERTY = "GOOGLE_APPLICATION_CREDENTIALS";
public static final String PROJECT_ID = System.getenv("PROJECT_ID");
public static final String SUBSCRIPTION_ID = System.getenv("SUBSCRIPTION_ID");
public static final String SUDO_PASSWORD = System.getenv("SUDO_PASSWORD");
public static final String HANGOUTS_CHAT_API_SCOPE = "https://www.googleapis.com/auth/chat.bot";
public static final String YAML_SOURCE = "AcroBot/data/abbrev.yaml"; // ClassLoader path

// Response templates
public static final String RESPONSE_URL_TEMPLATE = "https://chat.googleapis.com/v1/__SPACE_ID__/messages";
public static final String ADDED_RESPONSE = "Thank you for adding me! Send `@Acrobot help` for more information about me.";
Expand Down Expand Up @@ -37,4 +35,13 @@ public class Constants {

public static final String FOUND_YAML_TEXT = "\n\n_Found requested acronym in the IRC database. " +
"Send @Acrobot help for more information about this feature._\n";

// we should not return null for sudo password
private static final String SUDO_PASSWORD = System.getenv("SUDO_PASSWORD");
public static String getSudoPassword(String defaultValue) {
if(SUDO_PASSWORD == null) {
return defaultValue;
}
return SUDO_PASSWORD;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/redhat/messages/MessageTypeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static MessageType determineMessageAction(JsonNode eventJson) {

String message = msgNode.asText();

if(message.startsWith(Constants.SUDO_PASSWORD)) {
if(message.startsWith(Constants.getSudoPassword("PW does not exist"))) {
return MessageType.SUDO_RESPONSE;
}

Expand Down

0 comments on commit ebe9450

Please sign in to comment.