Skip to content

Commit 4facfba

Browse files
midigofranktaylordowns2000stuartc
authored
bump elixir deps (#4294)
* bump deps * Migrate away from deprecated use Tesla macro pattern Remove deprecated `use Tesla` and `plug` macros in favor of explicit Tesla.client() calls with middleware configuration. This migration: - Removes all `use Tesla` declarations - Converts `plug` macros to explicit middleware lists - Adds adapter helper functions for test compatibility - Updates all HTTP method calls to use Tesla.* prefix All Tesla clients now use explicit client building with middleware and adapter configuration via Application.get_env. Fixes deprecation warnings from Tesla 1.15+ upgrade. * concept sobelow skip * Remove sobelow-skips Fix sobelow warning Fix dialyzer error from storybook * Skip Traversal.SendDownload warning Don't log low threshold warnings on CI. --------- Co-authored-by: Taylor Downs <taylor@openfn.org> Co-authored-by: Stuart Corbishley <corbish@gmail.com>
1 parent e46806e commit 4facfba

File tree

13 files changed

+127
-84
lines changed

13 files changed

+127
-84
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ workflows:
118118
- build:
119119
name: "Check for security vulnerabilities"
120120
execute:
121-
- run: sudo -u lightning mix sobelow
121+
- run: sudo -u lightning mix sobelow --threshold medium
122122
- build:
123123
name: "Check Elixir tests (codecov)"
124124
execute:

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build-and-deploy:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v6
1313
- uses: erlef/setup-elixir@v1
1414
with:
1515
otp-version: 26

.sobelow-conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
format: "txt",
88
out: "",
99
threshold: "low",
10-
ignore: ["Config.CSP"],
10+
ignore: ["Config.CSP", "Config.HTTPS"],
1111
ignore_files: [""]
1212
]

lib/lightning/auth_providers/oauth_http_client.ex

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ defmodule Lightning.AuthProviders.OauthHTTPClient do
66
77
Returns structured error responses that integrate well with the audit system.
88
"""
9-
use Tesla
10-
119
alias LightningWeb.RouteHelpers
1210

1311
require Logger
1412

13+
defp adapter do
14+
Application.get_env(:tesla, __MODULE__, [])[:adapter]
15+
end
16+
1517
@doc """
1618
Revokes an OAuth token.
1719
@@ -77,10 +79,13 @@ defmodule Lightning.AuthProviders.OauthHTTPClient do
7779
redirect_uri: RouteHelpers.oidc_callback_url()
7880
}
7981

80-
Tesla.client([
81-
Tesla.Middleware.FormUrlencoded
82-
])
83-
|> post(client.token_endpoint, body)
82+
Tesla.client(
83+
[
84+
Tesla.Middleware.FormUrlencoded
85+
],
86+
adapter()
87+
)
88+
|> Tesla.post(client.token_endpoint, body)
8489
|> handle_response([200])
8590
|> maybe_introspect(client)
8691
end
@@ -114,10 +119,13 @@ defmodule Lightning.AuthProviders.OauthHTTPClient do
114119
grant_type: "refresh_token"
115120
}
116121

117-
Tesla.client([
118-
Tesla.Middleware.FormUrlencoded
119-
])
120-
|> post(client.token_endpoint, body)
122+
Tesla.client(
123+
[
124+
Tesla.Middleware.FormUrlencoded
125+
],
126+
adapter()
127+
)
128+
|> Tesla.post(client.token_endpoint, body)
121129
|> handle_response([200])
122130
|> maybe_introspect(client)
123131
|> case do
@@ -155,7 +163,8 @@ defmodule Lightning.AuthProviders.OauthHTTPClient do
155163
else
156164
headers = [{"Authorization", "Bearer #{access_token}"}]
157165

158-
get(client.userinfo_endpoint, headers: headers)
166+
Tesla.client([{Tesla.Middleware.Headers, headers}], adapter())
167+
|> Tesla.get(client.userinfo_endpoint)
159168
|> handle_response([200])
160169
end
161170
end
@@ -194,10 +203,13 @@ defmodule Lightning.AuthProviders.OauthHTTPClient do
194203
client_secret: client.client_secret
195204
}
196205

