Skip to content

Commit f44519b

Browse files
committed
[API] Adds security disable, enable and search user profiles
1 parent 9bf3f03 commit f44519b

File tree

6 files changed

+279
-0
lines changed

6 files changed

+279
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Disables a user profile so it's not visible in user profile searches.
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :uid Unique identifier for the user profile
29+
# @option arguments [String] :refresh If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. (options: true, false, wait_for)
30+
# @option arguments [Hash] :headers Custom HTTP headers
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-disable-user-profile.html
33+
#
34+
def disable_user_profile(arguments = {})
35+
raise ArgumentError, "Required argument 'uid' missing" unless arguments[:uid]
36+
37+
arguments = arguments.clone
38+
headers = arguments.delete(:headers) || {}
39+
40+
body = nil
41+
42+
_uid = arguments.delete(:uid)
43+
44+
method = Elasticsearch::API::HTTP_PUT
45+
path = "_security/profile/#{Utils.__listify(_uid)}/_disable"
46+
params = Utils.process_params(arguments)
47+
48+
Elasticsearch::API::Response.new(
49+
perform_request(method, path, params, body, headers)
50+
)
51+
end
52+
end
53+
end
54+
end
55+
end
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Enables a user profile so it's visible in user profile searches.
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :uid An unique identifier of the user profile
29+
# @option arguments [String] :refresh If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. (options: true, false, wait_for)
30+
# @option arguments [Hash] :headers Custom HTTP headers
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-enable-user-profile.html
33+
#
34+
def enable_user_profile(arguments = {})
35+
raise ArgumentError, "Required argument 'uid' missing" unless arguments[:uid]
36+
37+
arguments = arguments.clone
38+
headers = arguments.delete(:headers) || {}
39+
40+
body = nil
41+
42+
_uid = arguments.delete(:uid)
43+
44+
method = Elasticsearch::API::HTTP_PUT
45+
path = "_security/profile/#{Utils.__listify(_uid)}/_enable"
46+
params = Utils.process_params(arguments)
47+
48+
Elasticsearch::API::Response.new(
49+
perform_request(method, path, params, body, headers)
50+
)
51+
end
52+
end
53+
end
54+
end
55+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Searches for user profiles that match specified criteria.
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [List] :data A comma-separated list of keys for which the corresponding application data are retrieved.
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
# @option arguments [Hash] :body The search definition for user profiles
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-search-user-profile.html
33+
#
34+
def search_user_profiles(arguments = {})
35+
arguments = arguments.clone
36+
headers = arguments.delete(:headers) || {}
37+
38+
body = arguments.delete(:body)
39+
40+
method = if body
41+
Elasticsearch::API::HTTP_POST
42+
else
43+
Elasticsearch::API::HTTP_GET
44+
end
45+
46+
path = "_security/profile/_search"
47+
params = Utils.process_params(arguments)
48+
49+
Elasticsearch::API::Response.new(
50+
perform_request(method, path, params, body, headers)
51+
)
52+
end
53+
end
54+
end
55+
end
56+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client#security#disable_user_profile' do
21+
let(:expected_args) do
22+
[
23+
'PUT',
24+
'_security/profile/foo/_disable',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.security.disable_user_profile(uid: 'foo')).to be_a Elasticsearch::API::Response
33+
end
34+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client#security#enable_user_profile' do
21+
let(:expected_args) do
22+
[
23+
'PUT',
24+
'_security/profile/foo/_enable',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.security.enable_user_profile(uid: 'foo')).to be_a Elasticsearch::API::Response
33+
end
34+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client#security#search_user_profiles' do
21+
let(:expected_args) do
22+
[
23+
method,
24+
'_security/profile/_search',
25+
{},
26+
body,
27+
{}
28+
]
29+
end
30+
let(:method) { 'GET' }
31+
let(:body) { nil }
32+
33+
it 'performs the request' do
34+
expect(client_double.security.search_user_profiles).to be_a Elasticsearch::API::Response
35+
end
36+
37+
context 'when there is a body parameter' do
38+
let(:method) { 'POST' }
39+
let(:body) { {} }
40+
41+
it 'performs the request' do
42+
expect(client_double.security.search_user_profiles(body: {})).to be_a Elasticsearch::API::Response
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)