An Elixir toolkit for the AT Protocol. hexdocs.pm/atex
elixir bluesky atproto decentralization

Add support for configuring PLC host in IdentityResolver #1

closed opened by diddyfo.id targeting main from [deleted fork]: main

This PR fixes #2. plc.directory has been set as the default host in case the option is missing in the configuration.

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:5szlrh3xkfxxsuu4mo6oe6h7/sh.tangled.repo.pull/3mddkin3ty722
+32 -2
Diff #1
+3
config/runtime.exs
··· 8 8 private_key: 9 9 "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgyIpxhuDm0i3mPkrk6UdX4Sd9Jsv6YtAmSTza+A2nArShRANCAAQLF1GLueOBZOVnKWfrcnoDOO9NSRqH2utmfGMz+Rce18MDB7Z6CwFWjEq2UFYNBI4MI5cMI0+m+UYAmj4OZm+m", 10 10 key_id: "awooga" 11 + 12 + config :atex, Atex.IdentityResolver, 13 + directory_url: "https://plc.directory"
+26
lib/atex/config/identity_resolver.ex
··· 1 + defmodule Atex.Config.IdentityResolver do 2 + @moduledoc """ 3 + Configuration management for `Atex.IdentityResolver`. 4 + 5 + Contains all configuration logic for fetching identity documents. 6 + 7 + ## Configuration 8 + 9 + The following structure is expected in your application config: 10 + 11 + config :atex, Atex.IdentityResolver, 12 + directory_url: "https://plc.directory" # An address to a did:plc document host 13 + """ 14 + 15 + @doc """ 16 + Returns the configured URL for PLC queries. 17 + """ 18 + @spec directory_url :: String.t() 19 + def directory_url(), 20 + do: 21 + Keyword.get( 22 + Application.get_env(:atex, Atex.IdentityResolver, []), 23 + :directory_url, 24 + "https://plc.directory" 25 + ) 26 + end
+2 -1
lib/atex/identity_resolver/did.ex
··· 1 1 defmodule Atex.IdentityResolver.DID do 2 2 alias Atex.IdentityResolver.DIDDocument 3 + alias Atex.Config.IdentityResolver, as: Config 3 4 4 5 @type resolution_result() :: 5 6 {:ok, DIDDocument.t()} ··· 14 15 @spec resolve_plc(String.t()) :: resolution_result() 15 16 defp resolve_plc("did:plc:" <> _id = did) do 16 17 with {:ok, resp} when resp.status in 200..299 <- 17 - Req.get("https://plc.directory/#{did}"), 18 + Req.get("#{Config.directory_url()}/#{did}"), 18 19 {:ok, body} <- decode_body(resp.body), 19 20 {:ok, document} <- DIDDocument.from_json(body), 20 21 :ok <- DIDDocument.validate_for_atproto(document, did) do
+1 -1
mix.exs
··· 69 69 XRPC: ~r/^Atex\.XRPC/, 70 70 OAuth: [Atex.Config.OAuth, Atex.OAuth, Atex.OAuth.Plug], 71 71 Lexicons: ~r/^Atex\.Lexicon/, 72 - Identity: ~r/^Atex\.IdentityResolver/ 72 + Identity: [Atex.Config.IdentityResolver, ~r/^Atex\.IdentityResolver/] 73 73 ] 74 74 ] 75 75 end

History

2 rounds 1 comment
sign up or login to add to the discussion
2 commits
expand
84ad0605
feat: Add support for PLC endpoint configuration
883f6961
Fix runtime config error
expand 1 comment
closed without merging
1 commit
expand
84ad0605
feat: Add support for PLC endpoint configuration
expand 0 comments