|
|
@@ -17,61 +17,62 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import static bubble.model.cloud.notify.NotificationType.sync_password; |
|
|
|
import static bubble.model.cloud.notify.NotificationType.sync_account; |
|
|
|
import static org.cobbzilla.wizard.server.RestServerBase.reportError; |
|
|
|
|
|
|
|
@Service @Slf4j |
|
|
|
public class StandardSyncPasswordService implements SyncPasswordService { |
|
|
|
public class StandardSyncAccountService implements SyncAccountService { |
|
|
|
|
|
|
|
@Autowired private BubbleNetworkDAO networkDAO; |
|
|
|
@Autowired private BubbleNodeDAO nodeDAO; |
|
|
|
@Autowired private NotificationService notificationService; |
|
|
|
@Autowired private BubbleConfiguration configuration; |
|
|
|
|
|
|
|
public void syncPassword(Account account) { |
|
|
|
public void syncAccount(Account account) { |
|
|
|
final BubbleNetwork thisNetwork = configuration.getThisNetwork(); |
|
|
|
if (thisNetwork == null) { |
|
|
|
// should never happen |
|
|
|
log.warn("syncPassword: thisNetwork was null, sync_password is impossible"); |
|
|
|
log.warn("syncAccount: thisNetwork was null, sync_account is impossible"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!account.admin()) { |
|
|
|
log.info("syncPassword: not syncing non-admin password"); |
|
|
|
log.info("syncAccount: not syncing non-admin password"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!account.syncPassword()) { |
|
|
|
log.info("syncPassword: password sync disabled for account: "+account.getName()); |
|
|
|
if (!account.sync()) { |
|
|
|
log.info("syncAccount: password sync disabled for account: "+account.getName()); |
|
|
|
return; |
|
|
|
} |
|
|
|
final AnsibleInstallType installType = thisNetwork.getInstallType(); |
|
|
|
final SyncPasswordNotification notification = new SyncPasswordNotification(account); |
|
|
|
final SyncAccountNotification notification = new SyncAccountNotification(account); |
|
|
|
if (installType == AnsibleInstallType.sage) { |
|
|
|
// changing password on sage, notify all bubbles launched by user that have syncPassword == true |
|
|
|
// changing password on sage, notify all bubbles launched by user that have syncAccount == true |
|
|
|
|
|
|
|
for (BubbleNetwork network : networkDAO.findByAccount(account.getUuid())) { |
|
|
|
if (network.getState() != BubbleNetworkState.running) continue; |
|
|
|
if (!network.syncPassword()) continue; |
|
|
|
if (!network.syncAccount()) continue; |
|
|
|
for (BubbleNode node : nodeDAO.findByNetwork(network.getUuid())) { |
|
|
|
if (node.getUuid().equals(configuration.getThisNode().getUuid())) { |
|
|
|
log.info("syncPassword: not notifying self"); |
|
|
|
log.info("syncAccount: not notifying self"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
log.info("syncPassword: sending sync_password notification from sage to node: "+node.id()); |
|
|
|
notificationService.notify(node, sync_password, notification); |
|
|
|
log.info("syncAccount: sending sync_account notification from sage to node: "+node.id()); |
|
|
|
notificationService.notify(node, sync_account, notification); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (installType == AnsibleInstallType.node) { |
|
|
|
if (!thisNetwork.syncPassword()) { |
|
|
|
log.info("syncPassword: disabled for node, not sending sync_password notification"); |
|
|
|
if (!thisNetwork.syncAccount()) { |
|
|
|
log.info("syncAccount: disabled for node, not sending sync_account notification"); |
|
|
|
return; |
|
|
|
} |
|
|
|
// changing password on node, notify sage, which will then notify all bubbles launched by user that have syncPassword == true |
|
|
|
log.info("syncPassword: sending sync_password notification from node to sage: "+configuration.getSageNode()); |
|
|
|
notificationService.notify(configuration.getSageNode(), sync_password, notification); |
|
|
|
// changing password on node, notify sage, which will then notify all bubbles launched by user that have |
|
|
|
// syncAccount == true |
|
|
|
log.info("syncAccount: sending sync_account notification from node to sage: "+configuration.getSageNode()); |
|
|
|
notificationService.notify(configuration.getSageNode(), sync_account, notification); |
|
|
|
|
|
|
|
} else { |
|
|
|
reportError("syncPassword("+account.getEmail()+"/"+account.getUuid()+"): invalid installType: "+installType); |
|
|
|
reportError("syncAccount("+account.getEmail()+"/"+account.getUuid()+"): invalid installType: "+installType); |
|
|
|
} |
|
|
|
} |
|
|
|
|