|
@@ -47,7 +47,7 @@ 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 String sgIpsJson = doRequest("ips", HttpMethods.GET, null, parentService); |
|
|
final List<Map<String, Object>> sgIps = json(sgIpsJson, List.class); |
|
|
final List<Map<String, Object>> sgIps = json(sgIpsJson, List.class); |
|
|
if (empty(sgIps)) die("No IPs set for the specified main Sendgrid user"); |
|
|
if (empty(sgIps)) die("No IPs set for the specified main Sendgrid user"); |
|
|
final String sgIp = (String) sgIps.get(0).get("ip"); |
|
|
final String sgIp = (String) sgIps.get(0).get("ip"); |
|
@@ -58,7 +58,7 @@ public class SendgridSmtpEmailDriver extends SmtpEmailDriver { |
|
|
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[]{ sgIp }); |
|
|
new String[]{ sgIp }); |
|
|
doRequest("subusers", HttpMethods.POST, json(data)); |
|
|
|
|
|
|
|
|
doRequest("subusers", HttpMethods.POST, json(data), parentService); |
|
|
|
|
|
|
|
|
final CloudCredentials credentials = delegatedService.getCredentials(); |
|
|
final CloudCredentials credentials = delegatedService.getCredentials(); |
|
|
credentials.setParam(PARAM_USER, user) |
|
|
credentials.setParam(PARAM_USER, user) |
|
@@ -68,32 +68,28 @@ public class SendgridSmtpEmailDriver extends SmtpEmailDriver { |
|
|
return delegatedService; |
|
|
return delegatedService; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override public void postServiceDelete(@NonNull final CloudService service) { |
|
|
|
|
|
// TODO: there must be configuration present here. If this happens, try some other way: |
|
|
|
|
|
if (getConfiguration() == null) { |
|
|
|
|
|
die("postServiceDelete: Cannot do this action with server configuration set within"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void postServiceDelete(@NonNull final CloudServiceDAO serviceDAO, |
|
|
|
|
|
@NonNull final CloudService service) { |
|
|
final String parentServiceUuid = service.getCredentials().getParam(PARAM_PARENT_SERVICE); |
|
|
final String parentServiceUuid = service.getCredentials().getParam(PARAM_PARENT_SERVICE); |
|
|
if (parentServiceUuid == null) return; |
|
|
if (parentServiceUuid == null) return; |
|
|
|
|
|
|
|
|
final CloudService parentService = getConfiguration().getBean(CloudServiceDAO.class) |
|
|
|
|
|
.findByUuid(parentServiceUuid); |
|
|
|
|
|
|
|
|
final CloudService parentService = serviceDAO.findByUuid(parentServiceUuid); |
|
|
if (parentService == null) return; |
|
|
if (parentService == null) return; |
|
|
|
|
|
|
|
|
final String user = service.getCredentials().getParam(PARAM_USER); |
|
|
final String user = service.getCredentials().getParam(PARAM_USER); |
|
|
if (empty(user)) return; |
|
|
if (empty(user)) return; |
|
|
|
|
|
|
|
|
doRequest("subusers/" + user, HttpMethods.DELETE, null); |
|
|
|
|
|
|
|
|
doRequest("subusers/" + user, HttpMethods.DELETE, null, parentService); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String doRequest(@NonNull final String uri, @NonNull final String method, @Nullable final String json) { |
|
|
|
|
|
|
|
|
private String doRequest(@NonNull final String uri, @NonNull final String method, @Nullable final String json, |
|
|
|
|
|
@NonNull CloudService parentService) { |
|
|
final HttpRequestBean request = new HttpRequestBean(); |
|
|
final HttpRequestBean request = new HttpRequestBean(); |
|
|
request.setMethod(method) |
|
|
request.setMethod(method) |
|
|
.setUri(SG_API_BASE + uri) |
|
|
.setUri(SG_API_BASE + uri) |
|
|
.setEntity(json) |
|
|
.setEntity(json) |
|
|
.setHeader(CONTENT_TYPE, APPLICATION_JSON) |
|
|
.setHeader(CONTENT_TYPE, APPLICATION_JSON) |
|
|
.setHeader(AUTHORIZATION, "Bearer " + getCredentials().getParam(PARAM_PASSWORD)); |
|
|
|
|
|
|
|
|
.setHeader(AUTHORIZATION, "Bearer " + parentService.getCredentials().getParam(PARAM_PASSWORD)); |
|
|
|
|
|
|
|
|
final HttpResponseBean response; |
|
|
final HttpResponseBean response; |
|
|
try { |
|
|
try { |
|
|