File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 15
15
# limitations under the License.
16
16
#
17
17
18
+ import os
18
19
import click
19
20
20
21
from apisix .runner .server .server import Server as NewServer
@@ -31,7 +32,7 @@ def runner() -> None:
31
32
32
33
@runner .command ()
33
34
def start () -> None :
34
- config = NewConfig ()
35
+ config = NewConfig (os . path . dirname ( os . path . abspath ( __file__ )) )
35
36
server = NewServer (config )
36
37
server .receive ()
37
38
Original file line number Diff line number Diff line change @@ -79,15 +79,17 @@ def level(self, level: str) -> None:
79
79
80
80
class Config :
81
81
82
- def __init__ (self , config_name : str = "config.yaml" ):
82
+ def __init__ (self , config_path : str = "" , config_name : str = "config.yaml" ):
83
83
"""
84
84
init config
85
+ :param config_path:
86
+ local config file path
85
87
:param config_name:
86
88
local config file name
87
89
"""
88
90
self .socket = _ConfigSocket ()
89
91
self .logging = _ConfigLogging ()
90
- self ._loading_config (config_name )
92
+ self ._loading_config (config_path , config_name )
91
93
92
94
@staticmethod
93
95
def _get_env_config (config : str ):
@@ -101,13 +103,17 @@ def _get_env_config(config: str):
101
103
return os .getenv (env_name )
102
104
return config
103
105
104
- def _loading_config (self , config_name : str ):
106
+ def _loading_config (self , config_path : str , config_name : str ):
105
107
"""
106
108
load local configuration file
109
+ :param config_path:
107
110
:param config_name:
108
111
:return:
109
112
"""
110
- abs_path = os .path .dirname (os .path .dirname (os .path .dirname (__file__ )))
113
+ if len (config_path ) and os .path .exists (config_path ):
114
+ abs_path = config_path
115
+ else :
116
+ abs_path = os .path .dirname (os .path .dirname (os .path .dirname (__file__ )))
111
117
cf_path = "%s/%s" % (abs_path , config_name )
112
118
if not os .path .exists (cf_path ):
113
119
print ("ERR: config file `%s` not exists" % cf_path )
Original file line number Diff line number Diff line change 15
15
# limitations under the License.
16
16
#
17
17
18
+ import os
18
19
import logging
19
20
from apisix .runner .server .config import Config as NewServerConfig
20
21
21
22
22
- def test_config ():
23
+ def test_config_default ():
23
24
config = NewServerConfig ()
24
25
25
26
config .logging .level = "INFO"
@@ -36,3 +37,22 @@ def test_config():
36
37
37
38
config .socket .file = "/test/runner.sock"
38
39
assert config .socket .file == "/test/runner.sock"
40
+
41
+
42
+ def test_config_custom ():
43
+ config = NewServerConfig ("%s/apisix" % os .path .abspath (os .path .join (os .getcwd ())), "config.yaml" )
44
+
45
+ config .logging .level = "NOTSET"
46
+ assert config .logging .level == logging .NOTSET
47
+
48
+ config .logging .level = "INFO"
49
+ assert config .logging .level == logging .INFO
50
+
51
+ config .logging .level = "ERROR"
52
+ assert config .logging .level == logging .ERROR
53
+
54
+ config .logging .level = "WARN"
55
+ assert config .logging .level == logging .WARNING
56
+
57
+ config .socket .file = "/test/runner.sock"
58
+ assert config .socket .file == "/test/runner.sock"
You can’t perform that action at this time.
0 commit comments