Giter Club home page Giter Club logo

Comments (5)

teamon avatar teamon commented on June 9, 2024 1

Ahh, actually this won't work, as stated in Plug docs init might be called during compilation.

from verk_web.

teamon avatar teamon commented on June 9, 2024

It probably could be something simple like this:

defmodule VerkBasicAuth do
  @behaviour Plug

  def init(_opts) do
    if Application.get_env(:verk_web, :authorization) do
      BasicAuth.init(use_config: {:verk_web, :authorization})
    else
      :no_auth
    end
  end

  def call(conn, :no_auth), do: conn
  def call(%{request_path: "/verk" <> _} = conn, opts), do: BasicAuth.call(conn, opts)
  def call(conn, _), do: conn
end

from verk_web.

tlvenn avatar tlvenn commented on June 9, 2024

I have submitted a PR in Verk to address this kind of issue by leveraging Confex. Happy to submit a PR here to do the same.

from verk_web.

edgurgel avatar edgurgel commented on June 9, 2024

@tlvenn, I don't think this issue is related to environment variables versus application configuration. I may be completely wrong here but the issue here is that the plug is added at compile time.

from verk_web.

tlvenn avatar tlvenn commented on June 9, 2024

Good catch @edgurgel. With Phoenix 1.3, you can leverage load_from_system_env to solve this problem:

@doc """
  Dynamically loads configuration from the system environment
  on startup.

  It receives the endpoint configuration from the config files
  and must return the updated configuration.
  """
  def load_from_system_env(config) do
    config = Confex.process_env(config)

    unless config[:secret_key_base] do
      raise "Set SECRET_KEY environment variable!"
    end

    {:ok, config}
  end

https://github.com/Nebo15/pkcs7_verify.api/blob/master/lib/pkcs7_verify_api/web/endpoint.ex#L30

from verk_web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.