Skip to content

Commit f05cb94

Browse files
chore: Run pre-commit hook
1 parent 6f1b2e1 commit f05cb94

File tree

5 files changed

+75
-76
lines changed

5 files changed

+75
-76
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/helm/airflow-operator/crds/crds.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ spec:
513513
maxEntries:
514514
default: 1000
515515
description: Maximum number of entries in the cache; If this threshold is reached then the least recently used item is removed.
516-
format: int32
516+
format: uint32
517+
minimum: 0.0
517518
type: integer
518519
type: object
519520
configMapName:

rust/crd/src/authorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl AirflowAuthorizationResolved {
2727
pub struct OpaConfigResolved {
2828
pub connection_string: String,
2929
pub cache_entry_time_to_live: Duration,
30-
pub cache_max_entries: i32,
30+
pub cache_max_entries: u32,
3131
}
3232

3333
impl OpaConfigResolved {

tests/templates/kuttl/opa/41_check-authorization.py

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,151 +9,149 @@
99

1010
# Jane Doe has access to specific resources.
1111
user_jane_doe = {
12-
'first_name': "Jane",
13-
'last_name': "Doe",
14-
'username': "jane.doe",
15-
'email': "jane.doe@stackable.tech",
16-
'roles': [{'name': "User"}],
17-
'password': "T8mn72D9"
12+
"first_name": "Jane",
13+
"last_name": "Doe",
14+
"username": "jane.doe",
15+
"email": "jane.doe@stackable.tech",
16+
"roles": [{"name": "User"}],
17+
"password": "T8mn72D9",
1818
}
1919
# Richard Roe has no access.
2020
user_richard_roe = {
21-
'first_name': "Richard",
22-
'last_name': "Roe",
23-
'username': "richard.roe",
24-
'email': "richard.roe@stackable.tech",
25-
'roles': [{'name': "User"}],
26-
'password': "NvfpU518"
21+
"first_name": "Richard",
22+
"last_name": "Roe",
23+
"username": "richard.roe",
24+
"email": "richard.roe@stackable.tech",
25+
"roles": [{"name": "User"}],
26+
"password": "NvfpU518",
2727
}
2828

29+
2930
def create_user(user):
3031
requests.post(
31-
'http://airflow-webserver:8080/auth/fab/v1/users',
32-
auth=('airflow', 'airflow'),
33-
json=user
32+
"http://airflow-webserver:8080/auth/fab/v1/users",
33+
auth=("airflow", "airflow"),
34+
json=user,
3435
)
3536

37+
3638
def check_api_authorization_for_user(
37-
user,
38-
expected_status_code,
39-
method,
40-
endpoint,
41-
data=None,
42-
api="api/v1"
43-
):
44-
api_url = f'http://airflow-webserver:8080/{api}'
45-
46-
auth = (user['username'], user['password'])
47-
response = requests.request(method, f'{api_url}/{endpoint}', auth=auth, json=data)
39+
user, expected_status_code, method, endpoint, data=None, api="api/v1"
40+
):
41+
api_url = f"http://airflow-webserver:8080/{api}"
42+
43+
auth = (user["username"], user["password"])
44+
response = requests.request(method, f"{api_url}/{endpoint}", auth=auth, json=data)
4845
assert response.status_code == expected_status_code
4946

47+
5048
def check_api_authorization(method, endpoint, data=None, api="api/v1"):
5149
check_api_authorization_for_user(
52-
user_jane_doe,
53-
200,
54-
method=method,
55-
endpoint=endpoint,
56-
data=data,
57-
api=api
50+
user_jane_doe, 200, method=method, endpoint=endpoint, data=data, api=api
5851
)
5952
check_api_authorization_for_user(
60-
user_richard_roe,
61-
403,
62-
method=method,
63-
endpoint=endpoint,
64-
data=data,
65-
api=api
53+
user_richard_roe, 403, method=method, endpoint=endpoint, data=data, api=api
6654
)
6755

56+
6857
def check_website_authorization_for_user(user, expected_status_code):
69-
username = user['username']
70-
password = user['password']
58+
username = user["username"]
59+
password = user["password"]
7160
with requests.Session() as session:
7261
login_response = session.post(
73-
'http://airflow-webserver:8080/login/',
62+
"http://airflow-webserver:8080/login/",
7463
data=f"username={username}&password={password}",
7564
allow_redirects=False,
76-
headers={'Content-Type': 'application/x-www-form-urlencoded'}
65+
headers={"Content-Type": "application/x-www-form-urlencoded"},
7766
)
7867
assert login_response.ok, f"Login for {username} failed"
7968
home_response = session.get(
80-
'http://airflow-webserver:8080/home',
81-
allow_redirects=False
69+
"http://airflow-webserver:8080/home", allow_redirects=False
8270
)
83-
assert home_response.status_code == expected_status_code, \
84-
f"GET /home returned status code {home_response.status_code}, but {expected_status_code} was expected."
71+
assert (
72+
home_response.status_code == expected_status_code
73+
), f"GET /home returned status code {home_response.status_code}, but {expected_status_code} was expected."
74+
8575

8676
def test_is_authorized_configuration():
8777
# section == null
88-
check_api_authorization('GET', 'config')
78+
check_api_authorization("GET", "config")
8979
# section != null
90-
check_api_authorization('GET', 'config?section=core')
80+
check_api_authorization("GET", "config?section=core")
81+
9182

92-
def test_is_authorized_connection():
83+
def test_is_authorized_connection():
9384
# conn_id == null
94-
check_api_authorization('GET', 'connections')
85+
check_api_authorization("GET", "connections")
9586
# conn_id != null
96-
check_api_authorization('GET', 'connections/postgres_default')
87+
check_api_authorization("GET", "connections/postgres_default")
88+
9789

9890
def test_is_authorized_dag():
9991
# access_entity == null and id == null
10092
# There is no API endpoint to test this case.
10193

10294
# access_entity == null and id != null
103-
check_api_authorization('GET', 'dags/example_trigger_target_dag')
95+
check_api_authorization("GET", "dags/example_trigger_target_dag")
10496

10597
# access_entity != null and id == null
10698
# Check "GET /dags/~/dagRuns" because access to "GET /dags" is always allowed
107-
check_api_authorization('GET', 'dags/~/dagRuns')
99+
check_api_authorization("GET", "dags/~/dagRuns")
108100

109101
# access_entity != null and id != null
110-
check_api_authorization('GET', 'dags/example_trigger_target_dag/dagRuns')
102+
check_api_authorization("GET", "dags/example_trigger_target_dag/dagRuns")
103+
111104

112105
def test_is_authorized_dataset():
113106
# uri == null
114-
check_api_authorization('GET', 'datasets')
107+
check_api_authorization("GET", "datasets")
115108
# uri != null
116-
check_api_authorization('GET', 'datasets/s3%3A%2F%2Fbucket%2Fmy-task')
109+
check_api_authorization("GET", "datasets/s3%3A%2F%2Fbucket%2Fmy-task")
110+
117111

118112
def test_is_authorized_pool():
119113
# name == null
120-
check_api_authorization('GET', 'pools')
114+
check_api_authorization("GET", "pools")
121115
# name != null
122-
check_api_authorization('GET', 'pools/default_pool')
116+
check_api_authorization("GET", "pools/default_pool")
117+
123118

124119
def test_is_authorized_variable():
125120
# key != null
126-
check_api_authorization('POST', 'variables', data={'key': 'myVar', 'value': '1'})
121+
check_api_authorization("POST", "variables", data={"key": "myVar", "value": "1"})
127122
# key == null
128-
check_api_authorization('GET', 'variables/myVar')
123+
check_api_authorization("GET", "variables/myVar")
124+
129125

130126
def test_is_authorized_view():
131127
check_website_authorization_for_user(user_jane_doe, 200)
132128
check_website_authorization_for_user(user_richard_roe, 403)
133129

130+
134131
def test_is_authorized_custom_view():
135132
user_jane_doe_patched = user_jane_doe.copy()
136-
user_jane_doe_patched['email'] = "jane@stackable.tech"
133+
user_jane_doe_patched["email"] = "jane@stackable.tech"
137134
check_api_authorization_for_user(
138135
user_jane_doe,
139136
200,
140-
'PATCH',
141-
'users/jane.doe?update_mask=email',
137+
"PATCH",
138+
"users/jane.doe?update_mask=email",
142139
data=user_jane_doe_patched,
143-
api='/auth/fab/v1'
140+
api="/auth/fab/v1",
144141
)
145142

146143
user_richard_roe_patched = user_richard_roe.copy()
147-
user_richard_roe_patched['email'] = "richard@stackable.tech"
144+
user_richard_roe_patched["email"] = "richard@stackable.tech"
148145
check_api_authorization_for_user(
149146
user_richard_roe,
150147
403,
151-
'PATCH',
152-
'users/richard.roe?update_mask=email',
148+
"PATCH",
149+
"users/richard.roe?update_mask=email",
153150
data=user_richard_roe_patched,
154-
api='/auth/fab/v1'
151+
api="/auth/fab/v1",
155152
)
156153

154+
157155
# Create test users
158156
create_user(user_jane_doe)
159157
create_user(user_richard_roe)

0 commit comments

Comments
 (0)