ubicloud/helpers/private_subnet.rb
Jeremy Evans aeacc6f0bb Allow authorization methods to accept objects in addition to ids
Previously, project_id and subject_id needed to be a uuid, and
object_id could be a uuid or ubid. This allows accepting an
object for all three. This simplifies almost all callers of
these methods. It also doesn't require either parsing a ubid
or generating a ubid. Previously, even if a uuid was given, it
would turn it into a ubid in order to extract the class, and
guess ApiKey if it was an et ubid.
2025-09-18 02:56:28 +09:00

54 lines
1.6 KiB
Ruby

# frozen_string_literal: true
class Clover
def authorized_private_subnet(perm: "PrivateSubnet:view", location_id: nil, key: "private_subnet_id", id: nil)
authorized_object(association: :private_subnets, key:, perm:, location_id:, id:)
end
def private_subnet_list
dataset = dataset_authorize(@project.private_subnets_dataset, "PrivateSubnet:view")
if api?
dataset = dataset.where(location: @location) if @location
paginated_result(dataset.eager(nics: :private_subnet), Serializers::PrivateSubnet)
else
@pss = dataset.all
view "networking/private_subnet/index"
end
end
def private_subnet_post(name)
authorize("PrivateSubnet:create", @project)
if (firewall_id = typecast_params.nonempty_str("firewall_id"))
unless (firewall = authorized_firewall(location_id: @location.id))
fail Validation::ValidationFailed.new(firewall_id: "Firewall with id \"#{firewall_id}\" and location \"#{@location.display_name}\" is not found")
end
end
ps = nil
DB.transaction do
ps = Prog::Vnet::SubnetNexus.assemble(
@project.id,
name:,
location_id: @location.id,
firewall_id: firewall&.id
).subject
audit_log(ps, "create")
end
if api?
Serializers::PrivateSubnet.serialize(ps)
else
flash["notice"] = "'#{name}' will be ready in a few seconds"
request.redirect ps
end
end
def generate_private_subnet_options
options = OptionTreeGenerator.new
options.add_option(name: "name")
options.add_option(name: "location", values: Option.locations)
options.serialize
end
end