Skip to content

Commit

Permalink
Allow additional provider parameters to be specified in the API
Browse files Browse the repository at this point in the history
This update will allow providers to have more control over the parameters that are allowed when creating a new manager. Currently, only those columns for a provider are allowed. This will also be a good transition starting point to put more of the validation inside of the providers themselves, rather than store it all within the API controller.
  • Loading branch information
Jillian Tullo committed Jan 11, 2018
1 parent 15206e1 commit 75b01af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def validate_credential_attributes(provider, creds)
def fetch_provider_data(provider_klass, data, options = {})
data["options"] = data["options"].deep_symbolize_keys if data.key?("options")
provider_data = data.except(*RESTRICTED_ATTRS)
invalid_keys = provider_data.keys - provider_klass.columns_hash.keys - ENDPOINT_ATTRS - CONNECTION_ATTRS
invalid_keys = provider_data.keys - provider_klass.columns_hash.keys - ENDPOINT_ATTRS - CONNECTION_ATTRS - provider_klass::API_ALLOWED_ATTRIBUTES
raise BadRequestError, "Invalid Provider attributes #{invalid_keys.join(', ')} specified" if invalid_keys.present?
specify_zone(provider_data, data, options)
provider_data
Expand Down
19 changes: 19 additions & 0 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,25 @@ def have_endpoint_attributes(expected_hash)
.and_return([OvirtSDK4::ProbeResult.new(:version => '3')])
end

it 'allows provider specific attributes to be specified' do # JT
stub_const("#{ManageIQ::Providers::Azure::CloudManager}::API_ALLOWED_ATTRIBUTES", %w[azure_tenant_id])
tenant = FactoryGirl.create(:cloud_tenant)
api_basic_authorize collection_action_identifier(:providers, :create)

post(api_providers_url, :params => { "type" => "ManageIQ::Providers::Azure::CloudManager",
"name" => "sample azure provider",
"hostname" => "hostname",
"zone" => @zone,
"azure_tenant_id" => tenant.id,
"credentials" => {}})

expected = {
"results" => [a_hash_including("uid_ems" => tenant.id.to_s, "name" => "sample azure provider")]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it "rejects creation without appropriate role" do
api_basic_authorize

Expand Down

0 comments on commit 75b01af

Please sign in to comment.