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

Chore/python3 #646

Merged
merged 29 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4653cea
chore(python3): 2to3
paulineribeyre Jun 11, 2019
edc944c
chore(python3): fix some things
paulineribeyre Jun 12, 2019
0e3099f
chore(python3): fix more things
paulineribeyre Jun 13, 2019
9aaf024
chore(python3): this test never should have passed...
paulineribeyre Jun 13, 2019
2aa361c
chore(python3): remove py2 compatibility imports
paulineribeyre Jun 13, 2019
46fce29
chore(python3): fix failing oidc tests + other stuff
paulineribeyre Jun 14, 2019
13ad2ca
chore(python3): fix some more tests
paulineribeyre Jun 17, 2019
a1cfeac
chore(python3): Exception.message does not exist in py3
paulineribeyre Jun 17, 2019
525ce4c
fix deprecation warning
paulineribeyre Jun 17, 2019
79d1da7
chore(python3): python 3 dockerfile
paulineribeyre Jun 17, 2019
604d105
chore(python3): fix deployment (squash)
paulineribeyre Jun 17, 2019
0099a74
chore(python3): run integration tests
paulineribeyre Jun 18, 2019
83471db
master rebase
paulineribeyre Jun 18, 2019
8d4be60
chore(python3): black
paulineribeyre Jun 18, 2019
941f912
chore(python3): post integration tests fixes
paulineribeyre Jun 19, 2019
c3b2e3e
master rebase
paulineribeyre Jun 26, 2019
545ec0d
chore(python3): 2to3 + black
paulineribeyre Jun 26, 2019
9db625d
use wool check instead of travis
paulineribeyre Jun 28, 2019
928b382
codacy fixes
paulineribeyre Jul 2, 2019
11132a9
Merge branch 'master' into chore/python3
Avantol13 Jul 2, 2019
0daa0f0
chore(python3): pin dependencies
paulineribeyre Jul 2, 2019
cd1f788
Merge branch 'master' of github.com:uc-cdis/fence into chore/python3
paulineribeyre Jul 2, 2019
e73c7fa
chore(python3): pin storageclient
paulineribeyre Jul 2, 2019
8613c07
chore(python3): small fixes
paulineribeyre Jul 8, 2019
46af1ba
master rebase
paulineribeyre Jul 8, 2019
71e22c7
chore(python3): dockerrun.bash chmod 644 to 755
paulineribeyre Jul 9, 2019
19f8eb9
trigger jenkins
paulineribeyre Jul 11, 2019
7974071
Merge branch 'master' into chore/python3
paulineribeyre Jul 11, 2019
addd965
chore(python3): fix privacy policy tests
paulineribeyre Jul 11, 2019
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
9 changes: 9 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
workflow "Run python formatter" {
on = "pull_request"
resolves = ["Run wool"]
}

action "Run wool" {
uses = "uc-cdis/wool@master"
secrets = ["GITHUB_TOKEN"]
}
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python:

matrix:
allow_failures:
- python: "3.6"
- python: "2.7"

sudo: false

Expand All @@ -15,9 +15,6 @@ cache: pip
addons:
postgresql: "9.4"

env:
- REPOSITORY="uc-cdis/fence" PR_NUMBER="$TRAVIS_PULL_REQUEST"

install:
- pip uninstall -y six || true # travis installs wrong version
- pip uninstall -y userdatamodel || true
Expand All @@ -27,7 +24,6 @@ install:
- python setup.py install
- psql -U postgres -c "create database fence_test_tmp"
- if [[ $TRAVIS_PYTHON_VERSION != 3.6 ]]; then userdatamodel-init --db fence_test_tmp; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then pip install -e git+https://[email protected]/uc-cdis/wool.git#egg=wool; fi

before_script:
- sudo rm -f /etc/boto.cfg
Expand All @@ -41,4 +37,3 @@ script:
after_script:
- python-codacy-coverage -r coverage.xml
- COVERALLS_REPO_TOKEN=$COVERALLS_TOKEN coveralls
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 && $PR_NUMBER != false ]]; then wool; fi
42 changes: 29 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
# To run: docker run -d -v /path/to/fence-config.yaml:/var/www/fence/fence-config.yaml --name=fence -p 80:80 fence
# To check running container: docker exec -it fence /bin/bash

