2014-03-12 16:37:06 +00:00
|
|
|
READ_REPO = {
|
|
|
|
'scope': 'repo:read',
|
2014-03-14 22:57:28 +00:00
|
|
|
'icon': 'fa-hdd-o',
|
|
|
|
'title': 'View all visible repositories',
|
|
|
|
'description': ('This application will be able to view and pull all repositories visible to the '
|
|
|
|
'granting user or robot account')
|
2014-03-12 16:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WRITE_REPO = {
|
|
|
|
'scope': 'repo:write',
|
2014-03-14 22:57:28 +00:00
|
|
|
'icon': 'fa-hdd-o',
|
|
|
|
'title': 'Read/Write to any accessible repositories',
|
|
|
|
'description': ('This application will be able to view, push and pull to all repositories to which the '
|
|
|
|
'granting user or robot account has write access')
|
2014-03-12 16:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ADMIN_REPO = {
|
|
|
|
'scope': 'repo:admin',
|
2014-03-14 22:57:28 +00:00
|
|
|
'icon': 'fa-hdd-o',
|
|
|
|
'title': 'Administer Repositories',
|
|
|
|
'description': ('This application will have administrator access to all repositories to which the '
|
|
|
|
'granting user or robot account has access')
|
2014-03-12 16:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CREATE_REPO = {
|
|
|
|
'scope': 'repo:create',
|
2014-03-14 22:57:28 +00:00
|
|
|
'icon': 'fa-plus',
|
|
|
|
'title': 'Create Repositories',
|
|
|
|
'description': ('This application will be able to create repositories in to any namespaces that '
|
|
|
|
'the granting user or robot account is allowed to create repositories')
|
2014-03-12 16:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ALL_SCOPES = {scope['scope']:scope for scope in (READ_REPO, WRITE_REPO, ADMIN_REPO, CREATE_REPO)}
|
2014-03-12 20:31:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def scopes_from_scope_string(scopes):
|
|
|
|
return {ALL_SCOPES.get(scope, {}).get('scope', None) for scope in scopes.split(',')}
|
|
|
|
|
|
|
|
|
|
|
|
def validate_scope_string(scopes):
|
|
|
|
decoded = scopes_from_scope_string(scopes)
|
|
|
|
return None not in decoded and len(decoded) > 0
|
2014-03-14 22:57:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_subset_string(full_string, expected_string):
|
|
|
|
""" Returns true if the scopes found in expected_string are also found
|
|
|
|
in full_string.
|
|
|
|
"""
|
|
|
|
full_scopes = scopes_from_scope_string(full_string)
|
|
|
|
expected_scopes = scopes_from_scope_string(expected_string)
|
|
|
|
return expected_scopes.issubset(full_scopes)
|
|
|
|
|
|
|
|
def get_scope_information(scopes_string):
|
|
|
|
scopes = scopes_from_scope_string(scopes_string)
|
|
|
|
scope_info = []
|
|
|
|
for scope in scopes:
|
|
|
|
scope_info.append({
|
|
|
|
'title': ALL_SCOPES[scope]['title'],
|
|
|
|
'scope': ALL_SCOPES[scope]['scope'],
|
|
|
|
'description': ALL_SCOPES[scope]['description'],
|
|
|
|
'icon': ALL_SCOPES[scope]['icon'],
|
|
|
|
})
|
|
|
|
|
|
|
|
return scope_info
|