197-
Tesla.client([
198-
Tesla.Middleware.FormUrlencoded
199-
])
200-
|> post(client.revocation_endpoint, body)
206+
Tesla.client(
207+
[
208+
Tesla.Middleware.FormUrlencoded
209+
],
210+
adapter()
211+
)
212+
|> Tesla.post(client.revocation_endpoint, body)
201213
|> handle_response([200, 204])
202214
|> case do
203215
{:ok, _} ->
@@ -240,10 +252,13 @@ defmodule Lightning.AuthProviders.OauthHTTPClient do
240252
token_type_hint: "access_token"
241253
}
242254

243-
Tesla.client([
244-
Tesla.Middleware.FormUrlencoded
245-
])
246-
|> post(client.introspection_endpoint, body)
255+
Tesla.client(
256+
[
257+
Tesla.Middleware.FormUrlencoded
258+
],
259+
adapter()
260+
)
261+
|> Tesla.post(client.introspection_endpoint, body)
247262
|> handle_response([200])
248263
end
249264

lib/lightning/usage_tracking/client.ex

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,35 @@ defmodule Lightning.UsageTracking.Client do
44
55
66
"""
7-
use Tesla, only: [:head, :post], docs: false
8-
97
alias Lightning.UsageTracking.ResponseProcessor
108

9+
defp adapter do
10+
Application.get_env(:tesla, __MODULE__, [])[:adapter]
11+
end
12+
1113
def submit_metrics(metrics, host) do
1214
response =
1315
host
1416
|> build_client()
15-
|> post("/api/metrics", metrics)
17+
|> Tesla.post("/api/metrics", metrics)
1618

1719
if ResponseProcessor.successful?(response), do: :ok, else: :error
1820
end
1921

2022
def reachable?(host) do
2123
build_head_client(host)
22-
|> head("/")
24+
|> Tesla.head("/")
2325
|> ResponseProcessor.successful?()
2426
end
2527

2628
defp build_client(host) do
27-
Tesla.client([{Tesla.Middleware.BaseUrl, host}, Tesla.Middleware.JSON])
29+
Tesla.client(
30+
[{Tesla.Middleware.BaseUrl, host}, Tesla.Middleware.JSON],
31+
adapter()
32+
)
2833
end
2934

3035
defp build_head_client(host) do
31-
Tesla.client([{Tesla.Middleware.BaseUrl, host}])
36+
Tesla.client([{Tesla.Middleware.BaseUrl, host}], adapter())
3237
end
3338
end

lib/lightning/usage_tracking/github_client.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@ defmodule Lightning.UsageTracking.GithubClient do
22
@moduledoc """
33
A GitHub client to make unauthenticated HTTP requests to GitHub.
44
"""
5-
use Tesla, only: [:head], docs: false
6-
75
alias Lightning.UsageTracking.ResponseProcessor
86

97
@host "https://github.com/"
108

9+
defp adapter do
10+
Application.get_env(:tesla, __MODULE__, [])[:adapter]
11+
end
12+
1113
def open_fn_commit?(nil = _commit_sha), do: false
1214
def open_fn_commit?("" = _commit_sha), do: false
1315

1416
def open_fn_commit?(commit_sha) do
1517
response =
1618
@host
1719
|> build_client()
18-
|> head("OpenFn/lightning/commit/#{commit_sha}")
20+
|> Tesla.head("OpenFn/lightning/commit/#{commit_sha}")
1921

2022
ResponseProcessor.successful_200?(response)
2123
end
2224

2325
def build_client(host) do
24-
Tesla.client([{Tesla.Middleware.BaseUrl, host}])
26+
Tesla.client([{Tesla.Middleware.BaseUrl, host}], adapter())
2527
end
2628
end

lib/lightning/version_control/github_client.ex

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,123 @@ defmodule Lightning.VersionControl.GithubClient do
33
Tesla github http client we use this to make any network requests
44
to github from Lightning
55
"""
6-
use Tesla
7-
86
alias Lightning.VersionControl.GithubError
97
alias Lightning.VersionControl.GithubToken
108

