#436 Provide single login function able to process auth type
Closed: Fixed 6 years ago Opened 6 years ago by pbabinca.

I'd love to have authentication code independent on configured auth type. Currently if I need to authenticate against koji I need to do dispatching based on configured authentication type. Snippet of my code initializing koji module:

import argparse
import koji

parser = argparse.ArgumentParser()
parser.add_argument('--koji-profile')

args = parser.parse_args(sys.argv[1:])

try:
    result = koji.read_config(args.koji_profile)
except koji.ConfigurationError, e:
    parser.error(e.args[0])
    assert False  # pragma: no cover

session = koji.ClientSession(result['server'], result)

And now when I want to authenticate I need to look in result['auth_type'] and based on that do something similar to what koji CLI code does in activate_session(): https://pagure.io/koji/blob/master/f/cli/koji#_7555


Metadata Update from @tkopecek:
- Issue set to the milestone: 1.14

6 years ago

It should be possible already with 1.13 to use activate_session from koji_cli.lib. Nevertheless, it needs some cumbersome tweaks:

import optparse
from koji_cli.lib import activate_session
import koji

result = koji.read_config('koji')
result['user'] = 'username'
result['noauth'] = False
result['runas'] = None

session = koji.ClientSession(result['server'], result)
activate_session(session, optparse.Values(result))
targets = session.getBuildTargets()

It could be made easier with possible merging of PR #493 to:

from koji_cli.lib import activate_session
import koji

result = koji.read_config('koji')
session = koji.ClientSession(result['server'], result)
activate_session(session, result)
targets = session.getBuildTargets()

Note, that both cases needs CLI installed.

Commit bc43f8b relates to this ticket

Login to comment on this ticket.

Metadata