Return 404 status code when no license is installed

closes elastic/elasticsearch#2000

Original commit: elastic/x-pack-elasticsearch@3bd4193cf8
This commit is contained in:
Areek Zillur 2016-04-14 16:36:58 -04:00
parent e94942c68c
commit e5c2a44d5d
3 changed files with 27 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestGetLicenseAction extends BaseRestHandler {
@ -58,14 +59,15 @@ public class RestGetLicenseAction extends BaseRestHandler {
if (!request.hasParam("pretty")) {
builder.prettyPrint().lfAtEnd();
}
boolean hasLicense = response.license() != null;
builder.startObject();
if (response.license() != null) {
if (hasLicense) {
builder.startObject("license");
response.license().toInnerXContent(builder, params);
builder.endObject();
}
builder.endObject();
return new BytesRestResponse(OK, builder);
return new BytesRestResponse(hasLicense ? OK : NOT_FOUND, builder);
}
});
}

View File

@ -0,0 +1,12 @@
{
"license.delete": {
"documentation": "https://www.elastic.co/guide/en/shield/current/license-management.html",
"methods": ["DELETE"],
"url": {
"path": "/_license",
"paths": ["/_license"],
"parts" : {}
},
"body": null
}
}

View File

@ -55,3 +55,14 @@
- length: { license: 10 }
- match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" }
---
"Should throw 404 after license deletion":
- do:
license.delete: {}
- match: { acknowledged: true }
- do:
catch: missing
license.get: {}