Skip to content

Commit b8eed95

Browse files
authored
TECH-76: Upgrades to Erlang/OTP 27, updates deps (#23)
* TECH-76: Upgrades to Erlang/OTP 27, updates deps * Bumps CI * Fixes codestyle
1 parent 4ad8fca commit b8eed95

15 files changed

+121
-113
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
SERVICE_NAME=api-key-mgmt-v2
2-
OTP_VERSION=25.3
3-
REBAR_VERSION=3.18
2+
OTP_VERSION=27.1.2
3+
REBAR_VERSION=3.24
44
THRIFT_VERSION=0.14.2.3

.github/workflows/erlang-checks.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
thrift-version: ${{ steps.thrift-version.outputs.version }}
1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222
- run: grep -v '^#' .env >> $GITHUB_ENV
2323
- id: otp-version
2424
run: echo "::set-output name=version::$OTP_VERSION"
@@ -30,11 +30,12 @@ jobs:
3030
run:
3131
name: Run checks
3232
needs: setup
33-
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.12
33+
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.18
3434
with:
3535
otp-version: ${{ needs.setup.outputs.otp-version }}
3636
rebar-version: ${{ needs.setup.outputs.rebar-version }}
3737
use-thrift: true
3838
thrift-version: ${{ needs.setup.outputs.thrift-version }}
3939
run-ct-with-compose: true
4040
cache-version: v1
41+
upload-coverage: false

apps/akm/src/akm.app.src

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
genlib,
1111
erl_health,
1212
%oas_server_akm,
13+
prometheus,
14+
prometheus_cowboy,
15+
woody,
1316
scoper,
1417
jose,
1518
jsx,

apps/akm/src/akm_apikeys_handler.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
%% Providers
6060
-spec prepare(operation_id(), request_data(), handler_context(), handler_opts()) -> {ok, request_state()}.
61-
prepare(OperationID = 'IssueApiKey', #{'partyId' := PartyID, 'ApiKeyIssue' := ApiKey}, Context, _Opts) ->
61+
prepare('IssueApiKey' = OperationID, #{'partyId' := PartyID, 'ApiKeyIssue' := ApiKey}, Context, _Opts) ->
6262
Authorize = fun() ->
6363
Prototypes = [{operation, #{id => OperationID, party => PartyID}}],
6464
Resolution = akm_auth:authorize_operation(Prototypes, Context),
@@ -77,7 +77,7 @@ prepare(OperationID = 'IssueApiKey', #{'partyId' := PartyID, 'ApiKeyIssue' := Ap
7777
end
7878
end,
7979
{ok, #{authorize => Authorize, process => Process}};
80-
prepare(OperationID = 'GetApiKey', #{'partyId' := PartyID, 'apiKeyId' := ApiKeyId}, Context, _Opts) ->
80+
prepare('GetApiKey' = OperationID, #{'partyId' := PartyID, 'apiKeyId' := ApiKeyId}, Context, _Opts) ->
8181
Result = akm_apikeys_processing:get_api_key(ApiKeyId),
8282
Authorize = fun() ->
8383
ApiKey = extract_api_key(Result),
@@ -95,7 +95,7 @@ prepare(OperationID = 'GetApiKey', #{'partyId' := PartyID, 'apiKeyId' := ApiKeyI
9595
end,
9696
{ok, #{authorize => Authorize, process => Process}};
9797
prepare(
98-
OperationID = 'ListApiKeys',
98+
'ListApiKeys' = OperationID,
9999
#{
100100
'partyId' := PartyID,
101101
'limit' := Limit,
@@ -116,7 +116,7 @@ prepare(
116116
akm_handler_utils:reply_ok(200, Response)
117117
end,
118118
{ok, #{authorize => Authorize, process => Process}};
119-
prepare(OperationID = 'RequestRevokeApiKey', Params, Context, _Opts) ->
119+
prepare('RequestRevokeApiKey' = OperationID, Params, Context, _Opts) ->
120120
#{
121121
'partyId' := PartyID,
122122
'apiKeyId' := ApiKeyId,
@@ -140,7 +140,7 @@ prepare(OperationID = 'RequestRevokeApiKey', Params, Context, _Opts) ->
140140
end,
141141
{ok, #{authorize => Authorize, process => Process}};
142142
prepare(
143-
OperationID = 'RevokeApiKey',
143+
'RevokeApiKey' = OperationID,
144144
#{'partyId' := PartyID, 'apiKeyId' := ApiKeyId, 'apiKeyRevokeToken' := Token},
145145
Context,
146146
_Opts
@@ -163,7 +163,7 @@ prepare(
163163
end,
164164
{ok, #{authorize => Authorize, process => Process}}.
165165

166-
extract_api_key({ok, Apikey}) ->
167-
Apikey;
166+
extract_api_key({ok, ApiKey}) ->
167+
ApiKey;
168168
extract_api_key(_) ->
169169
undefined.

apps/akm/src/akm_apikeys_processing.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ get_api_key(ApiKeyId) ->
6565
end.
6666

6767
-spec list_api_keys(binary(), binary(), non_neg_integer(), non_neg_integer()) -> {ok, list_keys_response()}.
68-
list_api_keys(PartyId, Status, Limit, Offset) ->
69-
{ok, Columns, Rows} = get_keys(PartyId, Status, Limit, Offset),
68+
list_api_keys(PartyID, Status, Limit, Offset) ->
69+
{ok, Columns, Rows} = get_keys(PartyID, Status, Limit, Offset),
7070
case erlang:length(Rows) < Limit of
7171
true ->
7272
% last piece of data
@@ -159,19 +159,19 @@ get_full_api_key(ApiKeyId) ->
159159
{ok, ApiKey}
160160
end.
161161

162-
get_keys(PartyId, undefined, Limit, Offset) ->
162+
get_keys(PartyID, undefined, Limit, Offset) ->
163163
epgsql_pool:query(
164164
main_pool,
165165
"SELECT id, name, status, metadata, created_at FROM apikeys where party_id = $1 "
166166
"ORDER BY created_at DESC LIMIT $2 OFFSET $3",
167-
[PartyId, Limit, Offset]
167+
[PartyID, Limit, Offset]
168168
);
169-
get_keys(PartyId, Status, Limit, Offset) ->
169+
get_keys(PartyID, Status, Limit, Offset) ->
170170
epgsql_pool:query(
171171
main_pool,
172172
"SELECT id, name, status, metadata, created_at FROM apikeys where party_id = $1 AND status = $2 "
173173
"ORDER BY created_at DESC LIMIT $3 OFFSET $4",
174-
[PartyId, Status, Limit, Offset]
174+
[PartyID, Status, Limit, Offset]
175175
).
176176

177177
%% Encode/Decode

apps/akm/src/akm_auth.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ put_party_to_metadata(PartyId) ->
124124
put_party_to_metadata(PartyId, #{}).
125125

126126
-spec put_party_to_metadata(binary(), map()) -> map().
127-
put_party_to_metadata(PartyId, MetaData) ->
128-
put_metadata(get_metadata_mapped_key(party_id), PartyId, MetaData).
127+
put_party_to_metadata(PartyId, Metadata) ->
128+
put_metadata(get_metadata_mapped_key(party_id), PartyId, Metadata).
129129

130130
-spec get_party_from_metadata(map()) -> binary() | undefined.
131-
get_party_from_metadata(MetaData) ->
132-
get_metadata(get_metadata_mapped_key(party_id), MetaData).
131+
get_party_from_metadata(Metadata) ->
132+
get_metadata(get_metadata_mapped_key(party_id), Metadata).
133133

134134
get_metadata(Key, Metadata) ->
135135
maps:get(Key, Metadata, undefined).

apps/akm/src/akm_bouncer_context.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ build(Prototypes, {Acc0, External}) ->
4949
Acc1 = lists:foldl(fun({T, Params}, Acc) -> build(T, Params, Acc) end, Acc0, Prototypes),
5050
{Acc1, External}.
5151

52-
build(operation, Params = #{id := OperationID}, Acc) ->
52+
build(operation, #{id := OperationID} = Params, Acc) ->
5353
PartyEntity = party_entity(Params),
5454
ApiKeyEntity = api_key_entity(Params),
5555
ListEntities = lists:filter(fun(E) -> E =/= undefined end, [PartyEntity, ApiKeyEntity]),

apps/akm/src/akm_db_migration.erl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,17 @@ report_migrations(down, Results) ->
242242
[logger:info("Reverted ~s: ~p", [V, R]) || {V, R} <- Results],
243243
ok.
244244

245-
-define(DRIVER, epgsql).
246-
247245
record_migration(up, Conn, V) ->
248-
?DRIVER:equery(Conn, "INSERT INTO __migrations (id) VALUES ($1)", [V]);
246+
epgsql:equery(Conn, "INSERT INTO __migrations (id) VALUES ($1)", [V]);
249247
record_migration(down, Conn, V) ->
250-
?DRIVER:equery(Conn, "DELETE FROM __migrations WHERE id = $1", [V]).
248+
epgsql:equery(Conn, "DELETE FROM __migrations WHERE id = $1", [V]).
251249

252250
apply_migrations(Type, Migrations, Conn) ->
253251
Results = lists:foldl(
254252
fun
255253
(_, [{_, {error, _}} | _] = Acc) ->
256254
Acc;
257-
(Migration = {Version, _}, Acc) ->
255+
({Version, _} = Migration, Acc) ->
258256
case apply_migration(Type, Migration, Conn) of
259257
ok -> [{Version, ok} | Acc];
260258
{error, Error} -> [{Version, {error, Error}}]
@@ -268,7 +266,7 @@ apply_migrations(Type, Migrations, Conn) ->
268266
apply_migration(Type, {Version, Migration}, Conn) ->
269267
case eql:get_query(Type, Migration) of
270268
{ok, Query} ->
271-
case if_ok(?DRIVER:squery(Conn, Query)) of
269+
case if_ok(epgsql:squery(Conn, Query)) of
272270
ok ->
273271
_ = record_migration(Type, Conn, Version),
274272
ok;
@@ -316,12 +314,12 @@ applied_migrations(Args) when is_list(Args) ->
316314
end
317315
);
318316
applied_migrations(Conn) when is_pid(Conn) ->
319-
case ?DRIVER:squery(Conn, "SELECT id FROM __migrations ORDER by id ASC") of
317+
case epgsql:squery(Conn, "SELECT id FROM __migrations ORDER by id ASC") of
320318
{ok, _, Migs} ->
321319
[binary_to_list(Mig) || {Mig} <- Migs];
322320
{error, {error, error, <<"42P01">>, _, _, _}} ->
323321
%% init migrations and restart
324-
{ok, _, _} = ?DRIVER:squery(
322+
{ok, _, _} = epgsql:squery(
325323
Conn,
326324
"CREATE TABLE __migrations ("
327325
"id VARCHAR(255) PRIMARY KEY,"

apps/akm/src/akm_handler.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ attach_deadline(undefined, Context) ->
171171
attach_deadline(Deadline, Context) ->
172172
woody_context:set_deadline(Deadline, Context).
173173

174-
do_authorize_api_key(SwagContext = #{auth_context := PreAuthContext}, WoodyContext) ->
174+
do_authorize_api_key(#{auth_context := PreAuthContext} = SwagContext, WoodyContext) ->
175175
case akm_auth:authorize_api_key(PreAuthContext, make_token_context(SwagContext), WoodyContext) of
176176
{ok, AuthContext} ->
177177
SwagContext#{auth_context => AuthContext};

apps/akm/src/akm_sup.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ get_logic_handler_info() ->
5252
-spec enable_health_logging(erl_health:check()) -> erl_health:check().
5353
enable_health_logging(Check) ->
5454
EvHandler = {erl_health_event_handler, []},
55-
maps:map(fun(_, V = {_, _, _}) -> #{runner => V, event_handler => EvHandler} end, Check).
55+
maps:map(fun(_, {_, _, _} = V) -> #{runner => V, event_handler => EvHandler} end, Check).
5656

5757
start_epgsql_pooler() ->
5858
Params = genlib_app:env(akm, epsql_connection, #{}),

0 commit comments

Comments
 (0)