Skip to content

Commit

Permalink
Merge pull request #279 from jntullo/allow_provider_attributes
Browse files Browse the repository at this point in the history
Allow additional provider parameters to be specified on create
  • Loading branch information
abellotti authored Feb 14, 2018
2 parents b3a2bf8 + feeaa6c commit 6983681
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 @@ -455,6 +455,25 @@ def have_endpoint_attributes(expected_hash)
.and_return([OvirtSDK4::ProbeResult.new(:version => '3')])
end

it 'allows provider specific attributes to be specified' do
allow(ManageIQ::Providers::Azure::CloudManager).to receive(:api_allowed_attributes).and_return(%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 6983681

Please sign in to comment.