|
|
@@ -13,12 +13,15 @@ import org.cobbzilla.util.http.HttpResponseBean; |
|
|
|
|
|
|
|
import javax.annotation.Nullable; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static bubble.cloud.storage.StorageCryptStream.MIN_DISTINCT_LENGTH; |
|
|
|
import static bubble.cloud.storage.StorageCryptStream.MIN_KEY_LENGTH; |
|
|
|
import static org.apache.http.HttpHeaders.AUTHORIZATION; |
|
|
|
import static org.apache.http.HttpHeaders.CONTENT_TYPE; |
|
|
|
import static org.cobbzilla.util.daemon.ZillaRuntime.die; |
|
|
|
import static org.cobbzilla.util.daemon.ZillaRuntime.empty; |
|
|
|
import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON; |
|
|
|
import static org.cobbzilla.util.http.HttpUtil.getResponse; |
|
|
|
import static org.cobbzilla.util.json.JsonUtil.json; |
|
|
@@ -52,12 +55,17 @@ public class SendgridSmtpEmailDriver extends SmtpEmailDriver { |
|
|
|
return super.setupDelegatedCloudService(configuration, parentService, delegatedService); |
|
|
|
} |
|
|
|
|
|
|
|
final String sgIpsJson = doRequest("ips", HttpMethods.GET, null); |
|
|
|
final List<Map<String, Object>> sgIps = json(sgIpsJson, List.class); |
|
|
|
if (empty(sgIps)) die("No IPs set for the specified main Sendgrid user"); |
|
|
|
final String sgIp = (String) sgIps.get(0).get("ip"); |
|
|
|
|
|
|
|
final Account accountWithDelegate = configuration.getBean(AccountDAO.class) |
|
|
|
.findByUuid(delegatedService.getAccount()); |
|
|
|
final String user = sgUsername(delegatedService); |
|
|
|
String password = generatePassword(MIN_KEY_LENGTH, MIN_DISTINCT_LENGTH); |
|
|
|
final CreateSubuserRequest data = new CreateSubuserRequest(user, accountWithDelegate.getEmail(), password, |
|
|
|
new String[]{}); |
|
|
|
new String[]{ sgIp }); |
|
|
|
doRequest("subusers", HttpMethods.POST, json(data)); |
|
|
|
|
|
|
|
delegatedService.setDelegated(null).setTemplate(false); |
|
|
|