Skip to content

Commit

Permalink
fixed slack api secret leak
Browse files Browse the repository at this point in the history
  • Loading branch information
talhayaseen57 committed Mar 17, 2024
1 parent 1a75efe commit d47427f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ build/

### VS Code ###
.vscode/
/.cache_ggshield
/src/main/java/com/sherenterprise/coursereport/service/SlackSecrets.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import java.net.HttpURLConnection;
import java.net.URL;

import static com.sherenterprise.coursereport.service.SlackSecrets.CHANNEL_ID;
import static com.sherenterprise.coursereport.service.SlackSecrets.SLACK_TOKEN;

public class SlackBot {

private static final String TOKEN = "xoxb-6827094040193-6811539192533-TKdZIJGe7AAjpCiD7v8kwPmT";
private static final String CHANNEL_ID = "C06QB2UKQSV";
private static final String SLACK_API_URL = "https://slack.com/api/chat.postMessage";

public static void postMessage(String message) {
Expand All @@ -17,7 +18,7 @@ public static void postMessage(String message) {

connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", "Bearer " + TOKEN);
connection.setRequestProperty("Authorization", "Bearer " + SLACK_TOKEN);
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
System.out.println("About to post this message to slack: " + message);
String jsonPayload = "{\"channel\":\"" + CHANNEL_ID + "\",\"text\":\"" + message + "\"}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SlackBotTest {

@Test
public void slack_post_message_test () {
SlackBot.postMessage("Test message 1");
SlackBot.postMessage("Test message 2");
}

}

0 comments on commit d47427f

Please sign in to comment.