示例#1
0
 def test_access_token_setting(self):
     """
     Test functionality of is_acces_token_set
     """
     client = Client()
     assert not client.is_access_token_set()
     client.set_client_access_token("FAKE-TOKEN")
     assert client.is_access_token_set()
示例#2
0
class BuildKite(object):
    def __init__(self):
        """

        :param access_token:
        """
        self.client = Client()
        self.base_url = "https://api.buildkite.com/v2/"

    def set_access_token(self, access_token):
        """

        :param access_token:
        :return:
        """
        self.client.set_client_access_token(access_token)

    def requires_token(func):
        def wrapper(self, *args, **kwargs):
            if not self.client.is_access_token_set():
                raise NoAcccessTokenException
            else:
                return func(self, *args, **kwargs)

        return wrapper

    @requires_token
    def organizations(self):
        return Organizations(self.client, self.base_url)

    @requires_token
    def pipelines(self):
        return Pipelines(self.client, self.base_url)

    @requires_token
    def builds(self):
        return Builds(self.client, self.base_url)

    @requires_token
    def jobs(self):
        return Jobs(self.client, self.base_url)

    @requires_token
    def agents(self):
        return Agents(self.client, self.base_url)
示例#3
0
class BuildKite(object):
    """
    Public API for Buildkite
    """
    def __init__(self):
        """
        Create a new client
        """
        self.client = Client()
        self.base_url = "https://api.buildkite.com/v2/"

    def set_access_token(self, access_token):
        """
        Set the access token to be used to authenticate the requests
        :param access_token: The access token
        """
        self.client.set_client_access_token(access_token)

    def requires_token(func):
        """
        This annotation protects API calls that require authentication.

        It will cause them to raise NoAcccessTokenException if the token is not set in the client.

        :return: Function decorated with the protection
        """
        def wrapper(self, *args, **kwargs):
            """
            Call func or raise NoAcccessTokenException if no access token is set

            :param self:
            :param args: Optional
            :param kwargs: Optional

            :raises NoAcccessTokenException: If no access token is set
            :return:
            """
            if not self.client.is_access_token_set():
                raise NoAcccessTokenException
            else:
                return func(self, *args, **kwargs)

        return wrapper

    @requires_token
    def organizations(self):
        """
        Get Organisation operations for the Buildkite API

        :return: Client
        """
        return Organizations(self.client, self.base_url)

    @requires_token
    def pipelines(self):
        """
        Get Pipeline operations for the Buildkite API

        :return: Client
        """
        return Pipelines(self.client, self.base_url)

    @requires_token
    def builds(self):
        """
        Get Build operations for the Buildkite API

        :return: Client
        """
        return Builds(self.client, self.base_url)

    @requires_token
    def jobs(self):
        """
        Get Job operations for the Buildkite API

        :return: Client
        """
        return Jobs(self.client, self.base_url)

    @requires_token
    def agents(self):
        """
        Get Agent operations for the Buildkite API

        :return: Client
        """
        return Agents(self.client, self.base_url)

    @requires_token
    def emojis(self):
        """
        Get Emoji operations for the Buildkite API

        :return: Client
        """
        return Emojis(self.client, self.base_url)

    def annotations(self):
        """
        Get Annotation operations for the Buildkite API
        """
        return Annotations(self.client, self.base_url)