Browse Source

Add Sendgrid IP to create Subuser request

pull/61/head
Kristijan Mitrovic 4 years ago
parent
commit
12ef1ecbc5
1 changed files with 9 additions and 1 deletions
  1. +9
    -1
      bubble-server/src/main/java/bubble/cloud/email/SendgridSmtpEmailDriver.java

+ 9
- 1
bubble-server/src/main/java/bubble/cloud/email/SendgridSmtpEmailDriver.java View File

@@ -13,12 +13,15 @@ import org.cobbzilla.util.http.HttpResponseBean;


import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.IOException; 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_DISTINCT_LENGTH;
import static bubble.cloud.storage.StorageCryptStream.MIN_KEY_LENGTH; import static bubble.cloud.storage.StorageCryptStream.MIN_KEY_LENGTH;
import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.apache.http.HttpHeaders.AUTHORIZATION;
import static org.apache.http.HttpHeaders.CONTENT_TYPE; import static org.apache.http.HttpHeaders.CONTENT_TYPE;
import static org.cobbzilla.util.daemon.ZillaRuntime.die; 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.HttpContentTypes.APPLICATION_JSON;
import static org.cobbzilla.util.http.HttpUtil.getResponse; import static org.cobbzilla.util.http.HttpUtil.getResponse;
import static org.cobbzilla.util.json.JsonUtil.json; import static org.cobbzilla.util.json.JsonUtil.json;
@@ -52,12 +55,17 @@ public class SendgridSmtpEmailDriver extends SmtpEmailDriver {
return super.setupDelegatedCloudService(configuration, parentService, delegatedService); 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) final Account accountWithDelegate = configuration.getBean(AccountDAO.class)
.findByUuid(delegatedService.getAccount()); .findByUuid(delegatedService.getAccount());
final String user = sgUsername(delegatedService); final String user = sgUsername(delegatedService);
String password = generatePassword(MIN_KEY_LENGTH, MIN_DISTINCT_LENGTH); String password = generatePassword(MIN_KEY_LENGTH, MIN_DISTINCT_LENGTH);
final CreateSubuserRequest data = new CreateSubuserRequest(user, accountWithDelegate.getEmail(), password, final CreateSubuserRequest data = new CreateSubuserRequest(user, accountWithDelegate.getEmail(), password,
new String[]{});
new String[]{ sgIp });
doRequest("subusers", HttpMethods.POST, json(data)); doRequest("subusers", HttpMethods.POST, json(data));


delegatedService.setDelegated(null).setTemplate(false); delegatedService.setDelegated(null).setTemplate(false);


Loading…
Cancel
Save