You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/09/11 11:18:17 UTC
[incubator-ponymail-foal] branch master updated: a tad more linting
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new 96fbe6c a tad more linting
96fbe6c is described below
commit 96fbe6cfec7fc90648c10eca077c3a3214a88c0c
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Sep 11 13:18:02 2020 +0200
a tad more linting
---
server/plugins/aaa.py | 4 ++--
server/plugins/background.py | 6 ++++--
server/plugins/configuration.py | 24 +++++++++++++-----------
server/plugins/oauthGeneric.py | 6 ++++--
server/plugins/server.py | 1 +
server/plugins/session.py | 28 +++++++++++++++-------------
6 files changed, 39 insertions(+), 30 deletions(-)
diff --git a/server/plugins/aaa.py b/server/plugins/aaa.py
index c654a4c..6c31780 100644
--- a/server/plugins/aaa.py
+++ b/server/plugins/aaa.py
@@ -26,11 +26,11 @@ import plugins.session
def can_access_email(session: plugins.session.SessionObject, email) -> bool:
"""Determine if an email can be accessed by the current user"""
# If public email, it can always be accessed
- if not email.get('private'):
+ if not email.get("private"):
return True
else:
# If user can access the list, they can read the email
- if can_access_list(session, email.get('list_raw')):
+ if can_access_list(session, email.get("list_raw")):
return True
# If no access to list and email is private, deny access to email.
else:
diff --git a/server/plugins/background.py b/server/plugins/background.py
index dc43d69..5e9e3e9 100644
--- a/server/plugins/background.py
+++ b/server/plugins/background.py
@@ -57,7 +57,6 @@ async def get_lists(database: plugins.configuration.DBConfig) -> dict:
)
s.aggs.bucket("per_list", "terms", field="list_raw")
-
res = await client.search(
index=database.db_prefix + "-mbox", body=s.to_dict(), size=0
)
@@ -208,5 +207,8 @@ async def run_tasks(server: plugins.server.BaseServer):
try:
server.data.activity = await get_public_activity(server.config.database)
except plugins.database.DBError as e:
- print("Could not fetch activity data - database down or not connected: %s" % e)
+ print(
+ "Could not fetch activity data - database down or not connected: %s"
+ % e
+ )
await asyncio.sleep(server.config.tasks.refresh_rate)
diff --git a/server/plugins/configuration.py b/server/plugins/configuration.py
index 4546a59..54417cb 100644
--- a/server/plugins/configuration.py
+++ b/server/plugins/configuration.py
@@ -15,18 +15,20 @@ class TaskConfig:
class UIConfig:
- wordcloud: bool
- mailhost: str
+ wordcloud: bool
+ mailhost: str
sender_domains: str
- traceback: bool
+ traceback: bool
def __init__(self, subyaml: dict):
- self.wordcloud = bool(subyaml.get('wordcloud', False))
- self.mailhost = subyaml.get('mailhost', '') # Default to nothing (disabled)
- self.sender_domains = subyaml.get('sender_domains', '') # Default to nothing (disabled)
+ self.wordcloud = bool(subyaml.get("wordcloud", False))
+ self.mailhost = subyaml.get("mailhost", "") # Default to nothing (disabled)
+ self.sender_domains = subyaml.get(
+ "sender_domains", ""
+ ) # Default to nothing (disabled)
# Default to spitting out traceback to web clients
# Set to false in yaml to redirect to stderr instead.
- self.traceback = subyaml.get('traceback', True)
+ self.traceback = subyaml.get("traceback", True)
class OAuthConfig:
@@ -36,10 +38,10 @@ class OAuthConfig:
github_client_secret: str
def __init__(self, subyaml: dict):
- self.authoritative_domains = subyaml.get('authoritative_domains', [])
- self.google_client_id = subyaml.get('google_client_id', '')
- self.github_client_id = subyaml.get('github_client_id', '')
- self.github_client_secret = subyaml.get('github_client_secret', '')
+ self.authoritative_domains = subyaml.get("authoritative_domains", [])
+ self.google_client_id = subyaml.get("google_client_id", "")
+ self.github_client_id = subyaml.get("github_client_id", "")
+ self.github_client_secret = subyaml.get("github_client_secret", "")
class DBConfig:
diff --git a/server/plugins/oauthGeneric.py b/server/plugins/oauthGeneric.py
index 0676261..6bf5da1 100644
--- a/server/plugins/oauthGeneric.py
+++ b/server/plugins/oauthGeneric.py
@@ -10,8 +10,10 @@ async def process(formdata, session, server):
oauth_domain = m.group(1)
headers = {"User-Agent": "Pony Mail OAuth Agent/0.1"}
# This is a synchronous process, so we offload it to an async runner in order to let the main loop continue.
- rv = await server.runners.run(requests.post, formdata["oauth_token"], headers=headers, data=formdata)
+ rv = await server.runners.run(
+ requests.post, formdata["oauth_token"], headers=headers, data=formdata
+ )
js = rv.json()
js["oauth_domain"] = oauth_domain
- js['authoritative'] = True
+ js["authoritative"] = True
return js
diff --git a/server/plugins/server.py b/server/plugins/server.py
index 0d96ed3..795e7ea 100644
--- a/server/plugins/server.py
+++ b/server/plugins/server.py
@@ -7,6 +7,7 @@ from elasticsearch import AsyncElasticsearch
import plugins.configuration
import plugins.offloader
+
class Endpoint:
exec: typing.Callable
diff --git a/server/plugins/session.py b/server/plugins/session.py
index 40f64a8..e18a449 100644
--- a/server/plugins/session.py
+++ b/server/plugins/session.py
@@ -100,7 +100,7 @@ async def get_session(
)
if "ponymail" in cookies:
session_id = cookies["ponymail"].value
- if not all(c in 'abcdefg1234567890-' for c in session_id):
+ if not all(c in "abcdefg1234567890-" for c in session_id):
session_id = None
break
@@ -145,18 +145,21 @@ async def get_session(
# Get CID and fecth the account data
cid = session_doc["_source"]["cid"]
if cid:
- account_doc = await session.database.get(session.database.dbs.account, id=cid)
- creds = account_doc["_source"]['credentials']
- internal = account_doc['_source']['internal']
+ account_doc = await session.database.get(
+ session.database.dbs.account, id=cid
+ )
+ creds = account_doc["_source"]["credentials"]
+ internal = account_doc["_source"]["internal"]
# Set session data
session.cid = cid
session.last_accessed = last_update
creds["authoritative"] = (
- internal.get("oauth_provider") in server.config.oauth.authoritative_domains
+ internal.get("oauth_provider")
+ in server.config.oauth.authoritative_domains
)
- creds['oauth_provider'] = internal.get('oauth_provider', 'generic')
- creds['oauth_data'] = internal.get('oauth_data', {})
+ creds["oauth_provider"] = internal.get("oauth_provider", "generic")
+ creds["oauth_data"] = internal.get("oauth_data", {})
session.credentials = SessionCredentials(creds)
# Save in memory storage
@@ -172,7 +175,9 @@ async def set_session(server: plugins.server.BaseServer, cid, **credentials):
session_id = str(uuid.uuid4())
cookie: http.cookies.SimpleCookie = http.cookies.SimpleCookie()
cookie["ponymail"] = session_id
- session = SessionObject(server, last_accessed=time.time(), cookie=session_id, cid=cid)
+ session = SessionObject(
+ server, last_accessed=time.time(), cookie=session_id, cid=cid
+ )
session.credentials = SessionCredentials(credentials)
server.data.sessions[session_id] = session
@@ -206,10 +211,7 @@ async def save_session(session: SessionObject):
async def remove_session(session: SessionObject):
"""Remove a session object in the ES database"""
assert session.database, "Database not connected!"
- await session.database.delete(
- index=session.database.dbs.session,
- id=session.cookie
- )
+ await session.database.delete(index=session.database.dbs.session, id=session.cookie)
async def save_credentials(session: SessionObject):
@@ -229,6 +231,6 @@ async def save_credentials(session: SessionObject):
"internal": {
"oauth_provider": session.credentials.oauth_provider,
"oauth_data": session.credentials.oauth_data,
- }
+ },
},
)