Files
presentations/static-analysis/create_params.rb
2023-07-13 10:33:43 -04:00

58 lines
2.1 KiB
Ruby

def create
@interconnection = if create_with_service_tokens?
::Network::Interconnection::Connection::CreateWithServiceTokens.call(create_with_service_tokens_params)
else
::Network::Interconnection::Connection::Create.call(create_params)
end
if @interconnection.valid?
render "interconnections/connections/show", status: :created, location: interconnection_path(@interconnection.id)
else
render_validation_errors(@interconnection)
end
end
def create_params
# TODO: Remove facility from create params after making metro required in swagger docs
@facility = Facility.find_by_id_or(:code, params[:facility_id]) if params[:facility_id]
params.required([:name, :redundancy, :type])
params[:contact_email] = current_user.email unless params.has_key?(:contact_email)
params[:speed] = ::Network::Interconnection::InterconnectionPort.parse_speed(params[:speed]) if params.has_key?(:speed)
permitted = [:contact_email, :description, :name, :redundancy, :speed, :facility_id, :metro_id, :metro, :type, tags: []]
permitted << { vlans: [] } if advanced_shared_create_enabled?
permitted << :mode if dedicated_interconnection_mode_enabled? && params[:type] == "dedicated"
params
.permit(*permitted)
.merge(
facility: @facility,
metro: @metro,
project: @project,
organization: @organization,
virtual_networks: @virtual_networks,
)
end
def create_with_service_tokens_params
set_service_token_params
# TODO: Remove VRF feature flag check after VRF is released.
array_params = { tags: [], vlans: [] }
array_params = array_params.merge(vrfs: []) if Feature.enabled?(Feature::VRF_ON_SHARED_CONNECTIONS, @organization)
permitted = [:description, :locked, :name, :redundancy, :speed, :contact_email, :metro_id, :type, :service_token_type, array_params]
normalize_params
params
.permit(*permitted)
.merge(
vrfs: @vrfs,
metro: @metro,
project: @project,
organization: @organization,
virtual_networks: @virtual_networks,
)
end