FROM quay.io/cdis/py27base:pybase2-1.0.2
FROM quay.io/cdis/python-nginx:pybase3-1.0.0

RUN mkdir /var/www/fence \
&& chown www-data /var/www/fence
ENV appname=fence

COPY . /fence
# number of uwsgi worker processes
ENV UWSGI_CHEAPER 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


RUN apk update \
&& apk add postgresql-libs postgresql-dev libffi-dev libressl-dev \
&& apk add linux-headers musl-dev gcc \
&& apk add curl bash git vim make

COPY . /$appname
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini
COPY ./deployment/uwsgi/wsgi.py /$appname/wsgi.py
WORKDIR /$appname

WORKDIR /fence
RUN python -m pip install --upgrade pip \
&& python -m pip install --upgrade setuptools \
&& pip install -r requirements.txt

RUN pip install --upgrade pip \
&& python -m pip install -r requirements.txt
RUN ln -s /fence/wsgi.py /var/www/fence/wsgi.py
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >fence/version_data.py
RUN VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>fence/version_data.py
RUN python setup.py develop
RUN mkdir -p /var/www/$appname \
&& mkdir -p /var/www/.cache/Python-Eggs/ \
&& mkdir /run/nginx/ \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& chown nginx -R /var/www/.cache/Python-Eggs/ \
&& chown nginx /var/www/$appname

RUN apk update && apk add openssh && apk add libmcrypt-dev

