From fc6dfc6da8d2090976d82af7813acc9236406a03 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Mon, 23 Jan 2017 13:13:10 -0500 Subject: [PATCH 1/3] add ansible_repositories api --- .../api/ansible_repositories_controller.rb | 4 ++ .../requests/api/ansible_repositories_spec.rb | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 app/controllers/api/ansible_repositories_controller.rb create mode 100644 spec/requests/api/ansible_repositories_spec.rb diff --git a/app/controllers/api/ansible_repositories_controller.rb b/app/controllers/api/ansible_repositories_controller.rb new file mode 100644 index 00000000000..e2ae8d28b0c --- /dev/null +++ b/app/controllers/api/ansible_repositories_controller.rb @@ -0,0 +1,4 @@ +module Api + class AnsibleRepositoriesController < BaseController + end +end diff --git a/spec/requests/api/ansible_repositories_spec.rb b/spec/requests/api/ansible_repositories_spec.rb new file mode 100644 index 00000000000..0eaaae41afe --- /dev/null +++ b/spec/requests/api/ansible_repositories_spec.rb @@ -0,0 +1,49 @@ +RSpec.describe 'Ansible Repositories API' do + describe 'GET /api/ansible_repositories' do + it 'lists all the ansible repositories with an appropriate role' do + repository = FactoryGirl.create(:ansible_configuration_script) + api_basic_authorize collection_action_identifier(:ansible_repositories, :read, :get) + + run_get(ansible_repositories_url) + + expected = { + 'count' => 1, + 'subcount' => 1, + 'name' => 'ansible_repositories', + 'resources' => + [hash_including('href' => a_string_matching(ansible_repositories_url(repository.id)))] + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + end + + it 'forbids access to ansible repositories without an appropriate role' do + api_basic_authorize + + run_get(ansible_repositories_url) + + expect(response).to have_http_status(:forbidden) + end + end + + describe 'GET /api/ansible_repositories/:id' do + it 'will show an ansible repository with an appropriate role' do + repository = FactoryGirl.create(:ansible_configuration_script) + api_basic_authorize collection_action_identifier(:ansible_repositories, :read, :get) + + run_get(ansible_repositories_url(repository.id)) + + expect(response.parsed_body).to include('href' => a_string_matching(ansible_repositories_url(repository.id))) + expect(response).to have_http_status(:ok) + end + + it 'forbids access to an ansible repository without an appropriate role' do + repository = FactoryGirl.create(:ansible_configuration_script) + api_basic_authorize + + run_get(ansible_repositories_url(repository.id)) + + expect(response).to have_http_status(:forbidden) + end + end +end From 38aa85506d4790ac4d046bcafafd1a00068b23e0 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Wed, 25 Jan 2017 09:04:08 -0500 Subject: [PATCH 2/3] use the base class for what will be repositories --- .../api/ansible_repositories_controller.rb | 4 -- ...configuration_script_sources_controller.rb | 4 ++ .../requests/api/ansible_repositories_spec.rb | 49 ----------------- .../api/configuration_script_sources_spec.rb | 52 +++++++++++++++++++ 4 files changed, 56 insertions(+), 53 deletions(-) delete mode 100644 app/controllers/api/ansible_repositories_controller.rb create mode 100644 app/controllers/api/configuration_script_sources_controller.rb delete mode 100644 spec/requests/api/ansible_repositories_spec.rb create mode 100644 spec/requests/api/configuration_script_sources_spec.rb diff --git a/app/controllers/api/ansible_repositories_controller.rb b/app/controllers/api/ansible_repositories_controller.rb deleted file mode 100644 index e2ae8d28b0c..00000000000 --- a/app/controllers/api/ansible_repositories_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Api - class AnsibleRepositoriesController < BaseController - end -end diff --git a/app/controllers/api/configuration_script_sources_controller.rb b/app/controllers/api/configuration_script_sources_controller.rb new file mode 100644 index 00000000000..5d77ab9477d --- /dev/null +++ b/app/controllers/api/configuration_script_sources_controller.rb @@ -0,0 +1,4 @@ +module Api + class ConfigurationScriptSourcesController < BaseController + end +end diff --git a/spec/requests/api/ansible_repositories_spec.rb b/spec/requests/api/ansible_repositories_spec.rb deleted file mode 100644 index 0eaaae41afe..00000000000 --- a/spec/requests/api/ansible_repositories_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -RSpec.describe 'Ansible Repositories API' do - describe 'GET /api/ansible_repositories' do - it 'lists all the ansible repositories with an appropriate role' do - repository = FactoryGirl.create(:ansible_configuration_script) - api_basic_authorize collection_action_identifier(:ansible_repositories, :read, :get) - - run_get(ansible_repositories_url) - - expected = { - 'count' => 1, - 'subcount' => 1, - 'name' => 'ansible_repositories', - 'resources' => - [hash_including('href' => a_string_matching(ansible_repositories_url(repository.id)))] - } - expect(response.parsed_body).to include(expected) - expect(response).to have_http_status(:ok) - end - - it 'forbids access to ansible repositories without an appropriate role' do - api_basic_authorize - - run_get(ansible_repositories_url) - - expect(response).to have_http_status(:forbidden) - end - end - - describe 'GET /api/ansible_repositories/:id' do - it 'will show an ansible repository with an appropriate role' do - repository = FactoryGirl.create(:ansible_configuration_script) - api_basic_authorize collection_action_identifier(:ansible_repositories, :read, :get) - - run_get(ansible_repositories_url(repository.id)) - - expect(response.parsed_body).to include('href' => a_string_matching(ansible_repositories_url(repository.id))) - expect(response).to have_http_status(:ok) - end - - it 'forbids access to an ansible repository without an appropriate role' do - repository = FactoryGirl.create(:ansible_configuration_script) - api_basic_authorize - - run_get(ansible_repositories_url(repository.id)) - - expect(response).to have_http_status(:forbidden) - end - end -end diff --git a/spec/requests/api/configuration_script_sources_spec.rb b/spec/requests/api/configuration_script_sources_spec.rb new file mode 100644 index 00000000000..66de589dce0 --- /dev/null +++ b/spec/requests/api/configuration_script_sources_spec.rb @@ -0,0 +1,52 @@ +RSpec.describe 'Configuration Script Sources API' do + describe 'GET /api/configuration_script_sources' do + it 'lists all the configuration script sources with an appropriate role' do + repository = FactoryGirl.create(:configuration_script_source) + api_basic_authorize collection_action_identifier(:configuration_script_sources, :read, :get) + + run_get(configuration_script_sources_url) + + expected = { + 'count' => 1, + 'subcount' => 1, + 'name' => 'configuration_script_sources', + 'resources' => + [hash_including('href' => a_string_matching(configuration_script_sources_url(repository.id)))] + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + end + + it 'forbids access to configuration script sources without an appropriate role' do + api_basic_authorize + + run_get(configuration_script_sources_url) + + expect(response).to have_http_status(:forbidden) + end + end + + describe 'GET /api/configuration_script_sources/:id' do + it 'will show a configuration script source with an appropriate role' do + repository = FactoryGirl.create(:configuration_script_source) + api_basic_authorize collection_action_identifier(:configuration_script_sources, :read, :get) + + run_get(configuration_script_sources_url(repository.id)) + + expected = { + 'href' => a_string_matching(configuration_script_sources_url(repository.id)) + } + expect(response.parsed_body).to include(expected) + expect(response).to have_http_status(:ok) + end + + it 'forbids access to a configuration script source without an appropriate role' do + repository = FactoryGirl.create(:configuration_script_source) + api_basic_authorize + + run_get(configuration_script_sources_url(repository.id)) + + expect(response).to have_http_status(:forbidden) + end + end +end From dc84f65c09981ec403fef0fc0670fd9831c40927 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Thu, 26 Jan 2017 08:43:58 -0500 Subject: [PATCH 3/3] update product feature used update to the identifier --- config/api.yml | 14 ++++++++++++++ .../api/configuration_script_sources_spec.rb | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config/api.yml b/config/api.yml index 5381f919cbb..a8391cebca6 100644 --- a/config/api.yml +++ b/config/api.yml @@ -56,6 +56,20 @@ :get: - :name: read :identifier: embedded_configuration_script_payload_view + :configuration_script_sources: + :description: Configuration Script Source + :options: + - :collection + :verbs: *g + :klass: ConfigurationScriptSource + :collection_actions: + :get: + - :name: read + :identifier: embedded_configuration_script_source_view + :resource_actions: + :get: + - :name: read + :identifier: embedded_configuration_script_source_view :auth: :description: REST API Authentication :options: diff --git a/spec/requests/api/configuration_script_sources_spec.rb b/spec/requests/api/configuration_script_sources_spec.rb index 66de589dce0..517783017c9 100644 --- a/spec/requests/api/configuration_script_sources_spec.rb +++ b/spec/requests/api/configuration_script_sources_spec.rb @@ -10,8 +10,7 @@ 'count' => 1, 'subcount' => 1, 'name' => 'configuration_script_sources', - 'resources' => - [hash_including('href' => a_string_matching(configuration_script_sources_url(repository.id)))] + 'resources' => [hash_including('href' => a_string_matching(configuration_script_sources_url(repository.id)))] } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok)