Skip to content

Commit 67baa6b

Browse files
authored
Add black to pre-commit (#68)
1 parent 54e2d76 commit 67baa6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1562
-1955
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33
python: python3.8
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.3.0
6+
rev: v4.4.0
77
hooks:
88
- id: check-docstring-first
99
- id: check-executables-have-shebangs
@@ -13,6 +13,10 @@ repos:
1313
- id: debug-statements
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
16+
- repo: https://github.com/psf/black
17+
rev: 23.1.0
18+
hooks:
19+
- id: black
1620
- repo: https://github.com/pycqa/flake8
1721
rev: 5.0.4
1822
hooks:
@@ -22,4 +26,3 @@ repos:
2226
- flake8-builtins==2.0.1
2327
- flake8-comprehensions==3.10.1
2428
- flake8-tidy-imports==4.8.0
25-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"payload": "{\"type\":\"view_submission\",\"token\":\"ABCDEFGHIJKLMNOPQRSTUVWX\",\"team\":{\"id\":\"TEST_TEAM_ID\",\"domain\":\"test-team-name\"},\"user\":{\"id\":\"TEST_USER_ID\",\"name\":\"testusername\"},\"view\":{\"id\":\"VNHU13V36\",\"type\":\"modal\",\"title\":{ \"a\":\"b\" },\"submit\":{ \"a\":\"b\" },\"blocks\":[],\"private_metadata\":\"shhh-its-secret\",\"callback_id\":\"modal-with-inputs\",\"state\":{\"values\":{\"multiline\":{\"mlvalue\":{\"type\":\"plain_text_input\",\"value\":\"This is my example inputted value\"}},\"target_channel\":{\"target_select\":{\"type\":\"conversations_select\",\"selected_conversation\":\"C123B12DE\"}}}},\"hash\":\"156663117.cd33ad1f\",\"response_urls\":[{\"block_id\":\"target_channel\",\"action_id\":\"target_select\",\"channel_id\":\"C123B12DE\",\"response_url\":\"https:\\/\\/hooks.slack.com\\/app\\/ABC12312\\/1234567890\\/A100B100C100d100\"}]}}"
3-
}
3+
}

omnibot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from os import getenv
22
import importlib
33

4-
logging = importlib.import_module(getenv('LOG_MODULE', 'logging'))
4+
logging = importlib.import_module(getenv("LOG_MODULE", "logging"))

omnibot/authnz/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import re
1515
from functools import wraps
1616

17-
from flask import (
18-
abort,
19-
request
20-
)
17+
from flask import abort, request
2118

2219
from omnibot import logging
2320
from omnibot import settings
@@ -42,24 +39,26 @@ def enforce_checks(f):
4239
Checks will be executed in the order defined by the list. All checks must
4340
pass for a request to be accepted.
4441
"""
42+
4543
@wraps(f)
4644
def decorated(*args, **kwargs):
47-
checks = settings.AUTHORIZATION.get('checks', [])
45+
checks = settings.AUTHORIZATION.get("checks", [])
4846
if not checks:
4947
logger.warning(
50-
'No checks set in the authorization section of the configuration;'
51-
' denying access to API calls for sanity sake'
48+
"No checks set in the authorization section of the configuration;"
49+
" denying access to API calls for sanity sake"
5250
)
5351
return abort(403)
5452
for check in checks:
55-
module_name, function_name = check['module'].split(':')
53+
module_name, function_name = check["module"].split(":")
5654
module = importlib.import_module(module_name)
5755
function = getattr(module, function_name)
58-
func_kwargs = check.get('kwargs', {})
56+
func_kwargs = check.get("kwargs", {})
5957
response = function(**func_kwargs)
6058
if not response:
6159
return abort(403)
6260
return f(*args, **kwargs)
61+
6362
return decorated
6463

6564

omnibot/authnz/envoy_checks.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _match_subject(subject_to_match, subject):
2323
return False
2424

2525

26-
def envoy_internal_check(header='x-envoy-internal'):
26+
def envoy_internal_check(header="x-envoy-internal"):
2727
"""
2828
Perform a check to ensure that the ``x-envoy-internal`` is set to 'true'.
2929
By default this check will apply to all routes, if enabled. It's possible
@@ -45,44 +45,44 @@ def envoy_internal_check(header='x-envoy-internal'):
4545
"""
4646
# Flask provides all headers as strings. The only acceptable string here
4747
# is 'true'
48-
envoy_internal = request.headers.get(header) == 'true'
48+
envoy_internal = request.headers.get(header) == "true"
4949
# Easy case. The header says the request is internal.
5050
if envoy_internal:
5151
return True
5252
# If the request isn't internal, let's see if we have a permission that
5353
# matches, which has internal_only set to False
54-
permissions = settings.AUTHORIZATION.get('permissions', {})
54+
permissions = settings.AUTHORIZATION.get("permissions", {})
5555
for policy_name, policy in permissions.items():
56-
method_match = request.method in policy['methods']
57-
path_match = _match_path(request.path, policy['paths'])
58-
internal_only = policy.get('internal_only', True)
56+
method_match = request.method in policy["methods"]
57+
path_match = _match_path(request.path, policy["paths"])
58+
internal_only = policy.get("internal_only", True)
5959
if (method_match and path_match) and not internal_only:
6060
return True
6161
logger.warning(
62-
'Received an external request to internal endpoint',
62+
"Received an external request to internal endpoint",
6363
extra={
64-
'endpoint': request.path,
65-
'method': request.method,
66-
'header_value': envoy_internal,
64+
"endpoint": request.path,
65+
"method": request.method,
66+
"header_value": envoy_internal,
6767
},
6868
)
6969
return False
7070

7171

7272
def _check_permission(permission):
73-
permissions = settings.AUTHORIZATION.get('permissions', {})
73+
permissions = settings.AUTHORIZATION.get("permissions", {})
7474
policy = permissions.get(permission, {})
7575
# TODO: envoy RBAC spec allows for matching methods and paths as
7676
# individual checks. So for instance, a permission may allow for all GETs
7777
# without a particular path, or may allow all methods on particular paths.
78-
method_match = request.method in policy.get('methods', [])
79-
path_match = _match_path(request.path, policy.get('paths', []))
78+
method_match = request.method in policy.get("methods", [])
79+
path_match = _match_path(request.path, policy.get("paths", []))
8080
if method_match and path_match:
8181
return True
8282
return False
8383

8484

85-
def envoy_permissions_check(header='x-envoy-downstream-service-cluster'):
85+
def envoy_permissions_check(header="x-envoy-downstream-service-cluster"):
8686
"""
8787
Perform a check against the defined permissions and bindings in the
8888
authorization configuration to ensure the service defined in the
@@ -122,17 +122,17 @@ def envoy_permissions_check(header='x-envoy-downstream-service-cluster'):
122122
envoy_identity = request.headers.get(header)
123123
if envoy_identity is None:
124124
return False
125-
bindings = settings.AUTHORIZATION.get('bindings', {})
125+
bindings = settings.AUTHORIZATION.get("bindings", {})
126126
for subject, permissions in bindings.items():
127127
if _match_subject(envoy_identity, subject):
128128
for permission in permissions:
129129
if _check_permission(permission):
130130
return True
131131
logger.warning(
132-
'Received an unauthorized request',
132+
"Received an unauthorized request",
133133
extra={
134-
'from': envoy_identity,
135-
'endpoint': request.path,
134+
"from": envoy_identity,
135+
"endpoint": request.path,
136136
},
137137
)
138138
return False

omnibot/callbacks/interactive_component_callbacks.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ def echo_dialog_submission_callback(container):
1414
Just repond back with whatever is sent in.
1515
"""
1616
payload = container.payload
17-
logger.debug('echo callback payload: {}'.format(
18-
json.dumps(payload, indent=2))
19-
)
17+
logger.debug("echo callback payload: {}".format(json.dumps(payload, indent=2)))
2018
return {
2119
# Respond back to the slash command with the same text
22-
'responses': [
20+
"responses": [
2321
{
24-
'text': payload['submission']['echo_element'],
25-
'omnibot_parse': {
26-
'text': ['users', 'specials', 'channels']
27-
}
22+
"text": payload["submission"]["echo_element"],
23+
"omnibot_parse": {"text": ["users", "specials", "channels"]},
2824
}
2925
]
3026
}

0 commit comments

Comments
 (0)