add oidc auth to all routes and yapf everything

This commit is contained in:
Jordan Rodgers 2017-12-12 15:48:37 -05:00
parent b656df33ba
commit 539cd6f0f4
4 changed files with 97 additions and 38 deletions

View file

@ -1,5 +1,6 @@
import psycopg2
def connect_starrs(db, user, host, password):
try:
starrs = psycopg2.connect(
@ -15,7 +16,7 @@ def get_next_ip(starrs, range_name):
c = starrs.cursor()
try:
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.initialize", ('root', ))
c.callproc("api.get_address_from_range", (range_name, ))
results = c.fetchall()
c.execute("COMMIT")
@ -28,8 +29,8 @@ def get_ip_for_mac(starrs, mac):
c = starrs.cursor()
try:
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.get_system_interface_addresses", (mac.lower(),))
c.callproc("api.initialize", ('root', ))
c.callproc("api.get_system_interface_addresses", (mac.lower(), ))
results = c.fetchall()
c.execute("COMMIT")
finally:
@ -43,8 +44,8 @@ def renew_ip(starrs, addr):
c = starrs.cursor()
try:
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.renew_interface_address", (addr,))
c.callproc("api.initialize", ('root', ))
c.callproc("api.renew_interface_address", (addr, ))
results = c.fetchall()
c.execute("COMMIT")
finally:
@ -56,20 +57,20 @@ def check_hostname(starrs, hostname):
c = starrs.cursor()
try:
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.validate_name", (hostname,))
c.callproc("api.initialize", ('root', ))
c.callproc("api.validate_name", (hostname, ))
valid = False
if hostname == c.fetchall()[0][0]:
valid = True
c.execute("COMMIT")
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.initialize", ('root', ))
c.callproc("api.check_dns_hostname", (hostname, 'csh.rit.edu'))
available = False
if not c.fetchall()[0][0]:
available = True
c.execute("COMMIT")
except(psycopg2.InternalError):
except (psycopg2.InternalError):
valid = False
available = False
finally:
@ -81,7 +82,7 @@ def register_starrs(starrs, name, owner, mac, addr):
c = starrs.cursor()
try:
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.initialize", ('root', ))
c.callproc(
"api.create_system_quick",
(name, owner, 'members', mac, addr, 'csh.rit.edu', 'dhcp', True))
@ -96,7 +97,7 @@ def delete_starrs(starrs, name):
c = starrs.cursor()
try:
c.execute("BEGIN")
c.callproc("api.initialize", ('root',))
c.callproc("api.initialize", ('root', ))
c.callproc("api.remove_system", (name, ))
results = c.fetchall()
c.execute("COMMIT")