@@ -65,6 +65,37 @@ def get_config(self, request):
6565
6666 cfg = self .app .config .as_dict ()
6767
68+ # prepare certain config values for json
69+ # These guards/conversions should be done transparently in
70+ # Config class
71+ cfg ['gui' ]['is_first_launch' ] = cfg ['gui' ]['is_first_launch' ] in ('1' ,)
72+
73+ return JSONResponse (cfg )
74+
75+ @asyncio .coroutine
76+ @require_auth_token
77+ def patch_config (self , request ):
78+
79+ content = yield from request .content .read ()
80+ params = json .loads (content .decode ())
81+
82+ with self .app .config .update_context ():
83+ for obj_key , obj in params .items ():
84+ for key , value in obj .items ():
85+ setting = '{0}.{1}' .format (obj_key , key )
86+ logger .debug ('Setting %s.%s to %s' , obj_key , key , value )
87+
88+ # These guards/conversions should be done transparently in
89+ # Config class
90+ if setting == 'gui.is_first_launch' :
91+ value = '1' if value else '0'
92+
93+ self .app .config .set (setting , value )
94+
95+ return (yield from self .get_config (request ))
96+
97+ cfg = self .app .config .as_dict ()
98+
6899 # prepare certain config values for json
69100 cfg ['gui' ]['is_first_launch' ] = cfg ['gui' ]['is_first_launch' ] in ('1' , 'yes' )
70101
@@ -213,6 +244,7 @@ def start(self):
213244
214245 self .web_app .router .add_route ('GET' , '/v1/stats/' , self .get_stats )
215246 self .web_app .router .add_route ('GET' , '/v1/config/' , self .get_config )
247+ self .web_app .router .add_route ('PATCH' , '/v1/config/' , self .patch_config )
216248 self .web_app .router .add_route ('GET' , '/v1/pull' , self .get_pull )
217249 self .web_app .router .add_route ('GET' , '/v1/push' , self .get_push )
218250
0 commit comments