Exemplo n.º 1
0
    def status(self):
        """
        Demo/debug-oriented function, to display the information of all controlled resources
        """
        pat = self.oidch.get_new_pat()
        resource_reg_endpoint = self.wkh.get(
            TYPE_UMA_V2, KEY_UMA_V2_RESOURCE_REGISTRATION_ENDPOINT)
        actual_resources = resource.list(pat, resource_reg_endpoint,
                                         self.verify)

        print("-----------STATUS-----------")
        print(
            str(len(self.registered_resources)) +
            " Locally cached resources, with IDS: " +
            str(self.registered_resources))
        print(
            str(len(actual_resources)) +
            " Actual Resources registered in the AS, with IDS: " +
            str(actual_resources))
        print("-----------LIVE INFORMATION FROM AS------")
        for r in actual_resources:
            info = resource.read(pat,
                                 resource_reg_endpoint,
                                 r,
                                 secure=self.verify)
            print(info)
            print("++++++++++++++++")
        print("-----------STATUS END-------")
Exemplo n.º 2
0
 def get_resource(self, resource_id: str):
     """
     Returns the matching resource for resource_id or None if not found
     """
     pat = self.oidch.get_new_pat()
     resource_reg_endpoint = self.wkh.get(
         TYPE_UMA_V2, KEY_UMA_V2_RESOURCE_REGISTRATION_ENDPOINT)
     data = resource.read(pat, resource_reg_endpoint, resource_id,
                          self.verify)
     if "_id" in data and data["_id"] == resource_id:
         return data
     return None
Exemplo n.º 3
0
    def resource_exists(self, icon_uri: str):
        """
        Checks if the resources managed already contain a resource with that URI.
        Returns the matching (resource_id, scopes) or None if not found
        """
        pat = self.oidch.get_new_pat()
        resource_reg_endpoint = self.wkh.get(
            TYPE_UMA_V2, KEY_UMA_V2_RESOURCE_REGISTRATION_ENDPOINT)
        r = self.mongo.get_id_from_uri(icon_uri)
        if not r: return False
        data = resource.read(pat, resource_reg_endpoint, r, self.verify)
        if "icon_uri" in data and data["icon_uri"] == icon_uri:
            return True

        return False
Exemplo n.º 4
0
    def resource_exists(self, icon_uri: str) -> (str, str):
        """
        Checks if the resources managed already contain a resource with that URI.

        Returns the matching (resource_id, scopes) or None if not found
        """
        self.update_resources_from_as()
        pat = self.oidch.get_new_pat()
        resource_reg_endpoint = self.wkh.get(
            TYPE_UMA_V2, KEY_UMA_V2_RESOURCE_REGISTRATION_ENDPOINT)
        for r in self.registered_resources:
            data = resource.read(pat, resource_reg_endpoint, r, self.verify)
            #if "icon_uri" in data and data["icon_uri"] == icon_uri:
            if "icon_uri" in data:  #Default behavior for demo purposes
                return data["_id"], data["resource_scopes"]

        return None, None