Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade #14

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ should be the application's _/login_, and the scopes _profile_, _userid_,
_email_ and _openid_ should be accepted.

For testing and development, a client has already been registered with
the following parameters:
the following parameters:
<dl>
<dt>Client ID<dt>
<dd><em>1375546d-7476-4ed7-a61a-92fd841f36a2</em></dd>
Expand Down Expand Up @@ -91,7 +91,7 @@ or

To run it as a standalone web server:

pserve --reload developent.ini
pserve --reload development.ini

or

Expand Down
45 changes: 24 additions & 21 deletions himlar_dp_prep/dp_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def make_password():

class DpProvisioner(object):
def __init__(self, config):
self.config = config
self.config = config
self.member_role_name = config['member_role_name']
self.with_local_user = config.get('with_local_user')
self.api_pw = None
Expand All @@ -47,61 +47,64 @@ def __init__(self, config):
raise ValueError("Expecting unique '{}' domain".format(dp_domain_name))

def get_user(self, user_id):
api_users = self.ks.users.list(domain=self.domain, name=api_user_name(user_id))
try:
if api_users:
for user in api_users:
self.ks.users.get(user.id)
api_users = self.ks.users.list(domain=self.domain, name=api_user_name(user_id))
try:
if api_users:
for user in api_users:
self.ks.users.get(user.id)
return user
except:
log.info('User %s not found!', api_users)
log.info('User %s not found!', api_users)

def is_provisioned(self, user_id, user_type='api'):
user = self.get_user(user_id)
try:
try:
if user:
if hasattr(user, 'type') and user.type == user_type:
log.info('User %s is already provisioned!', user.name)
return True
# User found but type missing: we guess this is still ok
log.info('User %s found, but missing type = api!', user.name)
return True
except:
log.info('User %s not found!', user)
except:
log.info('User %s not found!', user)

def provision(self, user_id):
api_name = api_user_name(user_id)
if self.with_local_user:
log.info(f'provision user {api_name}')
api_pw = make_password()
data = {
'action': 'provision',
'email': user_id,
'password': api_pw
}
try:
self.rmq = MQclient(self.config)
self.rmq.push(data=data, queue='access')
return dict(api_user_name=api_name, api_pw=api_pw)
except:
raise exc.HTTPInternalServerError("HTTP error occurred during provision process.")
try:
self.rmq = MQclient(self.config, log)
self.rmq.push(data=data, queue='access')
return dict(api_user_name=api_name, api_pw=api_pw)
except Exception as e:
log.error(f'could not push data to mq: {e}')
raise exc.HTTPInternalServerError("MQ error occurred during provision process.")

def reset(self, user_id):
api_name = api_user_name(user_id)
if self.with_local_user:
log.info(f'reset pw for user {api_name}')
api_pw = make_password()
log.info("Reset password for: %s", user_id)
data = {
'action': 'reset_password',
'email': user_id,
'password': api_pw
}
try:
self.rmq = MQclient(self.config)
try:
self.rmq = MQclient(self.config, log)
if self.is_provisioned(user_id):
self.rmq.push(data=data, queue='access')
return api_pw
except:
raise exc.HTTPInternalServerError("HTTP error occurred during reset process.")
except Exception as e:
log.error(f'could not push data to mq: {e}')
raise exc.HTTPInternalServerError("MQ error occurred during reset process.")

if __name__ == '__main__':
DESCRIPTION = "Dataporten provisioner for Openstack"
Expand Down
16 changes: 9 additions & 7 deletions himlar_dp_prep/rmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@

class MQclient(object):

def __init__(self, config):
def __init__(self, config, logger):
self.log = logger
self.config = config
try:
try:
self.log.info('connect to mq...')
credentials = pika.PlainCredentials(
username=self.config['mq_username'],
password=self.config['mq_password'])
parameters = pika.ConnectionParameters(
host=self.config['mq_host'],
virtual_host=self.config['mq_vhost'],
credentials=credentials,
heartbeat_interval=10,
connection_attempts=2,
retry_delay=5,
socket_timeout=10,
blocked_connection_timeout=30)
self.connection = pika.BlockingConnection(parameters)
except:
raise exc.HTTPInternalServerError("HTTP error occurred.")
except Exception as e:
self.log.error(f'connection to mq server failed: {e}')

def get_channel(self, queue):
channel = self.connection.channel()
channel.queue_declare(queue=queue, durable=True)
return channel

def close_connection(self):
self.log.info('close mq connection')
self.connection.close()

