Skip to content

Commit

Permalink
Fix col data type in migrations and radusergroup view definition
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed Oct 26, 2023
1 parent 5a20091 commit 8169dac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def upgrade():
op.execute(
"""
CREATE OR REPLACE VIEW radusergroup AS
SELECT interface.mac AS "UserName",
SELECT interface.mac::text AS "UserName",
host(switch.management_ip) AS "NASIPAddress",
switch_port.name AS "NASPortId",
vlan.name::text || '_untagged'::text AS "GroupName",
Expand All @@ -69,7 +69,7 @@ def upgrade():
JOIN current_property ON "user".id = current_property.user_id AND NOT current_property.denied
WHERE current_property.property_name::text = 'network_access'::text
UNION ALL
SELECT interface.mac AS "UserName",
SELECT interface.mac::text AS "UserName",
host(switch.management_ip) AS "NASIPAddress",
switch_port.name AS "NASPortId",
radius_property.hades_group_name AS "GroupName",
Expand All @@ -87,7 +87,7 @@ def upgrade():
JOIN current_property ON "user".id = current_property.user_id AND NOT current_property.denied
JOIN radius_property ON radius_property.property::text = current_property.property_name::text
UNION ALL
SELECT interface.mac AS "UserName",
SELECT interface.mac::text AS "UserName",
host(switch.management_ip) AS "NASIPAddress",
switch_port.name AS "NASPortId",
'no_network_access'::text AS "GroupName",
Expand Down Expand Up @@ -227,7 +227,7 @@ def downgrade():
op.execute(
"""
CREATE OR REPLACE VIEW radusergroup AS
SELECT interface.mac AS "UserName",
SELECT interface.mac::text AS "UserName",
host(switch.management_ip) AS "NASIPAddress",
switch_port.name AS "NASPortId",
vlan.name::text || '_untagged'::text AS "GroupName",
Expand All @@ -245,7 +245,7 @@ def downgrade():
JOIN current_property ON "user".id = current_property.user_id AND NOT current_property.denied
WHERE current_property.property_name::text = 'network_access'::text
UNION ALL
SELECT interface.mac AS "UserName",
SELECT interface.mac::text AS "UserName",
host(switch.management_ip) AS "NASIPAddress",
switch_port.name AS "NASPortId",
radius_property.property AS "GroupName",
Expand All @@ -260,7 +260,7 @@ def downgrade():
JOIN current_property ON "user".id = current_property.user_id AND NOT current_property.denied
JOIN radius_property ON radius_property.property::text = current_property.property_name::text
UNION ALL
SELECT interface.mac AS "UserName",
SELECT interface.mac::text AS "UserName",
host(switch.management_ip) AS "NASIPAddress",
switch_port.name AS "NASPortId",
'no_network_access'::text AS "GroupName",
Expand Down
40 changes: 23 additions & 17 deletions pycroft/model/hades.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@
# Priority 20: valid case (interface's mac w/ vlan at correct ports)
# <mac> @ <switch>/<port> → <vlan>_[un]tagged (Prio 20)
# Parsing continues because of Fall-Through:=Yes
Query([
Interface.mac.label('UserName'),
# `host()` does not print the `/32` like `text` would
func.host(Switch.management_ip).label('NASIPAddress'),
SwitchPort.name.label('NASPortId'),
# TODO: add `_tagged` instead if interface needs that
(VLAN.name + '_untagged').label('GroupName'),
literal(20).label('Priority'),
]).select_from(User)
Query(
[
func.text(Interface.mac).label("UserName"),
# `host()` does not print the `/32` like `text` would
func.host(Switch.management_ip).label("NASIPAddress"),
SwitchPort.name.label("NASPortId"),
# TODO: add `_tagged` instead if interface needs that
(VLAN.name + "_untagged").label("GroupName"),
literal(20).label("Priority"),
]
)
.select_from(User)
.join(Host)
.join(Interface)
.join(Host.room)
Expand All @@ -97,7 +100,7 @@
# Also, priority 10: some other custom radius group
# <mac> @ <switch>/<port> → <blocking_group> (Prio -10)
select(
Interface.mac.label("UserName"),
func.text(Interface.mac).label("UserName"),
func.host(Switch.management_ip).label("NASIPAddress"),
SwitchPort.name.label("NASPortId"),
radius_property.c.hades_group_name.label("GroupName"),
Expand All @@ -118,13 +121,16 @@
radius_property, radius_property.c.property == CurrentProperty.property_name
),
# Priority 0: No blocking reason exists → generic error group `no_network_access`
Query([
Interface.mac.label('UserName'),
func.host(Switch.management_ip).label('NASIPAddress'),
SwitchPort.name.label('NASPortId'),
literal('no_network_access').label('GroupName'),
literal(0).label('Priority'),
]).select_from(User)
Query(
[
func.text(Interface.mac).label("UserName"),
func.host(Switch.management_ip).label("NASIPAddress"),
SwitchPort.name.label("NASPortId"),
literal("no_network_access").label("GroupName"),
literal(0).label("Priority"),
]
)
.select_from(User)
.outerjoin(network_access_subq, User.id == network_access_subq.c.user_id)
.filter(network_access_subq.c.network_access.is_(None))
.join(User.hosts)
Expand Down

0 comments on commit 8169dac

Please sign in to comment.