ridho9

ridho9

Hello, so I have few apps under an umbrella, lets say the names are linesdk, hibiki, and hibiki_web. So linesdk have a plug where you pass a secret key as the opts. hibiki_web is the app which runs the cowboy server and routes request to the linesdk plug. The secret key that needs to be passed is inside the :hibiki :channel_secret config. Here are some snippets

defmodule Hibiki.Config do
  def channel_secret, do: Application.fetch_env!(:hibiki, :channel_secret)
end

defmodule HibikiWeb.Router do
...
  post("/hibiki",
    to: LineSdk.Plug,
    init_opts: [
      channel_secret: Hibiki.Config.channel_secret(),
      handler: Hibiki.WebhookHandler
    ]
  )
...
end

defmodule LineSdk.Plug do
  use Plug.Builder
...
  plug(:validate, builder_opts())
...
  def validate(
        %Plug.Conn{
          assigns: %{raw_body: raw_body}
        } = conn,
        opts
      ) do
    with {:ok, signature} <- get_signature(conn),
         {:ok, _} <-
           LineSdk.Auth.validate_message(
             raw_body,
             opts[:channel_secret],
             signature
           ) do
      conn
    else
      {:error, err} ->
        conn
        |> send_resp(400, "#{err}")
        |> halt
    end
  end
...
end

And the plug access the channel_secret using opts[:channel_secret].

Now, these piece of code is running fine in my local development. But when I build the release into a docker image and deploy it, somehow the opts[:channel_secret] became nil while the opts[:handler] is not changing.
The weider thing is when use the release binary remote command and run Hibiki.Config.channel_secret() it does returns the correct value.

This is after I refactor the plug from hibiki_web to linesdk. Before it was fine. But in both cases, it is still the hibiki_web app that calls the Hibiki.Config.channel_secret() but somehow when the released app is running it returns nil. Can anybody help me? Thank you very much!

Showing Posts 1 to 2

Nicd

Nicd

Since you are using the function in your router’s post macro for init values, most likely the value is set at compile time (plug init calls are made at compile time). So check that the value is set correctly when you are compiling the release. Or if you only want to set the value on your target machine, you will need to refactor your code to grab it at runtime.

ridho9

ridho9 OP

Ah, that makes sense. I tried to pass the &Mod.fun/ar instead and it works. It seems I have to find another way to pass the value. Thanks!

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

Papipo
Name: Rodrigo Álvarez Location: Gijón, Spain Available for full remote backend/fullstack work. Experience: More than 20 years, 20 of t...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews