Exemplo n.º 1
0
    def membership_action(self, memb_id, action, reason=""):
        """Perform action on a membership

        Arguments:
        memb_id -- membership identifier
        action  -- action to perform, one of "leave", "cancel", "accept",
                   "reject", "remove"
        reason  -- reason of performing the action

        In case of success, return nothing.
        """
        path = join_urls(self.api_memberships, str(memb_id))
        path = join_urls(path, "action")
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request({action: reason}, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="POST")
Exemplo n.º 2
0
    def membership_action(self, memb_id, action, reason=""):
        """Perform action on a membership

        Arguments:
        memb_id -- membership identifier
        action  -- action to perform, one of "leave", "cancel", "accept",
                   "reject", "remove"
        reason  -- reason of performing the action

        In case of success, return nothing.
        """
        path = join_urls(self.api_memberships, str(memb_id))
        path = join_urls(path, "action")
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request({action: reason}, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="POST")
Exemplo n.º 3
0
    def project_action(self, project_id, action, reason=""):
        """Perform action on a project

        Arguments:
        project_id -- project identifier
        action     -- action to perform, one of "suspend", "unsuspend",
                      "terminate", "reinstate"
        reason     -- reason of performing the action

        In case of success, return nothing.
        """
        path = join_urls(self.api_projects, str(project_id))
        path = join_urls(path, "action")
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request({action: reason}, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="POST")
Exemplo n.º 4
0
    def project_action(self, project_id, action, reason=""):
        """Perform action on a project

        Arguments:
        project_id -- project identifier
        action     -- action to perform, one of "suspend", "unsuspend",
                      "terminate", "reinstate"
        reason     -- reason of performing the action

        In case of success, return nothing.
        """
        path = join_urls(self.api_projects, str(project_id))
        path = join_urls(path, "action")
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request({action: {"reason": reason}}, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="POST")
Exemplo n.º 5
0
    def application_action(self, app_id, action, reason=""):
        """Perform action on an application

        Arguments:
        app_id -- application identifier
        action -- action to perform, one of "approve", "deny",
                  "dismiss", "cancel"
        reason -- reason of performing the action

        In case of success, return nothing.
        """
        path = join_urls(self.api_applications, str(app_id))
        path = join_urls(path, "action")
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request({action: reason}, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="POST")
Exemplo n.º 6
0
    def __init__(self,
                 token,
                 auth_url,
                 retry=0,
                 use_pool=False,
                 pool_size=8,
                 logger=None,
                 headers=None):
        """Initialize AstakosClient Class

        Keyword arguments:
        token       -- user's/service's token (string)
        auth_url    -- i.e https://accounts.example.com/identity/v2.0
        retry       -- how many time to retry (integer)
        use_pool    -- use objpool for http requests (boolean)
        pool_size   -- if using pool, define the pool size
        logger      -- pass a different logger

        """

        # Get logger
        if logger is None:
            logger = logging.getLogger("astakosclient")
            logger.setLevel(logging.INFO)
        logger.debug(
            "Intialize AstakosClient: auth_url = %s, "
            "use_pool = %s, pool_size = %s", auth_url, use_pool, pool_size)

        # Check that token and auth_url (mandatory options) are given
        check_input("__init__", logger, token=token, auth_url=auth_url)

        # Initialize connection class
        parsed_auth_url = urlparse.urlparse(auth_url)
        conn_class = \
            scheme_to_class(parsed_auth_url.scheme, use_pool, pool_size)
        if conn_class is None:
            msg = "Unsupported scheme: %s" % parsed_auth_url.scheme
            logger.error(msg)
            raise BadValue(msg)

        # Save astakos base url, logger, connection class etc in our class
        self.retry = retry
        self.logger = logger
        self.token = token
        self.astakos_base_url = parsed_auth_url.netloc
        self.scheme = parsed_auth_url.scheme
        self.conn_class = conn_class
        if headers is not None:
            self.headers = copy(headers)
        else:
            self.headers = None

        # Initialize astakos api prefixes
        # API urls under auth_url
        self.auth_prefix = parsed_auth_url.path
        self.api_tokens = join_urls(self.auth_prefix, "tokens")
Exemplo n.º 7
0
    def get_membership(self, memb_id):
        """Retrieve membership description, if accessible

        Arguments:
        memb_id -- membership identifier

        In case of success, return membership description.
        """
        path = join_urls(self.api_memberships, str(memb_id))
        return self._call_astakos(path)
Exemplo n.º 8
0
    def get_application(self, app_id):
        """Retrieve application description, if accessible

        Arguments:
        app_id -- application identifier

        In case of success, return application description.
        """
        path = join_urls(self.api_applications, str(app_id))
        return self._call_astakos(path)
Exemplo n.º 9
0
    def get_project(self, project_id):
        """Retrieve project description, if accessible

        Arguments:
        project_id -- project identifier

        In case of success, return project description.
        """
        path = join_urls(self.api_projects, str(project_id))
        return self._call_astakos(path)
Exemplo n.º 10
0
    def get_application(self, app_id):
        """Retrieve application description, if accessible

        Arguments:
        app_id -- application identifier

        In case of success, return application description.
        """
        path = join_urls(self.api_applications, str(app_id))
        return self._call_astakos(path)
Exemplo n.º 11
0
    def application_action(self, app_id, action, reason=""):
        """Perform action on an application

        Arguments:
        app_id -- application identifier
        action -- action to perform, one of "approve", "deny",
                  "dismiss", "cancel"
        reason -- reason of performing the action

        In case of success, return nothing.
        """
        path = join_urls(self.api_applications, str(app_id))
        path = join_urls(path, "action")
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request({action: reason}, self.logger)
        return self._call_astakos(path,
                                  headers=req_headers,
                                  body=req_body,
                                  method="POST")
Exemplo n.º 12
0
    def get_membership(self, memb_id):
        """Retrieve membership description, if accessible

        Arguments:
        memb_id -- membership identifier

        In case of success, return membership description.
        """
        path = join_urls(self.api_memberships, str(memb_id))
        return self._call_astakos(path)
Exemplo n.º 13
0
    def get_project(self, project_id):
        """Retrieve project description, if accessible

        Arguments:
        project_id -- project identifier

        In case of success, return project description.
        """
        path = join_urls(self.api_projects, str(project_id))
        return self._call_astakos(path)
Exemplo n.º 14
0
    def modify_project(self, project_id, specs):
        """Submit application to modify an existing project

        Arguments:
        project_id -- project identifier
        specs      -- dict describing a project

        In case of success, return project and application identifiers.
        """
        path = join_urls(self.api_projects, str(project_id))
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request(specs, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="POST")
Exemplo n.º 15
0
    def modify_project(self, project_id, specs):
        """Submit application to modify an existing project

        Arguments:
        project_id -- project identifier
        specs      -- dict describing a project

        In case of success, return project and application identifiers.
        """
        path = join_urls(self.api_projects, str(project_id))
        req_headers = {'content-type': 'application/json'}
        req_body = parse_request(specs, self.logger)
        return self._call_astakos(path, headers=req_headers,
                                  body=req_body, method="PUT")
Exemplo n.º 16
0
    def __init__(self, token, auth_url,
                 retry=0, use_pool=False, pool_size=8, logger=None):
        """Initialize AstakosClient Class

        Keyword arguments:
        token       -- user's/service's token (string)
        auth_url    -- i.e https://accounts.example.com/identity/v2.0
        retry       -- how many time to retry (integer)
        use_pool    -- use objpool for http requests (boolean)
        pool_size   -- if using pool, define the pool size
        logger      -- pass a different logger

        """

        # Get logger
        if logger is None:
            logger = logging.getLogger("astakosclient")
            logger.setLevel(logging.INFO)
        logger.debug("Intialize AstakosClient: auth_url = %s, "
                     "use_pool = %s, pool_size = %s",
                     auth_url, use_pool, pool_size)

        # Check that token and auth_url (mandatory options) are given
        check_input("__init__", logger, token=token, auth_url=auth_url)

        # Initialize connection class
        parsed_auth_url = urlparse.urlparse(auth_url)
        conn_class = \
            scheme_to_class(parsed_auth_url.scheme, use_pool, pool_size)
        if conn_class is None:
            msg = "Unsupported scheme: %s" % parsed_auth_url.scheme
            logger.error(msg)
            raise BadValue(msg)

        # Save astakos base url, logger, connection class etc in our class
        self.retry = retry
        self.logger = logger
        self.token = token
        self.astakos_base_url = parsed_auth_url.netloc
        self.scheme = parsed_auth_url.scheme
        self.conn_class = conn_class

        # Initialize astakos api prefixes
        # API urls under auth_url
        self.auth_prefix = parsed_auth_url.path
        self.api_tokens = join_urls(self.auth_prefix, "tokens")
Exemplo n.º 17
0
    def validate_token(self, token_id, belongs_to=None):
        """ Validate a temporary access token (oath2)

        Keyword arguments:
        belongsTo         -- confirm that token belongs to tenant

        It returns back the token as well as information about the token
        holder.

        The belongs_to is optional and if it is given it must be inside the
        token's scope.

        In case of error raise an AstakosClientException.

        """
        path = join_urls(self.api_tokens, str(token_id))
        if belongs_to is not None:
            params = {'belongsTo': belongs_to}
            path = '%s?%s' % (path, urllib.urlencode(params))
        return self._call_astakos(path, method="GET", log_body=False)
Exemplo n.º 18
0
    def validate_token(self, token_id, belongs_to=None):
        """ Validate a temporary access token (oath2)

        Keyword arguments:
        belongsTo         -- confirm that token belongs to tenant

        It returns back the token as well as information about the token
        holder.

        The belongs_to is optional and if it is given it must be inside the
        token's scope.

        In case of error raise an AstakosClientException.

        """
        path = join_urls(self.api_tokens, str(token_id))
        if belongs_to is not None:
            params = {'belongsTo': belongs_to}
            path = '%s?%s' % (path, urllib.urlencode(params))
        return self._call_astakos(path, method="GET", log_body=False)
Exemplo n.º 19
0
 def api_usercatalogs(self):
     return join_urls(self.account_prefix, "user_catalogs")
Exemplo n.º 20
0
 def api_commissions_action(self):
     return join_urls(self.api_commissions, "action")
Exemplo n.º 21
0
 def api_feedback(self):
     return join_urls(self.account_prefix, "feedback")
Exemplo n.º 22
0
 def api_feedback(self):
     return join_urls(self.account_prefix, "feedback")
Exemplo n.º 23
0
 def api_quotas(self):
     return join_urls(self.account_prefix, "quotas")
Exemplo n.º 24
0
 def api_commissions(self):
     return join_urls(self.account_prefix, "commissions")
Exemplo n.º 25
0
 def api_memberships(self):
     return join_urls(self.api_projects, "memberships")
Exemplo n.º 26
0
 def api_oauth2_auth(self):
     return join_urls(self.oauth2_prefix, "auth")
Exemplo n.º 27
0
 def api_memberships(self):
     return join_urls(self.api_projects, "memberships")
Exemplo n.º 28
0
 def api_applications(self):
     return join_urls(self.api_projects, "apps")
Exemplo n.º 29
0
 def api_service_usercatalogs(self):
     return join_urls(self.account_prefix, "service/user_catalogs")
Exemplo n.º 30
0
 def api_getservices(self):
     return join_urls(self.ui_prefix, "get_services")
Exemplo n.º 31
0
 def api_oauth2_auth(self):
     return join_urls(self.oauth2_prefix, "auth")
Exemplo n.º 32
0
 def api_service_usercatalogs(self):
     return join_urls(self.account_prefix, "service/user_catalogs")
Exemplo n.º 33
0
 def api_commissions(self):
     return join_urls(self.account_prefix, "commissions")
Exemplo n.º 34
0
 def api_resources(self):
     return join_urls(self.account_prefix, "resources")
Exemplo n.º 35
0
try:
    import unittest2 as unittest
except ImportError:
    if sys.version_info < (2, 7):
        raise Exception("The unittest2 package is required for Python < 2.7")
    import unittest


