Skip to content

Commit 544d7e6

Browse files
nitzanjtocker
authored andcommitted
Allow deleteByToken to pass through when there's no api secret in config.
1 parent 9206a89 commit 544d7e6

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

cloudinary-android/src/main/java/com/cloudinary/android/UploaderStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
2525
}
2626
boolean returnError = ObjectUtils.asBoolean(options.get("return_error"), false);
2727

28-
if (Boolean.TRUE.equals(options.get("unsigned"))) {
29-
// Nothing to do
30-
} else {
28+
if (requiresSigning(action, options)) {
3129
String apiKey = ObjectUtils.asString(options.get("api_key"), this.cloudinary().config.apiKey);
3230
if (apiKey == null)
3331
throw new IllegalArgumentException("Must supply api_key");
@@ -43,6 +41,8 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
4341
params.put("signature", this.cloudinary().apiSignRequest(params, apiSecret));
4442
params.put("api_key", apiKey);
4543
}
44+
} else {
45+
// Nothing to do
4646
}
4747

4848
String apiUrl = buildUploadUrl(action, options);

cloudinary-core/src/main/java/com/cloudinary/strategies/AbstractUploaderStrategy.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ protected String buildUploadUrl(String action, Map options) {
4242
return StringUtils.join(new String[]{cloudinary, "v1_1", cloud_name, resource_type, action}, "/");
4343
}
4444
}
45+
46+
protected boolean requiresSigning(String action, Map options) {
47+
boolean unsigned = Boolean.TRUE.equals(options.get("unsigned"));
48+
boolean deleteByToken = "delete_by_token".equals(action);
49+
50+
return !unsigned && !deleteByToken;
51+
}
4552
}

cloudinary-http42/src/main/java/com/cloudinary/http42/UploaderStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
4444

4545
boolean returnError = ObjectUtils.asBoolean(options.get("return_error"), false);
4646

47-
if (options.get("unsigned") == null || Boolean.FALSE.equals(options.get("unsigned"))) {
47+
if (requiresSigning(action, options)) {
4848
uploader.signRequestParams(params, options);
4949
} else {
5050
Util.clearEmpty(params);

cloudinary-http43/src/main/java/com/cloudinary/http43/UploaderStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
6767

6868
boolean returnError = ObjectUtils.asBoolean(options.get("return_error"), false);
6969

70-
if (options.get("unsigned") == null || Boolean.FALSE.equals(options.get("unsigned"))) {
70+
if (requiresSigning(action, options)) {
7171
uploader.signRequestParams(params, options);
7272
} else {
7373
Util.clearEmpty(params);

cloudinary-http44/src/main/java/com/cloudinary/http44/UploaderStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
6767

6868
boolean returnError = ObjectUtils.asBoolean(options.get("return_error"), false);
6969

70-
if (options.get("unsigned") == null || Boolean.FALSE.equals(options.get("unsigned"))) {
70+
if (requiresSigning(action, options)) {
7171
uploader.signRequestParams(params, options);
7272
} else {
7373
Util.clearEmpty(params);

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void testDeleteByToken() throws Exception {
8888
Map options = ObjectUtils.asMap("return_delete_token", true, "tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG});
8989
Map res = cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
9090
String token = (String) res.get("delete_token");
91-
res = cloudinary.uploader().deleteByToken(token);
91+
res = new Cloudinary(ObjectUtils.asMap("cloud_name", cloudinary.config.cloudName)).uploader().deleteByToken(token);
9292
assertNotNull(res);
9393
assertEquals("ok", res.get("result"));
9494
}

0 commit comments

Comments
 (0)