@@ 0,0 1,36 @@
+"""Create git-daemon-export-ok files
+
+Revision ID: a8ad35a0bee7
+Revises: b4a2f2ed61b2
+Create Date: 2020-04-11 00:48:04.430870
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'a8ad35a0bee7'
+down_revision = 'b4a2f2ed61b2'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.orm import sessionmaker
+from gitsrht.types import Repository
+try:
+ from tqdm import tqdm
+except ImportError:
+ def tqdm(iterable):
+ yield from iterable
+
+
+Session = sessionmaker()
+
+
+def upgrade():
+ bind = op.get_bind()
+ session = Session(bind=bind)
+ print("Creating git-daemon-export-ok files")
+ for repo in tqdm(session.query(Repository).all()):
+ repo.update_visibility()
+
+
+def downgrade():
+ pass
@@ 1,4 1,6 @@
+import os
import sqlalchemy as sa
+from sqlalchemy import event
from srht.database import Base
from srht.oauth import ExternalUserMixin, ExternalOAuthTokenMixin
from scmsrht.repos import BaseAccessMixin, BaseRedirectMixin
@@ 17,7 19,26 @@ class Redirect(Base, BaseRedirectMixin):
pass
class Repository(Base, BaseRepositoryMixin):
- pass
+ def update_visibility(self):
+ if not os.path.exists(self.path):
+ # Repo dir not initialized yet
+ return
+ # In order to clone a public repo via http, a git-daemon-export-ok file
+ # must exist inside the repo directory. A private repo shouldn't have
+ # this file to improve security.
+ path = os.path.join(self.path, "git-daemon-export-ok")
+ should_exist = self.visibility in (RepoVisibility.public, RepoVisibility.unlisted)
+ if should_exist:
+ with open(path, 'w'):
+ pass
+ elif not should_exist and os.path.exists(path):
+ os.unlink(path)
+
+def update_visibility_event(mapper, connection, target):
+ target.update_visibility()
+
+event.listen(Repository, 'after_insert', update_visibility_event)
+event.listen(Repository, 'after_update', update_visibility_event)
from gitsrht.types.artifact import Artifact
from gitsrht.types.sshkey import SSHKey