From 5d8599a33d6cec1453a2a25b91db5aaafaca4a40 Mon Sep 17 00:00:00 2001 From: LilyRose2798 Date: Wed, 18 Jun 2025 15:53:40 +1000 Subject: [PATCH] Remove unnecessary authentication for unauthenticated endpoints --- src/endpoints/agents.gleam | 15 ++++-------- src/endpoints/factions.gleam | 24 ++++++++------------ src/endpoints/systems.gleam | 44 ++++++++++++------------------------ 3 files changed, 28 insertions(+), 55 deletions(-) diff --git a/src/endpoints/agents.gleam b/src/endpoints/agents.gleam index 1cd7f58..22c8e28 100644 --- a/src/endpoints/agents.gleam +++ b/src/endpoints/agents.gleam @@ -5,14 +5,13 @@ import models/agent_event.{type AgentEvent} import models/agent_symbol.{type AgentSymbol} import models/public_agent.{type PublicAgent} import utils/api.{type ApiResponse, type PagedData} -import utils/auth.{type AgentToken, AgentAuth} +import utils/auth.{type AgentToken, AgentAuth, NoAuth} pub fn list_public_agents( - token: AgentToken, page: Option(Int), limit: Option(Int), ) -> ApiResponse(PagedData(List(PublicAgent))) { - let request = api.get_page(AgentAuth(token), "/agents", page, limit) + let request = api.get_page(NoAuth, "/agents", page, limit) use response <- api.try_send(request) case response.status { 200 -> @@ -24,15 +23,9 @@ pub fn list_public_agents( } } -pub fn get_public_agent( - token: AgentToken, - agent_symbol: AgentSymbol, -) -> ApiResponse(PublicAgent) { +pub fn get_public_agent(agent_symbol: AgentSymbol) -> ApiResponse(PublicAgent) { let request = - api.get( - AgentAuth(token), - "/agents/" <> agent_symbol.to_string(agent_symbol), - ) + api.get(NoAuth, "/agents/" <> agent_symbol.to_string(agent_symbol)) use response <- api.try_send(request) case response.status { 200 -> api.parse_data_response(response, public_agent.decoder()) diff --git a/src/endpoints/factions.gleam b/src/endpoints/factions.gleam index 6b3ecd8..45a57ec 100644 --- a/src/endpoints/factions.gleam +++ b/src/endpoints/factions.gleam @@ -3,14 +3,13 @@ import gleam/option.{type Option} import models/faction.{type Faction} import models/faction_symbol.{type FactionSymbol} import utils/api.{type ApiResponse, type PagedData} -import utils/auth.{type AgentToken, AgentAuth} +import utils/auth.{type AgentToken, AgentAuth, NoAuth} pub fn list_factions( - token: AgentToken, page: Option(Int), limit: Option(Int), ) -> ApiResponse(PagedData(List(Faction))) { - let request = api.get_page(AgentAuth(token), "/factions", page, limit) + let request = api.get_page(NoAuth, "/factions", page, limit) use response <- api.try_send(request) case response.status { 200 -> @@ -19,12 +18,9 @@ pub fn list_factions( } } -pub fn get_faction( - token: AgentToken, - symbol: FactionSymbol, -) -> ApiResponse(Faction) { +pub fn get_faction(symbol: FactionSymbol) -> ApiResponse(Faction) { let request = - api.get(AgentAuth(token), "/factions/" <> faction_symbol.to_string(symbol)) + api.get(NoAuth, "/factions/" <> faction_symbol.to_string(symbol)) use response <- api.try_send(request) case response.status { 200 -> api.parse_data_response(response, faction.decoder()) @@ -36,12 +32,6 @@ pub type FactionReputation { FactionReputation(symbol: FactionSymbol, reputation: Int) } -fn faction_reputation_decoder() { - use symbol <- decode.field("symbol", faction_symbol.decoder()) - use reputation <- decode.field("reputation", decode.int) - decode.success(FactionReputation(symbol:, reputation:)) -} - pub fn get_my_factions( token: AgentToken, page: Option(Int), @@ -53,7 +43,11 @@ pub fn get_my_factions( 200 -> api.parse_paged_data_response( response, - decode.list(faction_reputation_decoder()), + decode.list({ + use symbol <- decode.field("symbol", faction_symbol.decoder()) + use reputation <- decode.field("reputation", decode.int) + decode.success(FactionReputation(symbol:, reputation:)) + }), ) _ -> api.parse_error_response(response) } diff --git a/src/endpoints/systems.gleam b/src/endpoints/systems.gleam index 9999b65..b815d4f 100644 --- a/src/endpoints/systems.gleam +++ b/src/endpoints/systems.gleam @@ -16,14 +16,13 @@ import models/waypoint_symbol.{type WaypointSymbol} import models/waypoint_trait_symbol.{type WaypointTraitSymbol} import models/waypoint_type.{type WaypointType} import utils/api.{type ApiResponse, type PagedData} -import utils/auth.{type AgentToken, AgentAuth} +import utils/auth.{NoAuth} pub fn list_systems( - token: AgentToken, page: Option(Int), limit: Option(Int), ) -> ApiResponse(PagedData(List(System))) { - let request = api.get_page(AgentAuth(token), "/systems", page, limit) + let request = api.get_page(NoAuth, "/systems", page, limit) use response <- api.try_send(request) case response.status { 200 -> @@ -32,15 +31,9 @@ pub fn list_systems( } } -pub fn get_system( - token: AgentToken, - system_symbol: SystemSymbol, -) -> ApiResponse(System) { +pub fn get_system(system_symbol: SystemSymbol) -> ApiResponse(System) { let request = - api.get( - AgentAuth(token), - "/systems/" <> system_symbol.to_string(system_symbol), - ) + api.get(NoAuth, "/systems/" <> system_symbol.to_string(system_symbol)) use response <- api.try_send(request) case response.status { 200 -> api.parse_data_response(response, system.decoder()) @@ -49,7 +42,6 @@ pub fn get_system( } pub fn list_system_waypoints( - token: AgentToken, system_symbol: SystemSymbol, page: Option(Int), limit: Option(Int), @@ -66,7 +58,7 @@ pub fn list_system_waypoints( } let request = api.get_page_with_query( - AgentAuth(token), + NoAuth, "/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints", page, limit, @@ -81,13 +73,12 @@ pub fn list_system_waypoints( } pub fn get_waypoint( - token: AgentToken, system_symbol: SystemSymbol, waypoint_symbol: WaypointSymbol, ) -> ApiResponse(Waypoint) { let request = api.get( - AgentAuth(token), + NoAuth, "/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints/" @@ -101,13 +92,12 @@ pub fn get_waypoint( } pub fn get_construction_site( - token: AgentToken, system_symbol: SystemSymbol, waypoint_symbol: WaypointSymbol, ) -> ApiResponse(Construction) { let request = api.get( - AgentAuth(token), + NoAuth, "/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints/" @@ -126,7 +116,6 @@ pub type ConstructionSiteSupplied { } pub fn supply_construction_site( - token: AgentToken, system_symbol: SystemSymbol, waypoint_symbol: WaypointSymbol, ship_symbol: ShipSymbol, @@ -135,7 +124,7 @@ pub fn supply_construction_site( ) -> ApiResponse(ConstructionSiteSupplied) { let request = api.post_json( - AgentAuth(token), + NoAuth, "/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints/" @@ -160,13 +149,12 @@ pub fn supply_construction_site( } pub fn get_market( - token: AgentToken, system_symbol: SystemSymbol, waypoint_symbol: WaypointSymbol, ) -> ApiResponse(Market) { let request = api.get( - AgentAuth(token), + NoAuth, "/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints/" @@ -181,13 +169,12 @@ pub fn get_market( } pub fn get_jump_gate( - token: AgentToken, system_symbol: SystemSymbol, waypoint_symbol: WaypointSymbol, ) -> ApiResponse(JumpGate) { let request = api.get( - AgentAuth(token), + NoAuth, "/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints/" @@ -202,17 +189,16 @@ pub fn get_jump_gate( } pub fn get_shipyard( - token, - system_symbol, - waypoint_symbol, + system_symbol: SystemSymbol, + waypoint_symbol: WaypointSymbol, ) -> ApiResponse(Shipyard) { let request = api.get( - AgentAuth(token), + NoAuth, "/systems/" - <> system_symbol + <> system_symbol.to_string(system_symbol) <> "/waypoints/" - <> waypoint_symbol + <> waypoint_symbol.to_string(waypoint_symbol) <> "/shipyard", ) use response <- api.try_send(request)