Expand All @@ -41,6 +53,10 @@ RUN (cd /tmp \
&& /bin/rm -rf /tmp/*)
EXPOSE 80

WORKDIR /var/www/fence
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >$appname/version_data.py \
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>$appname/version_data.py \
&& python setup.py develop

WORKDIR /var/www/$appname

CMD ["sh","-c","bash /fence/dockerrun.bash && /dockerrun.sh"]
CMD ["sh","-c","bash /fence/dockerrun.bash && /dockerrun.sh"]
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!groovy

@Library('cdis-jenkins-lib@master') _
@Library('cdis-jenkins-lib@chore/python3') _

testPipeline {
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ At the moment, supported IDPs include:
- InCommon
- eduGAIN

Note: the Shibboleth dockerfile image is at https://quay.io/repository/cdis/fence-shib and is NOT compatible with python 3/the latest fence.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a specific reason for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't update the shibboleth dockerfile to work with python 3 code for now, I discussed with Rudy and he said master fence probably won't be deployed to the commons that's using this dockerfile


## OIDC & OAuth2

Expand Down
20 changes: 10 additions & 10 deletions deployment/uwsgi/uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
protocol = uwsgi
socket = /var/run/gen3/uwsgi.sock
buffer-size = 32768
uid = nginx
gid = nginx
chown-socket = nginx:nginx
chmod-socket = 666
master = true
processes = 2
harakiri-verbose = true
# No global HARAKIRI, using only user HARAKIRI, because export overwrites it
# Cannot overwrite global HARAKIRI with user's: https://git.io/fjYuD
Expand All @@ -15,16 +17,14 @@ worker-reload-mercy = 45
reload-mercy = 45
mule-reload-mercy = 45
disable-logging = true
wsgi-file=/var/www/fence/wsgi.py
plugins = python
wsgi-file=/fence/wsgi.py
plugins = python3
vacuum = true
uid = www-data
gid = www-data
pythonpath = /var/www/fence/
pythonpath = /fence/
pythonpath = /usr/local/lib/python2.7/dist-packages/
pythonpath = /usr/local/lib/python3.6/site-packages/

# Initialize application master to avoid race conditions when multiple workers
# create the database.
#lazy = true
#lazy-apps = true
# Initialize application in worker processes, not master. This prevents the
# workers from all trying to open the same database connections at startup.
# lazy = true
# lazy-apps = true
4 changes: 4 additions & 0 deletions deployment/uwsgi/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from fence import app_init, app

app_init(app)
application = app
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ codacy-coverage
coveralls
mock==2.0.0
moto==1.1.24
-e git+https://github.com/uc-cdis/cdisutils-test.git@0.2.5#egg=cdisutilstest-0.2.5
-e git+https://github.com/uc-cdis/cdisutils-test.git@1.0.0#egg=cdisutilstest
Empty file modified dockerrun.bash
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions fence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def app_config(

def _setup_data_endpoint_and_boto(app):
if "AWS_CREDENTIALS" in config and len(config["AWS_CREDENTIALS"]) > 0:
value = config["AWS_CREDENTIALS"].values()[0]
value = list(config["AWS_CREDENTIALS"].values())[0]
app.boto = BotoManager(value, logger=logger)
app.register_blueprint(fence.blueprints.data.blueprint, url_prefix="/data")

Expand Down Expand Up @@ -232,7 +232,7 @@ def _set_authlib_cfgs(app):


def _setup_oidc_clients(app):
enabled_idp_ids = config["ENABLED_IDENTITY_PROVIDERS"]["providers"].keys()
enabled_idp_ids = list(config["ENABLED_IDENTITY_PROVIDERS"]["providers"].keys())

# Add OIDC client for Google if configured.
configured_google = (
Expand Down
10 changes: 5 additions & 5 deletions fence/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import flask
from flask_sqlalchemy_session import current_session
from functools import wraps
import urllib
import urllib.request, urllib.parse, urllib.error

from authutils.errors import JWTError, JWTExpiredError
from authutils.token.validate import (
Expand Down Expand Up @@ -99,16 +99,16 @@ def logout(next_url):
provider_logout = None
provider = flask.session.get("provider")
if provider == IdentityProvider.itrust:
safe_url = urllib.quote_plus(next_url)
safe_url = urllib.parse.quote_plus(next_url)
provider_logout = config["ITRUST_GLOBAL_LOGOUT"] + safe_url
elif provider == IdentityProvider.fence:
base = config["OPENID_CONNECT"]["fence"]["api_base_url"]
safe_url = urllib.quote_plus(next_url)
provider_logout = base + "/logout?" + urllib.urlencode({"next": safe_url})
safe_url = urllib.parse.quote_plus(next_url)
provider_logout = base + "/logout?" + urllib.parse.urlencode({"next": safe_url})

flask.session.clear()
redirect_response = flask.make_response(
flask.redirect(provider_logout or urllib.unquote(next_url))
flask.redirect(provider_logout or urllib.parse.unquote(next_url))
)
clear_cookies(redirect_response)
return redirect_response
Expand Down
6 changes: 3 additions & 3 deletions fence/blueprints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

def debug_log(function):
"""Output debug information to the logger for a function call."""
argument_names = list(function.func_code.co_varnames)
argument_names = list(function.__code__.co_varnames)

@functools.wraps(function)
def write_log(*args, **kwargs):
argument_values = (
"{} = {}".format(arg, value)
for arg, value in zip(argument_names, args) + kwargs.items()
for arg, value in list(zip(argument_names, args)) + list(kwargs.items())
)
msg = function.func_name + "\n\t" + "\n\t".join(argument_values)
msg = function.__name__ + "\n\t" + "\n\t".join(argument_values)
logger.debug(msg)
return function(*args, **kwargs)

Expand Down
6 changes: 3 additions & 3 deletions fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import time
from urlparse import urlparse
from urllib.parse import urlparse

from cached_property import cached_property
import cirrus
Expand Down Expand Up @@ -34,7 +34,7 @@
get_google_app_creds,
)
from fence.utils import get_valid_expiration_from_request
import multipart_upload
from . import multipart_upload


logger = get_logger(__name__)
Expand Down Expand Up @@ -825,7 +825,7 @@ def filter_auth_ids(action, list_auth_ids):
elif action == "upload":
checked_permission = "write-storage"
authorized_dbgaps = []
for key, values in list_auth_ids.items():
for key, values in list(list_auth_ids.items()):
if checked_permission in values:
authorized_dbgaps.append(key)
return authorized_dbgaps
18 changes: 5 additions & 13 deletions fence/blueprints/google.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import json
from urllib import unquote
from urllib.parse import unquote
from enum import Enum
import time

Expand Down Expand Up @@ -458,16 +458,12 @@ def _update_service_account_permissions(self, sa):

except CirrusNotFound as exc:
return (
"Can not update the service accout {}. Detail {}".format(
sa.email, exc.message
),
"Can not update the service accout {}. Detail {}".format(sa.email, exc),
404,
)
except GoogleAPIError as exc:
return (
"Can not update the service accout {}. Detail {}".format(
sa.email, exc.message
),
"Can not update the service accout {}. Detail {}".format(sa.email, exc),
400,
)
except Exception:
Expand Down Expand Up @@ -502,16 +498,12 @@ def _delete(self, id_):
force_delete_service_account(service_account_email)
except CirrusNotFound as exc:
return (
"Can not remove the service accout {}. Detail {}".format(
id_, exc.message
),
"Can not remove the service accout {}. Detail {}".format(id_, exc),
404,
)
except GoogleAPIError as exc:
return (
"Can not remove the service accout {}. Detail {}".format(
id_, exc.message
),
"Can not remove the service accout {}. Detail {}".format(id_, exc),
400,
)
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion fence/blueprints/login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def provider_info(idp_id):
}

try:
all_provider_info = [provider_info(idp_id) for idp_id in idps.keys()]
all_provider_info = [provider_info(idp_id) for idp_id in list(idps.keys())]
default_provider_info = provider_info(default_idp)
except KeyError as e:
raise InternalError("identity providers misconfigured: {}".format(str(e)))
Expand Down
2 changes: 1 addition & 1 deletion fence/blueprints/login/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from urlparse import urlparse
from urllib.parse import urlparse

import flask

Expand Down
2 changes: 1 addition & 1 deletion fence/blueprints/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _get_auth_response_for_prompts(prompts, grant, user, client, scope):

enabled_idps = config.get("OPENID_CONNECT", {})
idp_names = []
for idp, info in enabled_idps.iteritems():
for idp, info in enabled_idps.items():
# prefer name if its there, then just use the key for the provider
idp_name = info.get("name") or idp.title()
idp_names.append(idp_name)
Expand Down
2 changes: 1 addition & 1 deletion fence/blueprints/storage_creds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def list_sources():
services = set(
[
info.get("backend")
for _, info in config["STORAGE_CREDENTIALS"].iteritems()
for _, info in config["STORAGE_CREDENTIALS"].items()
if info.get("backend")
]
)
Expand Down
4 changes: 2 additions & 2 deletions fence/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from yaml import safe_load as yaml_load
import urlparse
import urllib.parse

import cirrus
from gen3config import Config
Expand Down Expand Up @@ -45,7 +45,7 @@ def post_process(self):
self.force_default_if_none(default, default_cfg=default_config)

if "ROOT_URL" not in self._configs and "BASE_URL" in self._configs:
url = urlparse.urlparse(self._configs["BASE_URL"])
url = urllib.parse.urlparse(self._configs["BASE_URL"])
self._configs["ROOT_URL"] = "{}://{}".format(url.scheme, url.netloc)

# allow authlib traffic on http for development if enabled. By default
Expand Down
9 changes: 5 additions & 4 deletions fence/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from httplib import responses as http_responses
from http.client import responses as http_responses
import flask
from flask import render_template
from werkzeug.exceptions import HTTPException
Expand Down Expand Up @@ -49,12 +49,13 @@ def get_error_response(error):


def get_error_details_and_status(error):
message = error.message if hasattr(error, "message") else str(error)
if isinstance(error, APIError):
if hasattr(error, "json") and error.json:
error.json["message"] = error.message
error.json["message"] = message
error_response = error.json, error.code
else:
error_response = {"message": error.message}, error.code
error_response = {"message": message}, error.code
elif isinstance(error, OAuth2Error):
error_response = {"message": error.description}, error.status_code
elif isinstance(error, HTTPException):
Expand All @@ -69,7 +70,7 @@ def get_error_details_and_status(error):
error_code = error.code
elif hasattr(error, "status_code"):
error_code = error.status_code
error_response = {"message": error.message}, error_code
error_response = {"message": message}, error_code

return error_response

Expand Down
Loading