Skip to content

Commit

Permalink
Merge pull request #43 from IN-CORE/release-1.7.0
Browse files Browse the repository at this point in the history
Release 1.7.0
  • Loading branch information
ywkim312 authored Jun 14, 2023
2 parents f713b30 + fd3dc08 commit f2a9e62
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

From version 1.2.0 the file IP2LOCATION-LITE-DB5.BIN is no longer part of the docker image and will need to be downloaded (after registration) from [ip2location](https://lite.ip2location.com/database/ip-country?lang=en_US) and be placed in /srv/incore_auth.

# [1.7.0] - 2023-06-14

## Added
- New user default usage to zero [#38](https://github.com/IN-CORE/incore-auth/issues/38)
- Return a user object that contains username, fullname, email, groups and roles.


# [1.6.0] - 2023-03-14

## Added
Expand Down
41 changes: 33 additions & 8 deletions incore_auth/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from urllib.parse import unquote_plus
from dotenv import load_dotenv

import bson

# Load .env file
load_dotenv()
CONTRIBUTION_DB_NAME = os.getenv('INFLUXDB_V2_FILE_LOCATION', 'data/IP2LOCATION-LITE-DB5.BIN')
Expand Down Expand Up @@ -123,6 +125,23 @@ def update_services_thread(request_info):
})
app.logger.info(f"Inserted space document for {username}")

mongo_usage = mongo_client["spacedb"]["UserAllocations"].find_one({"username": username})
if not mongo_usage:
mongo_client["spacedb"]["UserAllocations"].insert_one({
"className": "edu.illinois.ncsa.incore.common.models.UserAllocations",
"username": username,
"usage": {
"className": "edu.illinois.ncsa.incore.common.models.UserUsages",
"datasets": int(0),
"hazards": int(0),
"hazardDatasets": int(0),
"dfr3": int(0),
"datasetSize": bson.Int64(0),
"hazardDatasetSize": bson.Int64(0)
}
})
app.logger.info(f"Inserted space document for {username}")


@cached(cache=TTLCache(maxsize=cache_size, ttl=cache_timeout), key=cache_key)
def update_services(request_info):
Expand Down Expand Up @@ -263,9 +282,10 @@ def request_userinfo(request_info):
return

# get name of user
request_info["firstname"] = access_token["given_name"]
request_info["lastname"] = access_token["family_name"]
request_info["fullname"] = access_token["name"]
request_info["firstname"] = access_token.get("given_name", "")
request_info["lastname"] = access_token.get("family_name", "")
request_info["fullname"] = access_token.get("name", "")
request_info["email"] = access_token.get("email", "")

# retrieve the groups the user belongs to from access token
request_info['username'] = access_token["preferred_username"]
Expand Down Expand Up @@ -337,6 +357,7 @@ def verify_token():
"firstname": "",
"lastname": "",
"fullname": "",
"email": "",
"method": request.method,
"url": request.path,
"resource": "",
Expand Down Expand Up @@ -385,20 +406,24 @@ def verify_token():
# everything is ok
user_info = {"preferred_username": request_info['username']}
group_info = {"groups": request_info['groups']}
user_object = {
"username": request_info['username'],
"email": request_info['email'],
"fullname": request_info['fullname'],
"groups": request_info['groups'],
"roles": request_info['roles'],
}

response = Response(status=200)
response.headers['X-Auth-UserInfo'] = json.dumps(user_info)
response.headers['X-Auth-UserGroup'] = json.dumps(group_info)
response.headers['X-Auth-User'] = json.dumps(user_object)

if request.headers.get('Authorization') is not None:
response.headers['Authorization'] = unquote_plus(request.headers['Authorization'])
elif request.cookies.get('Authorization') is not None:
response.headers['Authorization'] = unquote_plus(request.cookies['Authorization'])

if request.headers.get('X-Auth-UserGroup') is not None:
response.headers['X-Auth-UserGroup'] = request.headers.get('X-Auth-UserGroup')
elif request.cookies.get('X-Auth-UserGroup') is not None:
response.headers['X-Auth-UserGroup'] = request.cookies['X-Auth-UserGroup']

return response


Expand Down

0 comments on commit f2a9e62

Please sign in to comment.