Skip to content

Commit

Permalink
chore(python3): black
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Jun 18, 2019
1 parent 83471db commit 9c28af5
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion fence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from fence.resources.aws.boto_manager import BotoManager
from fence.resources.openid.google_oauth2 import GoogleOauth2Client as GoogleClient
from fence.resources.openid.microsoft_oauth2 import (
MicrosoftOauth2Client as MicrosoftClient
MicrosoftOauth2Client as MicrosoftClient,
)
from fence.resources.openid.orcid_oauth2 import OrcidOauth2Client as ORCIDClient
from fence.resources.storage import StorageManager
Expand Down
16 changes: 4 additions & 12 deletions fence/blueprints/google.py
Original file line number Diff line number Diff line change
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
),
"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
),
"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
),
"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
),
"Can not remove the service accout {}. Detail {}".format(id_, exc),
400,
)
except Exception:
Expand Down
3 changes: 1 addition & 2 deletions fence/blueprints/login/fence_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def get(self):
validate_redirect(redirect_url)
flask.session["redirect"] = redirect_url
authorization_url, state = flask.current_app.fence_client.generate_authorize_redirect(
oauth2_redirect_uri,
prompt="login"
oauth2_redirect_uri, prompt="login"
)
flask.session["state"] = state
return flask.redirect(authorization_url)
Expand Down
4 changes: 1 addition & 3 deletions fence/blueprints/login/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def validate_redirect(url):
allowed_redirects = allowed_login_redirects()
if domain(url) not in allowed_redirects:
flask.current_app.logger.error(
"invalid redirect {}. expected one of: {}".format(
url, allowed_redirects
)
"invalid redirect {}. expected one of: {}".format(url, allowed_redirects)
)
raise UserError("invalid login redirect URL {}".format(url))
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
4 changes: 3 additions & 1 deletion fence/oidc/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def validate_authenticate_client(self):
# authorization header to check against stored hash.
hashed = client.client_secret
if (
bcrypt.hashpw(client_secret.encode("utf-8"), hashed.encode("utf-8")).decode("utf-8")
bcrypt.hashpw(client_secret.encode("utf-8"), hashed.encode("utf-8")).decode(
"utf-8"
)
!= hashed
):
logger.debug("client secret hash does not match stored secret hash")
Expand Down
4 changes: 3 additions & 1 deletion fence/oidc/grants/authorization_code_grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def authenticate_client(self):
# Client secrets are stored as hash.
hashed = client.client_secret
if (
bcrypt.hashpw(client_secret.encode("utf-8"), hashed.encode("utf-8")).decode("utf-8")
bcrypt.hashpw(
client_secret.encode("utf-8"), hashed.encode("utf-8")
).decode("utf-8")
!= hashed
):
raise InvalidClientError(uri=self.uri)
Expand Down
8 changes: 2 additions & 6 deletions fence/resources/aws/boto_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def get_user_group(self, group_names):
res[group["GroupName"]] = group
except Exception as ex:
self.logger.exception(ex)
raise UserError(
"Fail to get list of groups {}: {}".format(group_names, ex)
)
raise UserError("Fail to get list of groups {}: {}".format(group_names, ex))
return res

def create_user_group(self, group_name, path=None):
Expand All @@ -163,9 +161,7 @@ def create_user_group(self, group_name, path=None):
)
except Exception as ex:
self.logger.exception(ex)
raise UserError(
"Fail to create group {}: {}".format(group_name, ex)
)
raise UserError("Fail to create group {}: {}".format(group_name, ex))
return group

def __get_policy_document_by_group_name__(self, group_name):
Expand Down
4 changes: 3 additions & 1 deletion fence/resources/openid/google_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def get_auth_url(self):
authorization_endpoint = self.get_value_from_discovery_doc(
"authorization_endpoint", "https://accounts.google.com/o/oauth2/v2/auth"
)
uri, _ = self.session.create_authorization_url(authorization_endpoint, prompt="login")
uri, _ = self.session.create_authorization_url(
authorization_endpoint, prompt="login"
)

return uri

Expand Down
4 changes: 3 additions & 1 deletion fence/resources/openid/microsoft_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def get_auth_url(self):
"authorization_endpoint",
"https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize",
)
uri, _ = self.session.create_authorization_url(authorization_endpoint, prompt="login")
uri, _ = self.session.create_authorization_url(
authorization_endpoint, prompt="login"
)

return uri

Expand Down
4 changes: 3 additions & 1 deletion fence/resources/openid/orcid_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def get_auth_url(self):
"authorization_endpoint", "https://orcid.org/oauth/authorize"
)

uri, state = self.session.create_authorization_url(authorization_endpoint, prompt="login")
uri, state = self.session.create_authorization_url(
authorization_endpoint, prompt="login"
)

return uri

Expand Down
18 changes: 16 additions & 2 deletions fence/sync/sync_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,19 @@ def _read_file(filepath, encrypted=True, key=None, logger=None):
# TODO (rudyardrichter, 2019-01-08): raise error and move exit out to script
exit(1)
p = sp.Popen(
["mcrypt", "-a", "enigma", "-o", "scrypt", "-m", "stream", "--bare", "--key", key, "--force"],
[
"mcrypt",
"-a",
"enigma",
"-o",
"scrypt",
"-m",
"stream",
"--bare",
"--key",
key,
"--force",
],
stdin=open(filepath, "r"),
stdout=sp.PIPE,
stderr=open(os.devnull, "w"),
Expand Down Expand Up @@ -953,7 +965,9 @@ def _sync(self, sess):

permissions = [{"read-storage"} for _ in local_csv_file_list]
user_projects_csv, user_info_csv = self._parse_csv(
dict(list(zip(local_csv_file_list, permissions))), encrypted=False, sess=sess
dict(list(zip(local_csv_file_list, permissions))),
encrypted=False,
sess=sess,
)

try:
Expand Down
4 changes: 3 additions & 1 deletion fence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def create_client(
hashed_secret = None
if confidential:
client_secret = random_str(55)
hashed_secret = bcrypt.hashpw(client_secret.encode('utf-8'), bcrypt.gensalt()).decode("utf-8")
hashed_secret = bcrypt.hashpw(
client_secret.encode("utf-8"), bcrypt.gensalt()
).decode("utf-8")
auth_method = "client_secret_basic" if confidential else "none"
with driver.session as s:
user = query_for_user(session=s, username=username)
Expand Down
4 changes: 2 additions & 2 deletions tests/admin/test_admin_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ def test_get_user_groups(db_session, awg_users):
"projects": ["test_project_1"],
},
]
expected_groups.sort(key=lambda x: x['name'])
groups["groups"].sort(key=lambda x: x['name'])
expected_groups.sort(key=lambda x: x["name"])
groups["groups"].sort(key=lambda x: x["name"])
assert groups["groups"] == expected_groups
4 changes: 3 additions & 1 deletion tests/admin/test_admin_users_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def encoded_admin_jwt(kid, rsa_private_key):
claims["sub"] = "5678"
claims["iss"] = config["BASE_URL"]
claims["exp"] += 600
return jwt.encode(claims, key=rsa_private_key, headers=headers, algorithm="RS256").decode("utf-8")
return jwt.encode(
claims, key=rsa_private_key, headers=headers, algorithm="RS256"
).decode("utf-8")


# Dictionary for all these random magic numbers that the delete user
Expand Down
10 changes: 7 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def app(kid, rsa_private_key, rsa_public_key):
)

config.update(BASE_URL=config["BASE_URL"])
config.update(ENCRYPTION_KEY=Fernet.generate_key().decode('utf-8'))
config.update(ENCRYPTION_KEY=Fernet.generate_key().decode("utf-8"))

return fence.app

Expand Down Expand Up @@ -856,7 +856,9 @@ def oauth_client(app, db_session, oauth_user):
url = "https://oauth-test-client.net"
client_id = "test-client"
client_secret = fence.utils.random_str(50)
hashed_secret = bcrypt.hashpw(client_secret.encode('utf-8'), bcrypt.gensalt()).decode("utf-8")
hashed_secret = bcrypt.hashpw(
client_secret.encode("utf-8"), bcrypt.gensalt()
).decode("utf-8")
test_user = db_session.query(models.User).filter_by(id=oauth_user.user_id).first()
db_session.add(
models.Client(
Expand Down Expand Up @@ -884,7 +886,9 @@ def oauth_client_B(app, request, db_session):
url = "https://oauth-test-client-B.net"
client_id = "test-client-B"
client_secret = fence.utils.random_str(50)
hashed_secret = bcrypt.hashpw(client_secret.encode('utf-8'), bcrypt.gensalt()).decode("utf-8")
hashed_secret = bcrypt.hashpw(
client_secret.encode("utf-8"), bcrypt.gensalt()
).decode("utf-8")

test_user = db_session.query(models.User).filter_by(username="test").first()
if not test_user:
Expand Down
4 changes: 1 addition & 3 deletions tests/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ def test_valid_session_valid_access_token_diff_user(

def _get_cookies_from_response(response):
raw_cookies = [
header[1]
for header in response.headers.items()
if header[0] == "Set-Cookie"
header[1] for header in response.headers.items() if header[0] == "Set-Cookie"
]
cookies = {}
for cookie in raw_cookies:
Expand Down

0 comments on commit 9c28af5

Please sign in to comment.