def project_disabled(self):
        # Just search all Projects for a match
        for project in Project.objects.all():
            if project.matches(self.project):
                print "Project disable check: %s matches rules in %s" % (
                    self.project, project.name
                )
                if project and not project.allowed:
                    # Disabled if Project is marked not-allowed
                    return True
                if project and project.official:
                    # Disabled if Project is official and namespace is not
                    # valid
                    repourl = giturlparse(self.repourl)
                    service = get_or_none(
                        VCSService,
                        netloc=repourl.netloc,
                    )
                    if not service:
                        return True
                    namespace = get_or_none(
                        VCSNameSpace,
                        service=service,
                        path=os.path.dirname(repourl.path),
                    )
                    if not namespace:
                        return True

        return False
Beispiel #2
0
    def project_disabled(self):
        # Just search all Projects for a match
        for project in Project.objects.filter(obs=self.obs):
            if project.matches(self.project):
                print "Project disable check: %s matches rules in %s" % (
                    self.project, project.name)
                if project and not project.allowed:
                    # Disabled if Project is marked not-allowed
                    return True
                if project and project.official:
                    # Disabled if Project is official and namespace is not
                    # valid
                    repourl = giturlparse(self.repourl)
                    service = get_or_none(
                        VCSService,
                        netloc=repourl.netloc,
                    )
                    if not service:
                        return True
                    namespace = get_or_none(
                        VCSNameSpace,
                        service=service,
                        path=os.path.dirname(repourl.path),
                    )
                    if not namespace:
                        return True

        return False
Beispiel #3
0
    def clean(self, exclude=None):
        self.repourl = self.repourl.strip()
        self.branch = self.branch.strip()
        self.project = self.project.strip()
        self.package = self.package.strip()

        duplicates = WebHookMapping.objects.filter(
            project=self.project,
            package=self.package,
            obs=self.obs,
            build=True,
        )
        if self.pk:
            duplicates = duplicates.exclude(pk=self.pk)

        if self.build and duplicates.count():
            raise ValidationError(
                'A mapping object (%s) building in %s %s %s already exists' %
                (duplicates[0].pk, self.obs, self.project, self.package))

        repourl = giturlparse(self.repourl)
        service = get_or_none(VCSService, netloc=repourl.netloc)

        if settings.ONLY_KNOWN_SERVICES and service is None:
            raise ValidationError('%s is not an allowed service' %
                                  repourl.netloc)

        project = get_or_none(Project, name=self.project, obs=self.obs)

        if project and not project.allowed:
            raise ValidationError('Project %s does not allow mappings' %
                                  project)

        if project and project.official:
            namespace = get_or_none(
                VCSNameSpace,
                service=service,
                path=os.path.dirname(repourl.path),
            )
            if not service or not namespace:
                raise ValidationError(
                    'Official project %s allows mapping from known service '
                    'namespaces only' % project)

        if settings.STRICT_MAPPINGS:
            if project and not project.is_repourl_allowed(self.repourl):
                raise ValidationError(
                    "Webhook mapping repourl is not allowed by %s's "
                    "strict rules" % project)
            if project and not project.is_user_allowed(self.user):
                raise ValidationError(
                    "Webhook mapping to %s not allowed for %s" %
                    (project, self.user))
            if (not self.project.startswith("home:%s" % self.user.username)
                    and not self.user.is_superuser):
                raise ValidationError(
                    "Webhook mapping to %s not allowed for %s" %
                    (project, self.user))
 def find(repourl):
     url = giturlparse(repourl)
     return get_or_none(
         VCSNameSpace,
         service__netloc=url.netloc,
         path=os.path.dirname(url.path)
     )
    def clean(self, exclude=None):
        self.repourl = self.repourl.strip()
        self.branch = self.branch.strip()
        self.project = self.project.strip()
        self.package = self.package.strip()

        duplicates = WebHookMapping.objects.filter(
            project=self.project,
            package=self.package,
            obs=self.obs,
            build=True,
        )
        if self.pk:
            duplicates = duplicates.exclude(pk=self.pk)

        if self.build and duplicates.count():
            raise ValidationError(
                'A mapping object (%s) building in %s %s %s already exists' %
                (duplicates[0].pk, self.obs, self.project, self.package)
            )

        repourl = giturlparse(self.repourl)
        service = get_or_none(VCSService, netloc=repourl.netloc)

        if settings.SERVICE_WHITELIST and service is None:
            raise ValidationError(
                '%s is not an allowed service' % repourl.netloc
            )

        project = get_or_none(Project, name=self.project)

        if project and not project.allowed:
            raise ValidationError(
                'Project %s does not allow mappings' % project
            )

        if project and project.official:
            namespace = get_or_none(
                VCSNameSpace,
                service=service,
                path=os.path.dirname(repourl.path),
            )
            if not service or not namespace:
                raise ValidationError(
                    'Official project %s allows mapping from known service '
                    'namespaces only' % project
                )

        if settings.STRICT_MAPPINGS:
            if project and not project.is_repourl_allowed(self.repourl):
                raise ValidationError(
                    "Webhook mapping repourl is not allowed by %s's "
                    "strict rules" % project
                )
            if project and not project.is_user_allowed(self.user):
                raise ValidationError(
                    "Webhook mapping to %s not allowed for %s" %
                    (project, self.user)
                )
            if (
                not self.project.startswith("home:%s" % self.user.username) and
                not self.user.is_superuser
            ):
                raise ValidationError(
                    "Webhook mapping to %s not allowed for %s" %
                    (project, self.user)
                )
Beispiel #6
0
 def find(repourl):
     url = giturlparse(repourl)
     return get_or_none(VCSNameSpace,
                        service__netloc=url.netloc,
                        path=os.path.dirname(url.path))