Merge branch 'staging' into dev
This commit is contained in:
commit
1855c1c738
2 changed files with 101 additions and 8 deletions
97
ipsilon/info/infofasjson.py
Normal file
97
ipsilon/info/infofasjson.py
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
from ipsilon.info.common import InfoProviderBase, InfoProviderInstaller
|
||||||
|
from ipsilon.util.plugin import PluginObject
|
||||||
|
from ipsilon.util.policy import Policy
|
||||||
|
from ipsilon.util import config as pconfig
|
||||||
|
|
||||||
|
import fasjson_client
|
||||||
|
|
||||||
|
|
||||||
|
fasjson_mapping = [
|
||||||
|
['email', 'email'],
|
||||||
|
['username', 'nickname'],
|
||||||
|
['username', 'preferred_username'],
|
||||||
|
['timezone', 'zoneinfo'],
|
||||||
|
['locale', 'locale'],
|
||||||
|
['human_name', 'name'],
|
||||||
|
['givenname', 'given_name'],
|
||||||
|
['surname', 'family_name'],
|
||||||
|
['ircnicks', 'ircnicks'],
|
||||||
|
['gpgkeyids', 'gpg_keyids'],
|
||||||
|
['groups', 'groups'],
|
||||||
|
['agreements', 'agreements'],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class InfoProvider(InfoProviderBase):
|
||||||
|
|
||||||
|
def __init__(self, *args):
|
||||||
|
super(InfoProvider, self).__init__(*args)
|
||||||
|
self.mapper = Policy(fasjson_mapping)
|
||||||
|
|
||||||
|
self.name = 'fasjson'
|
||||||
|
self.description = """
|
||||||
|
Info plugin that retrieves user data from FASJSON. """
|
||||||
|
|
||||||
|
self.new_config(
|
||||||
|
self.name,
|
||||||
|
pconfig.String(
|
||||||
|
'FASJSON url',
|
||||||
|
'The FASJSON Url.',
|
||||||
|
'http://fasjson.tinystage.test/fasjson/'),
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fasjson_url(self):
|
||||||
|
return self.get_config_value('FASJSON url')
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_attrs(self, user):
|
||||||
|
try:
|
||||||
|
client = fasjson_client.Client(url=self.fasjson_url)
|
||||||
|
user_data = client.get_user(username=user).result
|
||||||
|
user_group_data = client.list_user_groups(username=user).result
|
||||||
|
user_agreements_data = client.list_user_agreements(username=user).result
|
||||||
|
except Exception as e:
|
||||||
|
self.error(f'FASJSON error: {e}')
|
||||||
|
return {}
|
||||||
|
|
||||||
|
# assumption that first email is the default
|
||||||
|
user_data['email'] = user_data['emails'][0] if user_data['emails'] else None
|
||||||
|
|
||||||
|
# add the groups to the user_data
|
||||||
|
user_data['groups'] = [ g['groupname'] for g in user_group_data]
|
||||||
|
|
||||||
|
# add the agreements to the user_data
|
||||||
|
user_data['agreements'] = [ g['name'] for g in user_agreements_data]
|
||||||
|
|
||||||
|
userattrs, extras = self.mapper.map_attributes(user_data)
|
||||||
|
self.debug(f'user_data: {user_data}')
|
||||||
|
self.debug(f'Userattrs: {userattrs}')
|
||||||
|
|
||||||
|
return userattrs
|
||||||
|
|
||||||
|
|
||||||
|
class Installer(InfoProviderInstaller):
|
||||||
|
|
||||||
|
def __init__(self, *pargs):
|
||||||
|
super(Installer, self).__init__()
|
||||||
|
self.name = 'fasjson'
|
||||||
|
self.pargs = pargs
|
||||||
|
|
||||||
|
def install_args(self, group):
|
||||||
|
group.add_argument('--info-fasjson', choices=['yes', 'no'], default='no',
|
||||||
|
help='Configure FAS info')
|
||||||
|
|
||||||
|
def configure(self, opts, changes):
|
||||||
|
if opts['info_fasjson'] != 'yes':
|
||||||
|
return
|
||||||
|
|
||||||
|
# Add configuration data to database
|
||||||
|
po = PluginObject(*self.pargs)
|
||||||
|
po.name = 'fasjson'
|
||||||
|
po.wipe_data()
|
||||||
|
po.wipe_config_values()
|
||||||
|
|
||||||
|
# Update global config to add login plugin
|
||||||
|
po.is_enabled = True
|
||||||
|
po.save_enabled_state()
|
|
@ -7,16 +7,12 @@ class OpenidCExtension(OpenidCExtensionBase):
|
||||||
name = 'fedora-account'
|
name = 'fedora-account'
|
||||||
display_name = 'Fedora Account Information'
|
display_name = 'Fedora Account Information'
|
||||||
scopes = {
|
scopes = {
|
||||||
'fedora': { # NOTE: This is temporary! DO NOT USE IN NEW PROJECTS!
|
|
||||||
'display_name': 'Fedora',
|
|
||||||
'claims': ['cla', 'zoneinfo', 'groups']
|
|
||||||
},
|
|
||||||
'https://id.fedoraproject.org/scope/groups': {
|
'https://id.fedoraproject.org/scope/groups': {
|
||||||
'display_name': 'Fedora Account Groups list',
|
'display_name': 'Fedora Account Group Memberships',
|
||||||
'claims': ['groups']
|
'claims': ['groups']
|
||||||
},
|
},
|
||||||
'https://id.fedoraproject.org/scope/cla': {
|
'https://id.fedoraproject.org/scope/agreements': {
|
||||||
'display_name': 'Fedora Account CLA status',
|
'display_name': 'Fedora Account Signed Agreements',
|
||||||
'claims': ['cla']
|
'claims': ['agreements']
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue