Skip to content

Commit

Permalink
This commit is part of our plan to deprecate and ultimately remove th…
Browse files Browse the repository at this point in the history
…e use of _xpack in the REST APIs.

- REST api docs
- HLRC docs and doc tests
- Handle REST actions with deprecation warnings
- Changed endpoints in rest-api-spec and relevant file names

Relates elastic#35958
  • Loading branch information
jkakavas committed Dec 6, 2018
1 parent 068c856 commit 8fba077
Show file tree
Hide file tree
Showing 153 changed files with 880 additions and 625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private SecurityRequestConverters() {}

static Request changePassword(ChangePasswordRequest changePasswordRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/user")
.addPathPartAsIs("_security/user")
.addPathPart(changePasswordRequest.getUsername())
.addPathPartAsIs("_password")
.build();
Expand All @@ -67,7 +67,7 @@ static Request changePassword(ChangePasswordRequest changePasswordRequest) throw

static Request putUser(PutUserRequest putUserRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/user")
.addPathPartAsIs("_security/user")
.addPathPart(putUserRequest.getUser().getUsername())
.build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
Expand All @@ -79,7 +79,7 @@ static Request putUser(PutUserRequest putUserRequest) throws IOException {

static Request deleteUser(DeleteUserRequest deleteUserRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack","security", "user")
.addPathPartAsIs("_security", "user")
.addPathPart(deleteUserRequest.getName())
.build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
Expand All @@ -90,7 +90,7 @@ static Request deleteUser(DeleteUserRequest deleteUserRequest) {

static Request putRoleMapping(final PutRoleMappingRequest putRoleMappingRequest) throws IOException {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/role_mapping")
.addPathPartAsIs("_security/role_mapping")
.addPathPart(putRoleMappingRequest.getName())
.build();
final Request request = new Request(HttpPut.METHOD_NAME, endpoint);
Expand All @@ -102,7 +102,7 @@ static Request putRoleMapping(final PutRoleMappingRequest putRoleMappingRequest)

static Request getRoleMappings(final GetRoleMappingsRequest getRoleMappingRequest) throws IOException {
RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder();
builder.addPathPartAsIs("_xpack/security/role_mapping");
builder.addPathPartAsIs("_security/role_mapping");
if (getRoleMappingRequest.getRoleMappingNames().size() > 0) {
builder.addPathPart(Strings.collectionToCommaDelimitedString(getRoleMappingRequest.getRoleMappingNames()));
}
Expand All @@ -119,7 +119,7 @@ static Request disableUser(DisableUserRequest disableUserRequest) {

private static Request setUserEnabled(SetUserEnabledRequest setUserEnabledRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/user")
.addPathPartAsIs("_security/user")
.addPathPart(setUserEnabledRequest.getUsername())
.addPathPart(setUserEnabledRequest.isEnabled() ? "_enable" : "_disable")
.build();
Expand All @@ -130,14 +130,14 @@ private static Request setUserEnabled(SetUserEnabledRequest setUserEnabledReques
}

static Request hasPrivileges(HasPrivilegesRequest hasPrivilegesRequest) throws IOException {
Request request = new Request(HttpGet.METHOD_NAME, "/_xpack/security/user/_has_privileges");
Request request = new Request(HttpGet.METHOD_NAME, "_security/user/_has_privileges");
request.setEntity(createEntity(hasPrivilegesRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request clearRealmCache(ClearRealmCacheRequest clearRealmCacheRequest) {
RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/realm");
.addPathPartAsIs("_security/realm");
if (clearRealmCacheRequest.getRealms().isEmpty() == false) {
builder.addCommaSeparatedPathParts(clearRealmCacheRequest.getRealms().toArray(Strings.EMPTY_ARRAY));
} else {
Expand All @@ -154,7 +154,7 @@ static Request clearRealmCache(ClearRealmCacheRequest clearRealmCacheRequest) {

static Request clearRolesCache(ClearRolesCacheRequest disableCacheRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/role")
.addPathPartAsIs("_security/role")
.addCommaSeparatedPathParts(disableCacheRequest.names())
.addPathPart("_clear_cache")
.build();
Expand All @@ -163,7 +163,7 @@ static Request clearRolesCache(ClearRolesCacheRequest disableCacheRequest) {

static Request deleteRoleMapping(DeleteRoleMappingRequest deleteRoleMappingRequest) {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/role_mapping")
.addPathPartAsIs("_security/role_mapping")
.addPathPart(deleteRoleMappingRequest.getName())
.build();
final Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
Expand All @@ -174,7 +174,7 @@ static Request deleteRoleMapping(DeleteRoleMappingRequest deleteRoleMappingReque

static Request deleteRole(DeleteRoleRequest deleteRoleRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/role")
.addPathPartAsIs("_security/role")
.addPathPart(deleteRoleRequest.getName())
.build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
Expand All @@ -185,28 +185,28 @@ static Request deleteRole(DeleteRoleRequest deleteRoleRequest) {

static Request getRoles(GetRolesRequest getRolesRequest) {
RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder();
builder.addPathPartAsIs("_xpack/security/role");
builder.addPathPartAsIs("_security/role");
if (getRolesRequest.getRoleNames().size() > 0) {
builder.addPathPart(Strings.collectionToCommaDelimitedString(getRolesRequest.getRoleNames()));
}
return new Request(HttpGet.METHOD_NAME, builder.build());
}

static Request createToken(CreateTokenRequest createTokenRequest) throws IOException {
Request request = new Request(HttpPost.METHOD_NAME, "/_xpack/security/oauth2/token");
Request request = new Request(HttpPost.METHOD_NAME, "_security/oauth2/token");
request.setEntity(createEntity(createTokenRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request invalidateToken(InvalidateTokenRequest invalidateTokenRequest) throws IOException {
Request request = new Request(HttpDelete.METHOD_NAME, "/_xpack/security/oauth2/token");
Request request = new Request(HttpDelete.METHOD_NAME, "_security/oauth2/token");
request.setEntity(createEntity(invalidateTokenRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request getPrivileges(GetPrivilegesRequest getPrivilegesRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/privilege")
.addPathPartAsIs("_security/privilege")
.addPathPart(getPrivilegesRequest.getApplicationName())
.addCommaSeparatedPathParts(getPrivilegesRequest.getPrivilegeNames())
.build();
Expand All @@ -215,7 +215,7 @@ static Request getPrivileges(GetPrivilegesRequest getPrivilegesRequest) {

static Request deletePrivileges(DeletePrivilegesRequest deletePrivilegeRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/security/privilege")
.addPathPartAsIs("_security/privilege")
.addPathPart(deletePrivilegeRequest.getApplication())
.addCommaSeparatedPathParts(deletePrivilegeRequest.getPrivileges())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private AuthenticateRequest() {
}

public Request getRequest() {
return new Request(HttpGet.METHOD_NAME, "/_xpack/security/_authenticate");
return new Request(HttpGet.METHOD_NAME, "/_security/_authenticate");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testPutUser() throws Exception {
assertThat(updateUserResponse.isCreated(), is(false));
// delete user
final Request deleteUserRequest = new Request(HttpDelete.METHOD_NAME,
"/_xpack/security/user/" + putUserRequest.getUser().getUsername());
"/_security/user/" + putUserRequest.getUser().getUsername());
highLevelClient().getLowLevelClient().performRequest(deleteUserRequest);
}

Expand Down
Loading

0 comments on commit 8fba077

Please sign in to comment.