119
require Logger
1210

13-
plug(Tesla.Middleware.BaseUrl, "https://api.github.com")
14-
plug(Tesla.Middleware.JSON)
11+
defp adapter do
12+
Application.get_env(:tesla, __MODULE__, [])[:adapter]
13+
end
1514

1615
def create_repo_dispatch_event(client, repo_name, body) do
17-
client |> post("/repos/#{repo_name}/dispatches", body) |> handle_resp([204])
16+
client
17+
|> Tesla.post("/repos/#{repo_name}/dispatches", body)
18+
|> handle_resp([204])
1819
end
1920

2021
def create_workflow_dispatch_event(client, repo_name, workflow_id, body) do
2122
client
22-
|> post(
23+
|> Tesla.post(
2324
"repos/#{repo_name}/actions/workflows/#{workflow_id}/dispatches",
2425
body
2526
)
2627
|> handle_resp([204])
2728
end
2829

2930
def get_installations(client) do
30-
client |> get("/user/installations") |> handle_resp([200])
31+
client |> Tesla.get("/user/installations") |> handle_resp([200])
3132
end
3233

3334
def get_installation_repos(client, query \\ [page: 1, per_page: 100]) do
3435
client
35-
|> get("/installation/repositories", query: query)
36+
|> Tesla.get("/installation/repositories", query: query)
3637
|> handle_resp([200])
3738
end
3839

3940
def get_repo(client, repo_name) do
40-
client |> get("/repos/#{repo_name}") |> handle_resp([200])
41+
client |> Tesla.get("/repos/#{repo_name}") |> handle_resp([200])
4142
end
4243

4344
def get_repo_branches(client, repo_name) do
44-
client |> get("/repos/#{repo_name}/branches") |> handle_resp([200])
45+
client |> Tesla.get("/repos/#{repo_name}/branches") |> handle_resp([200])
4546
end
4647

4748
def get_repo_content(client, repo, path, ref) do
4849
client
49-
|> get("/repos/#{repo}/contents/#{path}", query: [ref: ref])
50+
|> Tesla.get("/repos/#{repo}/contents/#{path}", query: [ref: ref])
5051
|> handle_resp([200])
5152
end
5253

5354
def delete_repo_content(client, repo, path, body) do
5455
client
55-
|> delete("/repos/#{repo}/contents/#{path}", body: body)
56+
|> Tesla.delete("/repos/#{repo}/contents/#{path}", body: body)
5657
|> handle_resp([200])
5758
end
5859

5960
def create_blob(client, repo, body) do
60-
client |> post("/repos/#{repo}/git/blobs", body) |> handle_resp([201])
61+
client |> Tesla.post("/repos/#{repo}/git/blobs", body) |> handle_resp([201])
6162
end
6263

6364
def create_tree(client, repo, body) do
64-
client |> post("/repos/#{repo}/git/trees", body) |> handle_resp([201])
65+
client |> Tesla.post("/repos/#{repo}/git/trees", body) |> handle_resp([201])
6566
end
6667

6768
def get_commit(client, repo, ref) do
68-
client |> get("/repos/#{repo}/commits/#{ref}") |> handle_resp([200])
69+
client |> Tesla.get("/repos/#{repo}/commits/#{ref}") |> handle_resp([200])
6970
end
7071

7172
def create_commit(client, repo, body) do
72-
client |> post("/repos/#{repo}/git/commits", body) |> handle_resp([201])
73+
client
74+
|> Tesla.post("/repos/#{repo}/git/commits", body)
75+
|> handle_resp([201])
7376
end
7477

7578
def create_ref(client, repo, body) do
76-
client |> post("/repos/#{repo}/git/refs", body) |> handle_resp([201])
79+
client |> Tesla.post("/repos/#{repo}/git/refs", body) |> handle_resp([201])
7780
end
7881

7982
def update_ref(client, repo, ref, body) do
80-
client |> post("/repos/#{repo}/git/refs/#{ref}", body) |> handle_resp([200])
83+
client
84+
|> Tesla.post("/repos/#{repo}/git/refs/#{ref}", body)
85+
|> handle_resp([200])
8186
end
8287

8388
def delete_ref(client, repo, ref) do
84-
client |> delete("/repos/#{repo}/git/refs/#{ref}") |> handle_resp([204])
89+
client
90+
|> Tesla.delete("/repos/#{repo}/git/refs/#{ref}")
91+
|> handle_resp([204])
8592
end
8693

8794
def delete_app_grant(client, app_client_id, token) do
8895
client
89-
|> delete("/applications/#{app_client_id}/grant",
96+
|> Tesla.delete("/applications/#{app_client_id}/grant",
9097
body: %{access_token: token}
9198
)
9299
|> handle_resp([204])
93100
end
94101

95102
def get_repo_public_key(client, repo) do
96103
client
97-
|> get("/repos/#{repo}/actions/secrets/public-key")
104+
|> Tesla.get("/repos/#{repo}/actions/secrets/public-key")
98105
|> handle_resp([200])
99106
end
100107

101108
def get_repo_secret(client, repo, secret_name) do
102109
client
103-
|> get("/repos/#{repo}/actions/secrets/#{secret_name}")
110+
|> Tesla.get("/repos/#{repo}/actions/secrets/#{secret_name}")
104111
|> handle_resp([200])
105112
end
106113

107114
def create_repo_secret(client, repo, secret_name, body) do
108115
client
109-
|> put("/repos/#{repo}/actions/secrets/#{secret_name}", body)
116+
|> Tesla.put("/repos/#{repo}/actions/secrets/#{secret_name}", body)
110117
|> handle_resp([201, 204])
111118
end
112119

113120
def delete_repo_secret(client, repo, secret_name) do
114121
client
115-
|> delete("/repos/#{repo}/actions/secrets/#{secret_name}")
122+
|> Tesla.delete("/repos/#{repo}/actions/secrets/#{secret_name}")
116123
|> handle_resp([204])
117124
end
118125

@@ -126,26 +133,30 @@ defmodule Lightning.VersionControl.GithubClient do
126133
]}
127134
]
128135

