This commit is contained in:
Duc Trung Le
2023-02-27 23:59:56 +01:00
committed by Duc Trung LE
parent 0e437224d0
commit 28464f9c47
4 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
"""Add from_config column to the services table
Revision ID: 3c2384c5aae1
Revises: 0eee8c825d24
Create Date: 2023-02-27 16:22:26.196231
"""
# revision identifiers, used by Alembic.
revision = '3c2384c5aae1'
down_revision = '0eee8c825d24'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
engine = op.get_bind().engine
tables = sa.inspect(engine).get_table_names()
if 'services' in tables:
op.add_column(
'services',
sa.Column('from_config', sa.Boolean, nullable=False, default=True),
)
op.execute('UPDATE services SET from_config = true')
def downgrade():
op.drop_column('services', sa.Column('from_config'))

View File

@@ -28,6 +28,12 @@ class ServiceAPIHandler(APIHandler):
service = self.services[service_name]
self.write(json.dumps(self.service_model(service)))
@needs_scope('read:services', 'read:services:name', 'read:roles:services')
def post(self, service_name):
model = self.get_json_body()
print('############', model)
self.write('ok')
default_handlers = [
(r"/api/services", ServiceListAPIHandler),

View File

@@ -2371,7 +2371,7 @@ class JupyterHub(Application):
orm_service = orm.Service.find(self.db, name=name)
if orm_service is None:
# not found, create a new one
orm_service = orm.Service(name=name)
orm_service = orm.Service(name=name, from_config=True)
self.db.add(orm_service)
if spec.get('admin', False):
self.log.warning(

View File

@@ -416,6 +416,9 @@ class Service(Base):
ondelete='SET NULL',
),
)
from_config = Column(Boolean, default=True)
oauth_client = relationship(
'OAuthClient',
back_populates="service",