def generate_template_args()

in iact3/config.py [0:0]


    def generate_template_args(self) -> dict:
        result = self.to_dict()
        if self.template_id or self.template_body:
            return result

        if self.template_url:
            template_url = self.template_url
            components = urlparse(template_url)
            if components.scheme in ('oss', 'http', 'https'):
                return result
            elif components.scheme == 'file':
                try:
                    tpl_body = urlopen(template_url).read()
                    result[TEMPLATE_BODY] = tpl_body.decode('utf-8')
                    result.pop(TEMPLATE_URL)
                    return result
                except Exception as ex:
                    raise Iact3Exception(f'failed to retrieve {template_url}: {ex}')
            else:
                raise Iact3Exception(f'template url {template_url} is not legally.')

        tpl_path = result.pop(TEMPLATE_LOCATION, None)
        tpl_item = self._get_template_location(tpl_path)
        if tpl_item is None:
            msg = f'Could not find template in {tpl_path or DEFAULT_TEMPLATE_PATH} directory' \
                  f'Template files need end with .template.json or .template.yaml or .template.yml.'
            raise Iact3Exception(msg)
        elif isinstance(tpl_item, dict):
            result[TEMPLATE_BODY] = json.dumps(tpl_item)
        else:
            file_path = Path(tpl_item).expanduser().resolve()
            if not file_path.is_file():
                return result
            try:
                with open(str(file_path), 'r', encoding='utf-8') as file_handle:
                    tpl_body = yaml.load(file_handle, Loader=CustomSafeLoader)
                    result[TEMPLATE_BODY] = json.dumps(tpl_body)
            except Exception as e:
                LOG.debug(str(e), exc_info=True)
                raise Iact3Exception(f'can not find a template: {str(e)}')
        return result