コード例 #1
0
    def _get_request_body_param(self):
        if not self.__topic_urn:
            raise SMNException("param", "topic_urn is None")
        if not (self.__csp_to_domainids or self.__csp_to_services):
            raise SMNException("param", "both domain_id and servcie is None")

        policy_map = deepcopy(self.__policy_map)
        user_statement = deepcopy(self.__user_statement)
        service_statement = deepcopy(self.__service_statement)

        if self.__csp_to_domainids == "*":
            user_principal = {"CSP": "*"}
            user_statement["Principal"] = user_principal
            user_statement["Resource"] = self.__topic_urn
            policy_map["Statement"].append(user_statement)
        elif self.__csp_to_domainids:
            user_principal = {"CSP": self.__csp_to_domainids}
            user_statement["Principal"] = user_principal
            user_statement["Resource"] = self.__topic_urn
            policy_map["Statement"].append(user_statement)
        else:
            pass

        if self.__csp_to_services:
            service_principal = {"Service": self.__csp_to_services}
            service_statement["Principal"] = service_principal
            service_statement["Resource"] = self.__topic_urn
            policy_map["Statement"].append(service_statement)

        return {"value": json.dumps(policy_map)}
コード例 #2
0
 def get_uri(self):
     uri = CommonRequest.get_uri(self)
     if not uri:
         raise SMNException("param", "topic_urn need to set.")
     if not self.attribute_name:
         raise SMNException("param", "attribute_name need to set.")
     return uri + self.attribute_name
コード例 #3
0
    def get_request_body_param(self):
        body_param = CommonRequest.get_request_body_param(self)
        if not body_param.__contains__('sign_id'):
            raise SMNException("param", "sign_id must be set.")

        if not body_param.__contains__('sms_template_id'):
            raise SMNException("param", "sms_template_id must be set.")

        if not body_param.__contains__('endpoints'):
            raise SMNException("param", "endpoints must be set.")
        return body_param
コード例 #4
0
    def authrize_to_users(self, domain_id_list):
        if type(domain_id_list) != list:
            raise SMNException("param", "domain_id_list must be list")

        if self.__csp_to_domainids is None:
            pass
        else:
            self.__csp_to_domainids = self.__csp_to_domainids + [
                'urn:csp:iam::' + domain_id + ':root'
                for domain_id in domain_id_list
            ]
コード例 #5
0
    def _get_project_id(self):
        '''get project id by ak/sk or ak/sk/securitytoken'''

        header = {"content-type": "application/json"}
        response = self._get_response('GET',
                                      self.__iam_endpoint,
                                      self.PROJECT_ID_URI,
                                      header,
                                      query={"name": self.__region_id})
        message_map = json.loads(response[2])
        try:
            project_id = message_map['projects'][0]['id']
        except Exception:
            raise SMNException(response[0], response[2])

        if project_id is None or len(project_id) == 0:
            raise SMNException(
                response[0],
                'Failed to get project id by aksk auth. project_id is null.')
        return project_id
コード例 #6
0
 def authrize_to_services(self, services_list):
     if type(services_list) != list:
         raise SMNException("param", "services_list must be list")
     self.__csp_to_services = self.__csp_to_services + [
         service for service in services_list
     ]
コード例 #7
0
 def set_protocol(self, protocol):
     if not valid_protocol(protocol):
         raise SMNException("param", "protocol is not support.")
     self.add_request_body_param('protocol', protocol)
コード例 #8
0
 def set_remark(self, remark):
     remark_len = len(remark.encode('utf-8'))
     if (remark_len > REMARK_LENGTH):
         raise SMNException("param", "remark is exceed 128 byte.")
     self.add_request_body_param("remark", remark)
コード例 #9
0
 def set_endpoint(self, endpoint):
     protocol = protocol_helper.get_protocol_type(endpoint)
     if protocol is None:
         raise SMNException("param", "endpoint is invalid.")
     self._set_protocol(protocol)
     self.add_request_body_param("endpoint", endpoint)
コード例 #10
0
 def set_subject(self, subject):
     subject_bytes = subject.encode('utf-8')
     if (len(subject_bytes) > MAX_SUBJECT_LENGTH):
         raise SMNException("param", "subject byte length excced 512 bytes")
     self.add_request_body_param("subject", subject)
コード例 #11
0
ファイル: SmsPublish.py プロジェクト: wxp0329/smn-sdk-python
 def get_request_body_param(self):
     body_param = CommonRequest.get_request_body_param(self)
     if body_param.__contains__('sign_id'):
         return body_param
     else:
         raise SMNException("param", "sign_id must be set.")
コード例 #12
0
ファイル: SmsPublish.py プロジェクト: wxp0329/smn-sdk-python
 def set_endpoint(self, endpoint):
     is_sms = get_protocol_type(endpoint)
     if is_sms != 'sms':
         raise SMNException("param", "telephone endpoint is invalid")
     self.add_request_body_param('endpoint', endpoint)