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

Allow additional provider parameters to be specified on create #279

Merged
merged 1 commit into from
Feb 14, 2018
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
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")]
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jntullo - does the results hash mirror the database columns? Is that why the first hash key is uid_ems and not azure_tenant_id

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bronaghs yeah, it is all of the physical attributes

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