129-
{:ok, Tesla.client(middleware)}
136+
{:ok, Tesla.client(middleware, adapter())}
130137
end
131138

132139
def build_bearer_client(token) do
133140
middleware = [
141+
{Tesla.Middleware.BaseUrl, "https://api.github.com"},
142+
Tesla.Middleware.JSON,
134143
{Tesla.Middleware.Headers,
135144
[
136145
{"Authorization", "Bearer #{token}"}
137146
]}
138147
]
139148

140-
{:ok, Tesla.client(middleware)}
149+
{:ok, Tesla.client(middleware, adapter())}
141150
end
142151

143152
def build_basic_auth_client(username, password) do
144153
middleware = [
154+
{Tesla.Middleware.BaseUrl, "https://api.github.com"},
155+
Tesla.Middleware.JSON,
145156
{Tesla.Middleware.BasicAuth, [username: username, password: password]}
146157
]
147158

148-
{:ok, Tesla.client(middleware)}
159+
{:ok, Tesla.client(middleware, adapter())}
149160
end
150161

151162
def build_installation_client(installation_id) do
@@ -155,7 +166,7 @@ defmodule Lightning.VersionControl.GithubClient do
155166

156167
with {:ok, auth_token, _} <- GithubToken.build(cert, app_id),
157168
{:ok, client} <- build_bearer_client(auth_token) do
158-
case post(
169+
case Tesla.post(
159170
client,
160171
"/app/installations/#{installation_id}/access_tokens",
161172
""

lib/lightning_web/controllers/project_file_controller.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ defmodule LightningWeb.ProjectFileController do
66
alias Lightning.Repo
77
alias Lightning.Storage.ProjectFileDefinition
88

9+
# sobelow_skip ["Traversal.SendDownload"]
10+
# Path is safe: generated by storage_path_for_exports/2 using system UUIDs only
911
def download(conn, %{"id" => id}) do
1012
project_file = Repo.get!(Lightning.Projects.File, id)
1113

0 commit comments

Comments
 (0)