# --------------------------------------------------------------------
# Helper functions
auth_url = "https://example.org/identity/v2.0"
account_prefix = "/account_prefix"
ui_prefix = "/ui_prefix"
oauth2_prefix = "/oauth2"
api_tokens = "/identity/v2.0/tokens"
api_usercatalogs = join_urls(account_prefix, "user_catalogs")
api_resources = join_urls(account_prefix, "resources")
api_quotas = join_urls(account_prefix, "quotas")
api_commissions = join_urls(account_prefix, "commissions")

# --------------------------------------
# Local users
token = {
    'id': "skzleaFlBl+fasFdaf24sx",
    'tenant': {
        'id': "73917abc-abcd-477e-a1f1-1763abcdefab",
        'name': "Example User One",
        },
    }

user = {
Exemplo n.º 36
0
 def api_service_project_quotas(self):
     return join_urls(self.account_prefix, "service_project_quotas")
Exemplo n.º 37
0
 def api_applications(self):
     return join_urls(self.api_projects, "apps")
Exemplo n.º 38
0
 def api_commissions_action(self):
     return join_urls(self.api_commissions, "action")
Exemplo n.º 39
0
 def api_projects(self):
     return join_urls(self.account_prefix, "projects")
Exemplo n.º 40
0
 def api_projects(self):
     return join_urls(self.account_prefix, "projects")
Exemplo n.º 41
0
 def api_oauth2_token(self):
     return join_urls(self.oauth2_prefix, "token")
Exemplo n.º 42
0
 def api_getservices(self):
     return join_urls(self.ui_prefix, "get_services")
Exemplo n.º 43
0
 def api_quotas(self):
     return join_urls(self.account_prefix, "quotas")
Exemplo n.º 44
0
 def api_oauth2_token(self):
     return join_urls(self.oauth2_prefix, "token")
Exemplo n.º 45
0
 def api_service_quotas(self):
     return join_urls(self.account_prefix, "service_quotas")
Exemplo n.º 46
0
 def api_usercatalogs(self):
     return join_urls(self.account_prefix, "user_catalogs")
Exemplo n.º 47
0
 def api_resources(self):
     return join_urls(self.account_prefix, "resources")
Exemplo n.º 48
0
# Use backported unittest functionality if Python < 2.7
try:
    import unittest2 as unittest
except ImportError:
    if sys.version_info < (2, 7):
        raise Exception("The unittest2 package is required for Python < 2.7")
    import unittest

# --------------------------------------------------------------------
# Helper functions
auth_url = "https://example.org/identity/v2.0"
account_prefix = "/account_prefix"
ui_prefix = "/ui_prefix"
oauth2_prefix = "/oauth2"
api_tokens = "/identity/v2.0/tokens"
api_usercatalogs = join_urls(account_prefix, "user_catalogs")
api_resources = join_urls(account_prefix, "resources")
api_quotas = join_urls(account_prefix, "quotas")
api_commissions = join_urls(account_prefix, "commissions")

# --------------------------------------
# Local users
token = {
    'id': "skzleaFlBl+fasFdaf24sx",
    'tenant': {
        'id': "73917abc-abcd-477e-a1f1-1763abcdefab",
        'name': "Example User One",
    },
}

user = {
Exemplo n.º 49
0
try:
    import unittest2 as unittest
except ImportError:
    if sys.version_info < (2, 7):
        raise Exception("The unittest2 package is required for Python < 2.7")
    import unittest


# --------------------------------------------------------------------
# Helper functions
auth_url = "https://example.org/identity/v2.0"
account_prefix = "/account_prefix"
ui_prefix = "/ui_prefix"
oauth2_prefix = "/oauth2"
api_tokens = "/identity/v2.0/tokens"
api_usercatalogs = join_urls(account_prefix, "user_catalogs")
api_resources = join_urls(account_prefix, "resources")
api_quotas = join_urls(account_prefix, "quotas")
api_commissions = join_urls(account_prefix, "commissions")

# --------------------------------------
# Local users
token = {
    'id': "skzleaFlBl+fasFdaf24sx",
    'tenant': {
        'id': "73917abc-abcd-477e-a1f1-1763abcdefab",
        'name': "Example User One",
        },
    }

user = {