Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] Add OPTIONS method to Clusters and Hosts #13574

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/api/clusters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ class ClustersController < BaseController
include Subcollections::Policies
include Subcollections::PolicyProfiles
include Subcollections::Tags

def options
render_options(:clusters, :node_types => EmsCluster.node_types)
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/hosts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ def edit_resource(type, id, data = {})
host.update_authentication(all_credentials) if all_credentials.present?
end
end

def options
render_options(:hosts, :node_types => Host.node_types)
end
end
end
13 changes: 13 additions & 0 deletions spec/requests/api/clusters_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RSpec.describe 'Clusters API' do
context 'OPTIONS /api/clusters' do
it 'returns clusters node_types' do
api_basic_authorize

expected = a_hash_including("data" => {"node_types" => EmsCluster.node_types.to_s})

run_options(clusters_url)
expect(response.parsed_body).to match(expected)
expect(response.headers['Access-Control-Allow-Methods']).to include('OPTIONS')
end
end
end
12 changes: 12 additions & 0 deletions spec/requests/api/hosts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,17 @@
expect(response).to have_http_status(:forbidden)
end
end

context 'OPTIONS /api/hosts' do
it 'returns hosts node_types' do
api_basic_authorize

expected = a_hash_including("data" => {"node_types" => Host.node_types.to_s})

run_options(hosts_url)
expect(response.parsed_body).to match(expected)
expect(response.headers['Access-Control-Allow-Methods']).to include('OPTIONS')
end
end
end
end