def push(self, data, queue='access'):
Expand All @@ -41,5 +43,5 @@ def push(self, data, queue='access'):
properties=pika.BasicProperties(
delivery_mode=2))
if result:
print ('New message added to queue: ', queue)
self.close_connection()
self.log.info('New message added to queue: ', queue)
self.close_connection()
40 changes: 40 additions & 0 deletions himlar_dp_prep/static/nrec.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions himlar_dp_prep/templates/home.mak
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<%inherit file="main.mak"/>
<div class="row uninett-color-white uninett-whole-row uninett-padded">
<h2>NREC via Dataporten</h2>
<h2>Sign up via FEIDE</h2>
<div> NREC – Norwegian Research and Education Cloud is a collaborative project between
<a href="https://www.uib.no">Univesity of Bergen</a>,
<a href="https://www.uio.no>Univesity of Oslo">University of Oslo</a> and
<a href="https://www.uninett.no">UNINETT</a>.
<a href="https://www.uib.no">Univesity of Bergen</a> and
<a href="https://www.uio.no>Univesity of Oslo">University of Oslo</a>.
For more information about this service, please read our <a href="https://docs.nrec.no">documentation.</a>
</div>
<br/>
Expand Down
6 changes: 3 additions & 3 deletions himlar_dp_prep/templates/loggedin.mak
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div class="row uninett-color-white uninett-whole-row uninett-padded">
<h2>${user.name}</h2>
% if was_provisioned:
<p>NREC was already prepared for Dataporten</p>
<p>NREC was already prepared with FEIDE</p>
% else:
<p>NREC prepared for Dataporten</p>
<p>NREC prepared with FEIDE</p>
% endif
% if api_pw:
<h3>API access</h3>
Expand All @@ -22,5 +22,5 @@
<a style="color:#eb212e" href="/reset" class="btn btn-underline">Reset API password</a>
% endif
<br/>
<p>You may be sent back to Dataporten again.</p>
<p>You may be sent back to FEIDE again.</p>
</div>
11 changes: 4 additions & 7 deletions himlar_dp_prep/templates/main.mak
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="author" content="">
<link rel="shortcut icon" href="${request.static_url('himlar_dp_prep:uninett-theme/ico/favicon.ico')}">

<title>NREC via Dataporten</title>
<title>NREC via FEIDE</title>

<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
Expand All @@ -30,11 +30,9 @@
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<a class="navbar-brand" href="/"><img src="${request.static_url('himlar_dp_prep:uninett-theme/images/UNINETT_logo.svg')}" alt="Uninett logo" type="image/svg+xml"></a>
</div>
<div class="navbar-department">
<div class="department">Dataporten</div>
<a class="navbar-brand" href="/"><img src="${request.static_url('himlar_dp_prep:static/nrec.svg')}" alt="Uninett logo" type="image/svg+xml"></a>
</div>

<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
</ul>
Expand All @@ -51,8 +49,7 @@
<div class="col-lg-12">
<div class="footer-uninett">
<div class="footer-content-uninett">
<div class="footer-logo"> <img src="${request.static_url('himlar_dp_prep:uninett-theme/images/Uninett_pil_rod.svg')}" alt="Uninett logo" type="image/svg+xml"></div>
<div class="footer-uninett-department">UNINETT AS 2020</div>

</div>
<div class="clearfix"></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion himlar_dp_prep/templates/noemail.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%inherit file="main.mak"/>
<div class="row uninett-color-white uninett-whole-row uninett-padded">
<h2>Email not provided</h2>
<p>cannot prepare NREC for Dataporten</p>
<p>cannot prepare NREC with FEIDE</p>
</div>
2 changes: 1 addition & 1 deletion himlar_dp_prep/templates/provision.mak
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<a href="http://docs.nrec.no/en/latest/terms-of-service.html" target="blank">
Terms of Service</a>.</p>
% endif
<p>You may be sent back to Dataporten again.</p>
<p>You may be sent back to FEIDE again.</p>
</div>
4 changes: 2 additions & 2 deletions himlar_dp_prep/templates/reset.mak
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%inherit file="main.mak"/>
<div class="row uninett-color-white uninett-whole-row uninett-padded">
<h2>NREC via Dataporten</h2>
<h2>NREC via FEIDE</h2>
<br/>
% if was_provisioned:
<h3>Reset API password</h3>
Expand All @@ -23,5 +23,5 @@
</a><br>
% endif
<br/>
<p>You may be sent back to Dataporten again.</p>
<p>You may be sent back to FEIDE again.</p>
</div>
1 change: 0 additions & 1 deletion himlar_dp_prep/uninett-theme
Submodule uninett-theme deleted from e7d859
2 changes: 2 additions & 0 deletions himlar_dp_prep/uninett-theme/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./uninett-theme/fonts/colfaxLight*
.DS_Store
5 changes: 5 additions & 0 deletions himlar_dp_prep/uninett-theme/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2013 (c) UNINETT AS - All Rights Reserved

DO NOT USE WITHOUT EXPLICIT PERMISSION FROM UNINETT AS.


25 changes: 25 additions & 0 deletions himlar_dp_prep/uninett-theme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
UNINETT Bootstrap Theme
=======================

Bootstrap theme with UNINETT look.


## Credits

* [Bootstrap](http://getbootstrap.com/about/)
* [H-K Reklamebyrå](http://h-k.no)


## Adding fonts

Fill the fonts folder with the Colfax font.

## Licence


2013 (c) UNINETT AS - All Rights Reserved

DO NOT USE WITHOUT EXPLICIT PERMISSION FROM UNINETT AS.

The Colfax fonts are required but not included in this repo, and are licenced separately

22 changes: 22 additions & 0 deletions himlar_dp_prep/uninett-theme/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "uninett-bootstrap-theme",
"version": "1.0.0",
"main": "css/uninett.css",
"private": true,
"authors": [
"Andreas Åkre Solberg <[email protected]>",
"Yørn de Jong <[email protected]>",
"HK Reklamebyrå"
],
"licence": "All rights reserved",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bootstrap": "~3"
}
}
Loading