Skip to content

Commit

Permalink
Update rkwebutil
Browse files Browse the repository at this point in the history
  • Loading branch information
rknop committed Jul 15, 2024
1 parent d1967af commit ad27cac
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 91 deletions.
2 changes: 1 addition & 1 deletion conductor/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSTALLDIR = test_install

toinstall = webservice.py db.py flaskauth.py updater.py run_conductor.sh \
toinstall = webservice.py rkauth_flask.py updater.py run_conductor.sh \
static/conductor.js static/conductor_start.js static/rkwebutil.js \
static/resetpasswd_start.js static/rkauth.js static/seechange.css \
templates/base.html templates/conductor_root.html
Expand Down
8 changes: 0 additions & 8 deletions conductor/db.py

This file was deleted.

1 change: 0 additions & 1 deletion conductor/flaskauth.py

This file was deleted.

1 change: 1 addition & 0 deletions conductor/rkauth_flask.py
29 changes: 21 additions & 8 deletions conductor/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,29 @@ def do_the_things( self ):
# Import and configure the auth subapp

sys.path.insert( 0, pathlib.Path(__name__).parent )
import flaskauth
import rkauth_flask

kwargs = {
'db_host': cfg.value( 'db.host' ),
'db_port': cfg.value( 'db.port' ),
'db_name': cfg.value( 'db.database' ),
'db_user': cfg.value( 'db.user' )
}
password = cfg.value( 'db.password' )
if password is None:
if cfg.value( 'db.password_file' ) is None:
raise RuntimeError( 'In config, one of db.password or db.password_file must be specified' )
with open( cfg.value( 'db.password_file' ) ) as ifp:
password = ifp.readline().strip()
kwargs[ 'db_password' ] = password

for attr in [ 'email_from', 'email_subject', 'email_system_name',
'smtp_server', 'smtp_port', 'smtp_use_ssl', 'smtp_username', 'smtp_password' ]:
setattr( flaskauth.RKAuthConfig, attr, cfg.value( f'conductor.{attr}' ) )
flaskauth.RKAuthConfig.webap_url = cfg.value('conductor.conductor_url')
if flaskauth.RKAuthConfig.webap_url[-1] != '/':
flaskauth.RKAuthConfig.webap_url += '/'
flaskauth.RKAuthConfig.webap_url += "auth"
# app.logger.debug( f'webap_url is {flaskauth.RKAuthConfig.webap_url}' )
app.register_blueprint( flaskauth.bp )
kwargs[ attr ] = cfg.value( f'conductor.{attr}' )

rkauth_flask.RKAuthConfig.setdbparams( **kwargs )

app.register_blueprint( rkauth_flask.bp )

# Configure urls

Expand Down
2 changes: 1 addition & 1 deletion docker/application/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ ADD conductor/ /usr/src/seechange/conductor/
# Need special handling of symlinks, because the
# ADD above copied the links as is, but they point
# to something that won't exist at the destination.
ADD conductor/flaskauth.py /usr/src/seechange/conductor/flaskauth.py
ADD conductor/rkauth_flask.py /usr/src/seechange/conductor/rkauth_flask.py
ADD conductor/static/rkwebutil.js /usr/src/seechange/conductor/static/rkwebutil.js
ADD conductor/static/rkauth.js /usr/src/seechange/conductor/static/rkauth.js
ADD conductor/static/seechange.css /usr/src/seechange/conductor/static/seechange.css
Expand Down
4 changes: 2 additions & 2 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Normally, all of these image should already be present in the `ghcr.io` archive,

