#363 Add config endpoint
Merged a year ago by lucarval. Opened a year ago by lholecek.
lholecek/waiverdb add-extra-about-info  into  master

Add config endpoint
Lukas Holecek • a year ago  
file modified
+33
@@ -651,6 +651,39 @@ 

      assert output['auth_method'] == client.application.config['AUTH_METHOD']

  

  

+ def test_config_endpoint_permissions_map(client):

+     config = {

+         'PERMISSION_MAPPING': {

+             '^kernel-qe\\.': {

+                 'groups': ['devel', 'qa'],

+                 'users': [],

+             },

+             '': {

+                 'groups': ['factory2-admins'],

+                 'users': [],

+             },

+         }

+     }

+ 

+     with patch.dict(client.application.config, config):

+         r = client.get('/api/v1.0/config')

+ 

+     assert r.status_code == 200

+     assert r.json['permission_mapping'] == config['PERMISSION_MAPPING']

+ 

+ 

+ def test_config_endpoint_superusers(client):

+     config = {

+         'SUPERUSERS': ['alice', 'bob']

+     }

+ 

+     with patch.dict(client.application.config, config):

+         r = client.get('/api/v1.0/config')

+ 

+     assert r.status_code == 200

+     assert r.json['superusers'] == config['SUPERUSERS']

+ 

+ 

  def test_cors_good(client, session):

      headers = {

          'Access-Control-Request-Method': 'POST',

file modified
+35
@@ -629,6 +629,40 @@ 

          return {'version': __version__, 'auth_method': current_app.config['AUTH_METHOD']}

  

  

+ class ConfigResource(Resource):

+     @jsonp

+     def get(self):

+         """

+         Returns the current configuration (PERMISSION_MAPPING and SUPERUSERS).

+ 

+         **Sample response**:

+ 

+         .. sourcecode:: none

+ 

+           HTTP/1.0 200 OK

+           Content-Length: 55

+           Content-Type: application/json

+           Date: Tue, 31 Oct 2017 04:29:19 GMT

+           Server: Werkzeug/0.11.10 Python/2.7.13

+ 

+           {

+             "permission_mapping": {

+                 "^kernel-qe": {

+                     "groups": ["devel", "qa"],

+                     "users": []

+                 }

+             },

+             "superusers": ["alice", "bob"]

+           }

+ 

+         :statuscode 200: Configuration is returned.

+         """

+         return {

+             'permission_mapping': current_app.config.get('PERMISSION_MAPPING'),

+             'superusers': current_app.config.get('SUPERUSERS'),

+         }

+ 

+ 

  class MonitorResource(Resource):

      def get(self):

          from waiverdb.monitor import MonitorAPI
@@ -641,4 +675,5 @@ 

  api.add_resource(FilteredWaiversResource, '/waivers/+filtered')

  api.add_resource(GetWaiversBySubjectsAndTestcases, '/waivers/+by-subjects-and-testcases')

  api.add_resource(AboutResource, '/about', strict_slashes=False)

+ api.add_resource(ConfigResource, '/config', strict_slashes=False)

  api.add_resource(MonitorResource, '/metrics')

The new endpoint lists configuration for PERMISSION_MAPPING and
SUPERUSERS.

JIRA: FACTORY-4589
Signed-off-by: Lukas Holecek hluk@email.cz

rebased onto e94173e547159aa70cab199062c7be12363c0c61

a year ago

rebased onto 443140d

a year ago

rebased onto 443140d

a year ago

Pull-Request has been merged by lucarval

a year ago