Skip to content

Commit

Permalink
Add url check for matrix url
Browse files Browse the repository at this point in the history
  • Loading branch information
shayaantx committed May 30, 2024
1 parent 36fba7a commit dc9c5db
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/java/com/botdarr/clients/matrix/MatrixBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.botdarr.scheduling.Scheduler;
import org.apache.logging.log4j.util.Strings;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;

public class MatrixBootstrap extends ChatClientBootstrap {
Expand All @@ -28,13 +30,28 @@ public void init() throws Exception {
chatClient.listen();
}

private boolean isValidURL(String urlString) {
try {
new URL(urlString);
return true;
} catch (MalformedURLException e) {
return false;
}
}

@Override
public boolean isConfigured(Properties properties) {
return
final boolean isConfigured =
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_USERNAME)) &&
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_PASSWORD)) &&
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_ROOM)) &&
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_HOME_SERVER));
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_PASSWORD)) &&
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_ROOM)) &&
!Strings.isBlank(properties.getProperty(Config.Constants.MATRIX_HOME_SERVER));

if (isConfigured && !isValidURL(properties.getProperty(Config.Constants.MATRIX_HOME_SERVER))) {
throw new RuntimeException("Matrix home server must be a url");
}

return isConfigured;
}

@Override
Expand Down

0 comments on commit dc9c5db

Please sign in to comment.