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

Slack app improvements #18684

Merged
merged 1 commit into from
Nov 19, 2024
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 @@ -4,8 +4,6 @@
import static org.openmetadata.schema.type.EventType.ENTITY_DELETED;
import static org.openmetadata.schema.type.EventType.ENTITY_UPDATED;

import com.slack.api.bolt.model.builtin.DefaultBot;
import com.slack.api.bolt.model.builtin.DefaultInstaller;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -222,12 +220,10 @@ public void updateSetting(Settings setting) {
JsonUtils.convertValue(setting.getConfigValue(), SlackAppConfiguration.class);
setting.setConfigValue(encryptSlackAppSetting(appConfiguration));
} else if (setting.getConfigType() == SettingsType.SLACK_BOT) {
DefaultBot appConfiguration =
JsonUtils.convertValue(setting.getConfigValue(), DefaultBot.class);
String appConfiguration = JsonUtils.convertValue(setting.getConfigValue(), String.class);
setting.setConfigValue(encryptSlackDefaultBotSetting(appConfiguration));
} else if (setting.getConfigType() == SettingsType.SLACK_INSTALLER) {
DefaultInstaller appConfiguration =
JsonUtils.convertValue(setting.getConfigValue(), DefaultInstaller.class);
String appConfiguration = JsonUtils.convertValue(setting.getConfigValue(), String.class);
setting.setConfigValue(encryptSlackDefaultInstallerSetting(appConfiguration));
} else if (setting.getConfigType() == SettingsType.SLACK_STATE) {
String slackState = JsonUtils.convertValue(setting.getConfigValue(), String.class);
Expand All @@ -251,7 +247,7 @@ public void updateSetting(Settings setting) {
public Settings getSlackbotConfigInternal() {
try {
Settings setting = dao.getConfigWithKey(SettingsType.SLACK_BOT.value());
DefaultBot slackBotConfiguration =
String slackBotConfiguration =
SystemRepository.decryptSlackDefaultBotSetting((String) setting.getConfigValue());
setting.setConfigValue(slackBotConfiguration);
return setting;
Expand All @@ -264,7 +260,7 @@ public Settings getSlackbotConfigInternal() {
public Settings getSlackInstallerConfigInternal() {
try {
Settings setting = dao.getConfigWithKey(SettingsType.SLACK_INSTALLER.value());
DefaultInstaller slackInstallerConfiguration =
String slackInstallerConfiguration =
SystemRepository.decryptSlackDefaultInstallerSetting((String) setting.getConfigValue());
setting.setConfigValue(slackInstallerConfiguration);
return setting;
Expand All @@ -288,7 +284,7 @@ public Settings getSlackStateConfigInternal() {
}

@SneakyThrows
public static String encryptSlackDefaultBotSetting(DefaultBot decryptedSetting) {
public static String encryptSlackDefaultBotSetting(String decryptedSetting) {
String json = JsonUtils.pojoToJson(decryptedSetting);
if (Fernet.getInstance().isKeyDefined()) {
return Fernet.getInstance().encryptIfApplies(json);
Expand All @@ -297,15 +293,15 @@ public static String encryptSlackDefaultBotSetting(DefaultBot decryptedSetting)
}

@SneakyThrows
public static DefaultBot decryptSlackDefaultBotSetting(String encryptedSetting) {
public static String decryptSlackDefaultBotSetting(String encryptedSetting) {
if (Fernet.getInstance().isKeyDefined()) {
encryptedSetting = Fernet.getInstance().decryptIfApplies(encryptedSetting);
}
return JsonUtils.readValue(encryptedSetting, DefaultBot.class);
return JsonUtils.readValue(encryptedSetting, String.class);
}

@SneakyThrows
public static String encryptSlackDefaultInstallerSetting(DefaultInstaller decryptedSetting) {
public static String encryptSlackDefaultInstallerSetting(String decryptedSetting) {
String json = JsonUtils.pojoToJson(decryptedSetting);
if (Fernet.getInstance().isKeyDefined()) {
return Fernet.getInstance().encryptIfApplies(json);
Expand All @@ -314,11 +310,11 @@ public static String encryptSlackDefaultInstallerSetting(DefaultInstaller decryp
}

@SneakyThrows
public static DefaultInstaller decryptSlackDefaultInstallerSetting(String encryptedSetting) {
public static String decryptSlackDefaultInstallerSetting(String encryptedSetting) {
if (Fernet.getInstance().isKeyDefined()) {
encryptedSetting = Fernet.getInstance().decryptIfApplies(encryptedSetting);
}
return JsonUtils.readValue(encryptedSetting, DefaultInstaller.class);
return JsonUtils.readValue(encryptedSetting, String.class);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
{
"$ref": "internal/searchIndexingAppConfig.json"
},
{
"$ref": "external/slackAppTokenConfiguration.json"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$id": "https://open-metadata.org/schema/entity/applications/configuration/slackAppTokenConfiguration.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "SlackAppTokenConfiguration",
"description": "This schema defines the Slack App Token Configuration",
"type": "object",
"javaType": "org.openmetadata.schema.entity.applications.configuration.SlackAppTokenConfiguration",
"properties": {
"userToken": {
"title": "User Token",
"description": "User Token",
"type": "string"
},
"botToken": {
"title": "Bot Token",
"description": "Bot Token",
"type": "string"
}
},
"additionalProperties": false,
"required": [
"userToken",
"botToken"
]
}
Loading