#1160 hub: new listCGs RPC
Merged 2 years ago by tkopecek. Opened 3 years ago by ktdreyer.
ktdreyer/koji list-cgs  into  master

file modified
@@ -8024,6 +8024,35 @@ 

          raise koji.GenericError('invalid user ID: %i' % user_id)



+ def list_cgs():

+     """List all available content generators in the system


+     :returns: A map of content generators, like {"name": data}. The data map

+               for each content generator has an "id" key for the content

+               generator ID, and a "users" key for the a list usernames who

+               are permitted to import for this content generator.

+     """


+     fields = {'content_generator.id': 'id', 'content_generator.name': 'name',

+               'users.name': 'user_name'}

+     columns, aliases = zip(*fields.items())

+     tables = ['cg_users']

+     joins = ['content_generator ON content_generator.id = cg_users.cg_id',

+              'users ON users.id = cg_users.user_id']

+     clauses = ['cg_users.active = TRUE']

+     query = QueryProcessor(tables=tables, aliases=aliases, columns=columns,

+                            joins=joins, clauses=clauses)

+     cgs = {}

+     for result in query.iterate():

+         cg_id = result['id']

+         cg_name = result['name']

+         user_name = result['user_name']

+         if cg_name not in cgs:

+             cgs[cg_name] = {'id': cg_id, 'users': []}

+         cgs[cg_name]['users'].append(user_name)

+     return cgs



  def grant_cg_access(user, cg, create=False):


      Grant user access to act as the given content generator
@@ -11017,6 +11046,7 @@ 

              raise koji.GenericError('unknown user: %s' % username)

          set_user_status(user, koji.USER_STATUS['BLOCKED'])


+     listCGs = staticmethod(list_cgs)

      grantCGAccess = staticmethod(grant_cg_access)

      revokeCGAccess = staticmethod(revoke_cg_access)


Add a new hub method for listing new content generator records.

The purpose of this change is to make it easier for administrators to determine what content generators are present and what user accounts have access to those.

Another benefit of this change is making it easier for content generator developers to do a "pre-flight" check to ensure the current session has access to a content generator before uploading large content into the hub.

rebased onto 74394fe30d5ccb994a041df67cc963feafdf1d89

3 years ago

rebased onto 75d08788f1ccdefb3e9a5614128fcd78e613d9dc

3 years ago

+1 This would be useful to me as well, since the MBS-Koji integration tests need to grant CG access to exercise the module import process.

@tkopecek is there an issue related to this PR?

rebased onto 1a50c58

2 years ago

Commit 66f8cd4 fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago