Delete gateway_proxy directory (#10)
diff --git a/gateway_proxy/.gitignore b/gateway_proxy/.gitignore
deleted file mode 100644
index a08668f..0000000
--- a/gateway_proxy/.gitignore
+++ /dev/null
@@ -1,30 +0,0 @@
-__pycache__/
-*.py[cod]
-
-# Distribution / packaging
-bin/
-build/
-develop-eggs/
-dist/
-eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-
-# Unit test / coverage reports
-.tox/
-.coverage
-.cache
-nosetests.xml
-coverage.xml
-
-*.log
-*.pot
-
-# vscode
-.vscode/
\ No newline at end of file
diff --git a/gateway_proxy/gateway_proxy/__init__.py b/gateway_proxy/gateway_proxy/__init__.py
deleted file mode 100644
index d996748..0000000
--- a/gateway_proxy/gateway_proxy/__init__.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-__project__ = "gateway-proxy"
-__author__ = "https://shenyu.apache.org"
-
-
-def get_help():
- print("Please contact author:{}".format(__author__))
-
-
-def get_doc():
- print("detail document: ")
-
-
-
-
diff --git a/gateway_proxy/gateway_proxy/api.py b/gateway_proxy/gateway_proxy/api.py
deleted file mode 100644
index 1ee70b9..0000000
--- a/gateway_proxy/gateway_proxy/api.py
+++ /dev/null
@@ -1,229 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-import requests
-from requests.exceptions import (ReadTimeout, RequestException, ConnectTimeout)
-
-from gateway_proxy.gateway_proxy.config import GatewayConfig, ALL_ENV
-from gateway_proxy.gateway_proxy.exception import (EnvTypeExp, SetUpUriExp, SetUpRegisterExp,
- SetUpGatewayExp, GetRegisterTokenErr)
-
-
-class GatewayProxy(object):
- """
- gateway proxy class
- """
- def __init__(self):
- self.headers = {"Content-Type": "application/json;charset=UTF-8"}
- self.env = GatewayConfig.uri.get("environment")
- if not isinstance(self.env, str) or self.env not in ALL_ENV:
- raise EnvTypeExp(env=self.env)
- self.register_token = None
- self._set_up_gateway_service_url()
- self._setup_uri_params()
- self._setup_register_params()
- self._get_register_token()
- if not self.register_token:
- raise GetRegisterTokenErr(msg="can't get register token")
- else:
- self.headers.update({"X-Access-Token": self.register_token})
-
- def _set_up_gateway_service_url(self):
- try:
- self.gateway_base_urls = GatewayConfig.__dict__.get(self.env, {}).get("servers", "").split(",")
- self.port = GatewayConfig.__dict__.get(self.env, {}).get("port")
- url_pre = "http://{}:{}"
- self.gateway_base_urls = [url_pre.format(_url, self.port) for _url in self.gateway_base_urls]
- self.register_meta_data_suffix = "/gateway-shenyu/register-metadata"
- self.register_uri_suffix = "/gateway-shenyu/register-uri"
-
- self.register_meta_data_path_list = [_url + self.register_meta_data_suffix for _url in
- self.gateway_base_urls]
- self.register_uri_list = [_url + self.register_uri_suffix for _url in self.gateway_base_urls]
- except SetUpGatewayExp as sue:
- raise SetUpUriExp(app_name=GatewayConfig.uri.get("app_name"), msg=str(sue), env=self.env)
-
- def _setup_uri_params(self):
- """
- setup uri params
- """
- try:
- self.host = GatewayConfig.uri.get("host")
- self.port = GatewayConfig.uri.get("port")
- self.app_name = GatewayConfig.uri.get("app_name")
- self.rpc_type = GatewayConfig.uri.get("rpc_type")
- self.context_path = GatewayConfig.uri.get("context_path")
- self.register_type = GatewayConfig.register.get("register_type")
- self.register_servers = GatewayConfig.register.get("register_servers")
- except SetUpUriExp as se:
- raise SetUpUriExp(app_name=GatewayConfig.uri.get("app_name"), msg=str(se), env=self.env)
-
- def _setup_register_params(self):
- """
- setup register params
- """
- try:
- self.register_token_type = GatewayConfig.register.get("register_type")
- self.register_base_servers = GatewayConfig.register.get("servers").split(",")
- self.register_path = "/platform/login"
- self.register_token_servers = [_url + self.register_uri_suffix for _url in self.register_base_servers]
- self.register_username = GatewayConfig.register.get("props", {}).get("username")
- self.register_password = GatewayConfig.register.get("props", {}).get("password")
- except SetUpRegisterExp as se:
- raise SetUpRegisterExp(app_name=GatewayConfig.uri.get("app_name"), msg=str(se), env=self.env)
-
- def _request(self, url, json_data):
- """
- base post request
- """
- if not url or not isinstance(url, str) or not isinstance(json_data, dict):
- print("_request url or data format error")
- return False
- try:
- res = requests.post(url, json=json_data, headers=self.headers, timeout=5)
- status_code = res.status_code
- msg = res.text
- except ConnectTimeout as ce:
- print("connect timeout, detail is:{}".format(str(ce)))
- return False
- except ReadTimeout as rte:
- print("read time out, detail is:{}".format(str(rte)))
- return False
- except RequestException as rqe:
- print("request except, detail is:{}".format(str(rqe)))
- return False
- except Exception as e:
- print("request ({}) except, detail is:{}".format(url, str(e)))
- return False
- else:
- # According to the interface return value of the gateway registry, the request is considered successful
- # only when msg==success; if the interface return value of the gateway registry changes, the judgment
- # method should also be modified
- if msg == "success":
- return True
- print("request ({}) fail, status code is:{}, msg is:{}".format(res.url, status_code, msg))
- return False
-
- def _get_register_token(self):
- """
- base get http request
- """
- default_res = ""
- params = {
- "userName": self.register_username,
- "password": self.register_password
- }
- try:
- for url in self.register_token_servers:
- res = requests.get(url, params=params, timeout=5)
- status_code = res.status_code
- res_data = res.json()
- token = res_data.get("data", {}).get("token", "")
- if token:
- self.register_token = token
- break
- except ConnectTimeout as ce:
- print("connect timeout, detail is:{}".format(str(ce)))
- return False
- except ReadTimeout as rte:
- print("read time out, detail is:{}".format(str(rte)))
- return False
- except RequestException as rqe:
- print("request except, detail is:{}".format(str(rqe)))
- return False
- except Exception as e:
- print("get register token except, detail is:{}".format(str(e)))
- return False
-
- def register_uri(self):
- """
- register uri
- """
- json_data = {
- "appName": self.app_name,
- "contextPath": self.context_path,
- "rpcType": self.rpc_type,
- "host": self.host,
- "port": self.port
- }
- register_flag = False
- for _url in self.register_uri_list:
- res = self._request(_url, json_data)
- if not res:
- continue
- else:
- print("[SUCCESS], register uri success, register data is:{}".format(str(json_data)))
- register_flag = True
- break
- if not register_flag:
- print("[ERROR], register uri fail, app_name is:{}, host is:{}, port is:{}".format(self.app_name,
- self.host,
- self.port))
- return register_flag
-
- def register_metadata(self, **kwargs):
- """
- register path to gateway
- path: The path needs to be unique, for example, your path is: /order/findById, your request prefix
- is: /hello, the path must be /hello/order/findById
- register_all Register all paths ?
- rule_name: Can be the same as path
- enabled: Whether to open, If you want to open the gateway proxy, you must fill in True
- path_desc: Path description, optional filling
- register_meta_data: Need to register metadata, not for http request, fill in false
- """
- if not kwargs.get("register_all") and not kwargs.get("path"):
- return False
-
- register_all = kwargs.get("register_all", False)
- path = kwargs.get("path", "")
- rule_name = kwargs.get("rule_name", "")
- enabled = kwargs.get("enabled", True)
- path_desc = kwargs.get("path_desc", "")
- register_meta_data = kwargs.get("register_meta_data", False)
- if register_all:
- path = self.context_path + "**" if self.context_path.endswith("/") else self.context_path + "/**"
- rule_name = path if not rule_name else rule_name
- json_data = {
- "appName": self.app_name,
- "contextPath": self.context_path,
- "path": path,
- "pathDesc": path_desc,
- "rpcType": self.rpc_type,
- "ruleName": rule_name,
- "enabled": enabled,
- "registerMetaData": register_meta_data,
- "pluginNames": []
-
- }
- register_flag = False
- for _url in self.register_meta_data_path_list:
- res = self._request(_url, json_data)
- if not res:
- continue
- else:
- print("[SUCCESS], register metadata success, register data is:{}".format(str(json_data)))
- register_flag = True
- break
- if not register_flag:
- print("[ERROR],register metadata fail, app_name:{}, path:{}, contextPath:{}".format(self.app_name,
- path,
- self.context_path))
- return register_flag
diff --git a/gateway_proxy/gateway_proxy/config.py b/gateway_proxy/gateway_proxy/config.py
deleted file mode 100644
index 46aeec5..0000000
--- a/gateway_proxy/gateway_proxy/config.py
+++ /dev/null
@@ -1,63 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-ALL_ENV = ("test", "pre", "prod")
-
-
-class GatewayConfig:
- """
- If there are multiple gateway registry servers, separated by commas,
- for example: "servers": "10.11.12.12,10.11.12.13"
- """
- # Now only HTTP mode is supported
-
- register_type = "http"
-
- test = {
- "servers": "xx.xx.xx.xx",
- "port": 1001
- }
- pre = {
- "servers": "xx.xx.xx.xx",
- "port": 1001
- }
- prod = {
- "servers": "xx.xx.xx.xx",
- "port": 1001
- }
-
- register = {
- "register_type": "http",
- "servers": "xx.xx.xx.xx",
- "props": {
- "username": "admin",
- "password": "123456"
- }
- }
-
- # Items of configuration that need to be modified according to the project
- uri = {
- "app_name": "app1", # app name
- "host": "127.0.0.1", # python service host
- "port": 8000, # python service port
- "context_path": "/xxx", # context_path
- "environment": "test", # environment
- "rpc_type": register_type # rpc type
- }
diff --git a/gateway_proxy/gateway_proxy/exception.py b/gateway_proxy/gateway_proxy/exception.py
deleted file mode 100755
index 57c3add..0000000
--- a/gateway_proxy/gateway_proxy/exception.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-class GatewayProxyBaseExp(Exception):
- def __init__(self, app_name="", path="", msg="", env=""):
- self.app_name = app_name
- self.path = path
- self.msg = msg
- self.env = env
-
- def __str__(self):
- return "Gateway Proxy Exception, app_name:{}, path is:({}), msg:{}".format(self.app_name, self.path, self.msg)
-
- def __repr__(self):
- return self.__str__()
-
-
-class EnvTypeExp(GatewayProxyBaseExp):
- pass
-
-
-class SetUpUriExp(GatewayProxyBaseExp):
- pass
-
-
-class SetUpRegisterExp(GatewayProxyBaseExp):
- pass
-
-
-class GetRegisterTokenErr(GatewayProxyBaseExp):
- pass
-
-
-class SetUpGatewayExp(GatewayProxyBaseExp):
- pass
-
-
-class RegisterUriExp(GatewayProxyBaseExp):
- pass
-
-
-class RegisterMetaDataExp(GatewayProxyBaseExp):
- pass
-
-
-class RegisterAllMetaDataExp(GatewayProxyBaseExp):
- pass
diff --git a/gateway_proxy/gateway_proxy/main.py b/gateway_proxy/gateway_proxy/main.py
deleted file mode 100644
index 6623e9a..0000000
--- a/gateway_proxy/gateway_proxy/main.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
\ No newline at end of file
diff --git a/gateway_proxy/gateway_proxy/register.py b/gateway_proxy/gateway_proxy/register.py
deleted file mode 100644
index 6638a61..0000000
--- a/gateway_proxy/gateway_proxy/register.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-from copy import deepcopy
-from functools import wraps
-
-from gateway_proxy.gateway_proxy.api import GatewayProxy
-from gateway_proxy.gateway_proxy.exception import (RegisterUriExp, RegisterMetaDataExp, RegisterAllMetaDataExp)
-
-
-def register_uri(func):
- @wraps(func)
- def _register_uri():
- try:
- gt = GatewayProxy()
- gt.register_uri()
- func()
- except RegisterUriExp as e:
- raise RegisterUriExp()
- except Exception as e:
- print("register_uri except, detail is:{}".format(str(e)))
- raise e
- return _register_uri
-
-
-def register_metadata(**kwargs):
- def register_decorator(func):
- @wraps(func)
- def _wrapped_register_metadata():
- try:
- gt = GatewayProxy()
- gt.register_metadata(**kwargs)
- func()
- except RegisterMetaDataExp as ee:
- raise ee
- except Exception as e:
- print("register_metadata except, detail is:{}".format(str(e)))
- raise e
- return _wrapped_register_metadata
- return register_decorator
-
-
-def register_all_metadata(**kwargs):
- def register_all_metadata_decorator(func):
- @wraps(func)
- def _wrapped_register_all_metadata():
- try:
- gt = GatewayProxy()
- _kwargs = deepcopy(kwargs)
- _kwargs.update({"register_all": True})
- gt.register_metadata(**_kwargs)
- func()
- except RegisterAllMetaDataExp as ee:
- raise ee
- except Exception as e:
- print("register_all_metadata except, detail is:{}".format(str(e)))
- raise e
- return _wrapped_register_all_metadata
- return register_all_metadata_decorator
diff --git a/gateway_proxy/setup.py b/gateway_proxy/setup.py
deleted file mode 100644
index 2564e42..0000000
--- a/gateway_proxy/setup.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-from setuptools import setup
-
-setup(
- name="gateway_proxy", # project name, pip3 install gateway_proxy
- version="0.1.0", # version
- author="https://shenyu.apache.org", # author
- author_email="https://shenyu.apache.org/zh/community", # email
- url="https://github.com/mutianzero/incubator-shenyu-client-python", # project repo url
- description="shenyu python proxy service sdk", # description
- packages=["gateway_proxy"], # packages name
- install_requires=["requests>=2.25.1", "PyYAML>=5.3"], # requires third packages
- python_requires=">=3.6", # python version condition
- entry_points={ # console scripts
- "console_scripts": [
- "gp-help=gateway_proxy:get_help",
- "gp-doc=gateway_proxy:get_doc"
- ]
- }
-)