How to use the stashy.helpers.Nested function in stashy

To help you get started, we’ve selected a few stashy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cosmin / stashy / stashy / permissions.py View on Github external
* REPO_ADMIN

        """
        return self._client.put(self.url(), params=dict(name=user, permission=permission))

    @ok_or_error
    def revoke(self, user):
        """
        Revoke all permissions for a user.
        """
        return self._client.delete(self.url(), params=dict(name=user))


class Permissions(ResourceBase):
    groups = Nested(Groups)
    users = Nested(Users)


class ProjectPermissions(Permissions):
    def _url_for(self, permission):
        return self.url().rstrip("/") + "/" + permission + "/all"

    def _url_for_users(self):
        return self.url().rstrip("/") + "/users"

    def _url_for_groups(self):
        return self.url().rstrip("/") + "/groups"

    @ok_or_error
    def grant(self, permission):
        """
        Grant or revoke a project permission to all users, i.e. set the default permission.
github cosmin / stashy / stashy / repos.py View on Github external
Support for withCounts is not implement.
        """
        params = dict(until=until, withCounts=False)
        if since is not None:
            params['since'] = since
        if path is not None:
            params['path'] = path
        return self.paginate('/commits', params=params)

    permissions = Nested(Permissions)
    repo_permissions = Nested(RepositoryPermissions,
                              relative_path="/permissions")

    pull_requests = Nested(PullRequests, relative_path="/pull-requests")
    settings = Nested(Settings)
    webhooks = Nested(Webhooks)
    branch_permissions = Nested(BranchPermissions, relative_path=None)
       
    @response_or_error
    def _get_public(self):
        """
        Args:
            N/A
        Returns:
            (bool): True if repo is public, False if it is not public
        """
        return self._client.get(self.url())

    @ok_or_error
    def _set_public(self, value):
        """
github cosmin / stashy / stashy / projects.py View on Github external
def keys(self):
        """
        Retrieve the access keys associated with the project
        """
        return self.paginate('/ssh', is_keys=True)

    @ok_or_error
    def add_key(self, key_text, permission):
        return self._client.post(self.url('/ssh', is_keys=True),
                                 data=dict(key=dict(text=key_text),
                                           permission=permission))


    permissions = Nested(ProjectPermissions, relative_path="/permissions")
    repos = Nested(Repos)
    settings = Nested(Settings)
    branch_permissions = Nested(BranchPermissions, relative_path=None)
    default_reviewers = Nested(DefaultReviewers, relative_path=None)


class Projects(ResourceBase, IterableResource):
    @response_or_error
    def get(self, project):
        """
        Retrieve the project matching the supplied key.
        """
        return self._client.get(self.url(project))

    def __getitem__(self, item):
        return Project(item, self.url(item), self._client, self)

    @response_or_error
github cosmin / stashy / stashy / projects.py View on Github external
def list(self, type=None):
        """
        Convenience method to return a list (rather than iterable) of all elements
        """
        return list(self.all(type=type))

    def __getitem__(self, item):
        """
        Return a :class:`Hook` object for operations on a specific hook
        """
        return Hook(item, self.url(item), self._client, self)


class Settings(ResourceBase):
    hooks = Nested(Hooks)

class Project(ResourceBase):
    def __init__(self, key, url, client, parent):
        super(Project, self).__init__(url, client, parent)
        self._key = key

    @ok_or_error
    def delete(self):
        """
        Delete the project
        """
        return self._client.delete(self.url())

    @response_or_error
    def update(self, new_key=None, name=None, description=None, avatar=None, public=None):
        """
github cosmin / stashy / stashy / repos.py View on Github external
path: an optional path to filter changesets by.

        Support for withCounts is not implement.
        """
        params = dict(until=until, withCounts=False)
        if since is not None:
            params['since'] = since
        if path is not None:
            params['path'] = path
        return self.paginate('/commits', params=params)

    permissions = Nested(Permissions)
    repo_permissions = Nested(RepositoryPermissions,
                              relative_path="/permissions")

    pull_requests = Nested(PullRequests, relative_path="/pull-requests")
    settings = Nested(Settings)
    webhooks = Nested(Webhooks)
    branch_permissions = Nested(BranchPermissions, relative_path=None)
       
    @response_or_error
    def _get_public(self):
        """
        Args:
            N/A
        Returns:
            (bool): True if repo is public, False if it is not public
        """
        return self._client.get(self.url())

    @ok_or_error
    def _set_public(self, value):
github cosmin / stashy / stashy / permissions.py View on Github external
* REPO_WRITE
            * REPO_ADMIN

        """
        return self._client.put(self.url(), params=dict(name=user, permission=permission))

    @ok_or_error
    def revoke(self, user):
        """
        Revoke all permissions for a user.
        """
        return self._client.delete(self.url(), params=dict(name=user))


class Permissions(ResourceBase):
    groups = Nested(Groups)
    users = Nested(Users)


class ProjectPermissions(Permissions):
    def _url_for(self, permission):
        return self.url().rstrip("/") + "/" + permission + "/all"

    def _url_for_users(self):
        return self.url().rstrip("/") + "/users"

    def _url_for_groups(self):
        return self.url().rstrip("/") + "/groups"

    @ok_or_error
    def grant(self, permission):
        """
github cosmin / stashy / stashy / projects.py View on Github external
Retrieve the access keys associated with the project
        """
        return self.paginate('/ssh', is_keys=True)

    @ok_or_error
    def add_key(self, key_text, permission):
        return self._client.post(self.url('/ssh', is_keys=True),
                                 data=dict(key=dict(text=key_text),
                                           permission=permission))


    permissions = Nested(ProjectPermissions, relative_path="/permissions")
    repos = Nested(Repos)
    settings = Nested(Settings)
    branch_permissions = Nested(BranchPermissions, relative_path=None)
    default_reviewers = Nested(DefaultReviewers, relative_path=None)


class Projects(ResourceBase, IterableResource):
    @response_or_error
    def get(self, project):
        """
        Retrieve the project matching the supplied key.
        """
        return self._client.get(self.url(project))

    def __getitem__(self, item):
        return Project(item, self.url(item), self._client, self)

    @response_or_error
    def create(self, key, name, description='', avatar=None):
        """
github cosmin / stashy / stashy / client.py View on Github external
from .helpers import Nested, add_json_headers
from .admin import Admin
from .projects import Projects
from .ssh import Keys
from .compat import basestring
from .allrepos import Repos
from .builds import Build

class Stash(object):
    _url = "/"

    def __init__(self, base_url, username=None, password=None, oauth=None, verify=True, token=None, session=None):
        self._client = StashClient(base_url, username, password, oauth, verify, token, session=session)

    admin = Nested(Admin)
    projects = Nested(Projects)
    ssh = Nested(Keys)
    repos = Nested(Repos)

    def groups(self, filter=None):
        """
        Consider using stash.admin.groups instead.
        """
        return self.admin.groups.get(filter)

    def users(self, filter=None):
        """
        Consider using stash.admin.users instead.
        """
        return self.admin.users.get(filter)