To build and push the docker images, in the `tests` subdirectory run:
```
IMTGAG=[tag] docker compose build
IMGTAG=[tag] docker compose build
```
where [tag] is exactly what you see in the `docker-compose.yaml` file, followed by:
```
Expand All @@ -84,4 +84,4 @@ This set of docker images depend on the following files:
* `webap/*`
* `requirements.text`

If you change any of those files, you will need to build and push new docker images. Before doing that, edit `tests/docker-compose.yaml` and bump the date part of the tag for _every_ image, so that your changed images will only get used for your branch while you're still finalizing your pull request, and so that the updated images will get used by everybody else once your branch has been merged to main.
If you change any of those files, you will need to build and push new docker images. Before doing that, edit `tests/docker-compose.yaml` and bump the date part of the tag for _every_ image (search and replace is your friend), so that your changed images will only get used for your branch while you're still finalizing your pull request, and so that the updated images will get used by everybody else once your branch has been merged to main.
60 changes: 1 addition & 59 deletions models/user.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from datetime import datetime, timedelta
import dateutil.parser
import pytz
import uuid

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID as sqlUUID
from sqlalchemy.dialects.postgresql import JSONB
from models.base import Base, SmartSession
from util.util import as_UUID, as_datetime

from models.base import Base

class AuthUser(Base):
__tablename__ = "authuser"
Expand All @@ -20,61 +14,9 @@ class AuthUser(Base):
pubkey = sa.Column( sa.Text )
privkey = sa.Column( JSONB )

# This is here rather than just using things already defined in base
# because this table is designed to work with the pre-existing auth
# library in rkwebutil.
@classmethod
def get( cls, id, session=None ):
id = id if isinstance( id, uuid.UUID) else uuid.UUID( id )
with SmartSession(session) as sess:
q = sess.query(cls).filter( cls.id==id )
if q.count() > 1:
raise ErrorMsg( f'Error, {cls.__name__} {id} multiply defined! This shouldn\'t happen.' )
if q.count() == 0:
return None
return q[0]

@classmethod
def getbyusername( cls, name, session=None ):
with SmartSession(session) as sess:
q = sess.query(cls).filter( cls.username==name )
return q.all()

@classmethod
def getbyemail( cls, email, session=None ):
with SmartSession(session) as sess:
q = sess.query(cls).filter( cls.email==email )
return q.all()


class PasswordLink(Base):
__tablename__ = "passwordlink"

id = sa.Column( sqlUUID(as_uuid=True), primary_key=True, default=uuid.uuid4 )
userid = sa.Column( sqlUUID(as_uuid=True), sa.ForeignKey("authuser.id", ondelete="CASCADE"), index=True )
expires = sa.Column( sa.DateTime(timezone=True) )

@classmethod
def new( cls, userid, expires=None, session=None ):
if expires is None:
expires = datetime.now(pytz.utc) + timedelta(hours=1)
else:
expires = as_datetime( expires )
with SmartSession(session) as sess:
link = PasswordLink( userid = as_UUID(userid),
expires = expires )
sess.add( link )
sess.commit()
return link

# This is here rather than just using things already defined in base
# because this table is designed to work with the pre-existing auth
# library in rkwebutil.
@classmethod
def get( cls, uuid, session=None ):
with SmartSession(session) as sess:
q = sess.query( PasswordLink ).filter( PasswordLink.id==uuid )
if q.count() == 0:
return None
else:
return q.first()
18 changes: 9 additions & 9 deletions tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
make-archive-directories:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/upload-connector:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/upload-connector:${IMGTAG:-test20240715}
build:
context: ../extern/nersc-upload-connector
args:
Expand All @@ -20,7 +20,7 @@ services:
depends_on:
make-archive-directories:
condition: service_completed_successfully
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/upload-connector:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/upload-connector:${IMGTAG:-test20240715}
build:
context: ../extern/nersc-upload-connector
args:
Expand All @@ -47,7 +47,7 @@ services:
user: ${USERID:-0}:${GROUPID:-0}

postgres:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/postgres:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/postgres:${IMGTAG:-test20240715}
build:
context: ../docker/postgres
environment:
Expand All @@ -60,7 +60,7 @@ services:
retries: 5

setuptables:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-test20240715}
build:
context: ../
dockerfile: ./docker/application/Dockerfile
Expand All @@ -84,7 +84,7 @@ services:
- "${MAILHOG_PORT:-8025}:8025"

conductor:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/conductor:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/conductor:${IMGTAG:-test20240715}
build:
context: ../
dockerfile: ./docker/application/Dockerfile
Expand Down Expand Up @@ -114,7 +114,7 @@ services:
condition: service_completed_successfully
make-archive-directories:
condition: service_completed_successfully
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange-webap:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange-webap:${IMGTAG:-test20240715}
build:
context: ../webap
user: ${USERID:-0}:${GROUPID:-0}
Expand All @@ -135,7 +135,7 @@ services:
entrypoint: [ "gunicorn", "-w", "4", "-b", "0.0.0.0:8081", "--timeout", "0", "seechange_webap:app" ]

runtests:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-test20240715}
build:
context: ../
dockerfile: ./docker/application/Dockerfile
Expand Down Expand Up @@ -165,7 +165,7 @@ services:
entrypoint: "pytest -v /seechange/$TEST_SUBFOLDER"

runalltests:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-test20240715}
build:
context: ../
dockerfile: ./docker/application/Dockerfile
Expand Down Expand Up @@ -195,7 +195,7 @@ services:
entrypoint: "pytest -v /seechange/tests"

shell:
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-tests20240628}
image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-c3-time-domain}/seechange:${IMGTAG:-test20240715}
build:
context: ../
dockerfile: ./docker/application/Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_pipeline_exposure_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_exposure_launcher( conductor_connector,
measq = session.query( Measurements ).join( Cutouts ).join( SourceList ).join( Image )
meas0 = measq.filter( Image.id==sub0.id ).all()
meas1 = measq.filter( Image.id==sub1.id ).all()
assert len(meas0) == 3
assert len(meas0) == 2
assert len(meas1) == 6

finally:
Expand Down
2 changes: 1 addition & 1 deletion webap/rkwebutil
Submodule rkwebutil updated 55 files
+2 −1 .gitignore
+0 −436 auth.py
+2 −1 rkauth.js
+245 −126 rkauth_flask.py
+589 −0 rkauth_webpy.py
+151 −51 test/docker-compose.yaml
+19 −0 test/docker_apache/000-default.conf
+70 −0 test/docker_apache/Dockerfile
+30 −0 test/docker_apache/Makefile
+1 −0 test/docker_apache/ap
+1 −0 test/docker_apache/cert.pem
+1 −0 test/docker_apache/key.pem
+8 −0 test/docker_apache/server.py
+65 −0 test/docker_flask/Dockerfile
+2 −2 test/docker_flask/Makefile
+19 −19 test/docker_flask/ap/__init__.py
+0 −0 test/docker_flask/ap/static/ap.css
+0 −0 test/docker_flask/ap/static/ap.js
+0 −0 test/docker_flask/ap/static/ap_start.js
+0 −0 test/docker_flask/ap/static/tconv.js
+0 −0 test/docker_flask/ap/static/tconv_start.js
+0 −0 test/docker_flask/ap/templates/ap.html
+0 −0 test/docker_flask/ap/templates/base.html
+0 −0 test/docker_flask/ap/templates/tconv.html
+0 −0 test/docker_flask/cert.pem
+1 −1 test/docker_flask/createdb.py
+0 −0 test/docker_flask/key.pem
+0 −0 test/docker_flask/server.py
+0 −41 test/docker_flaskserver/Dockerfile
+0 −200 test/docker_flaskserver/ap/db.py
+9 −13 test/docker_postgres/Dockerfile
+4 −4 test/docker_postgres/run_postgres.sh
+10 −3 test/docker_test/Dockerfile
+5 −1 test/docker_webpy/000-default.conf
+68 −0 test/docker_webpy/Dockerfile
+3 −4 test/docker_webpy/Makefile
+0 −0 test/docker_webpy/ap.css
+4 −16 test/docker_webpy/ap.js
+22 −28 test/docker_webpy/ap.py
+25 −0 test/docker_webpy/ap_start.js
+1 −0 test/docker_webpy/cert.pem
+0 −0 test/docker_webpy/createdb.py
+1 −0 test/docker_webpy/key.pem
+0 −0 test/docker_webpy/ports.conf
+0 −0 test/docker_webpy/wsgi.conf.patch
+0 −30 test/docker_webserver/Dockerfile
+0 −37 test/docker_webserver/ap_start.js
+0 −220 test/docker_webserver/db.py
+14 −9 test/test_auth.py
+2 −0 test/test_install/apache/.gitignore
+2 −0 test/test_install/apache_sa/.gitignore
+2 −0 test/test_install/flask/.gitignore
+2 −0 test/test_install/flask_sa/.gitignore
+2 −0 test/test_install/webpy/.gitignore
+2 −0 test/test_install/webpy_sa/.gitignore

0 comments on commit ad27cac

Please sign in to comment.