Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Web dashboard for the FunWithFlags Elixir package

License

NotificationsYou must be signed in to change notification settings

tompave/fun_with_flags_ui

Repository files navigation

Mix TestsCode Quality
Hex.pm

A Web dashboard for theFunWithFlags Elixir package.

How to run

FunWithFlags.UI is just a plug and it can be run in a number of ways.It's primarily meant to be embedded in a host Plug application, either Phoenix or another Plug app.

Mounted in Phoenix

The router plug can be mounted inside the Phoenix router withPhoenix.Router.forward/4.

defmoduleMyPhoenixAppWeb.RouterdouseMyPhoenixAppWeb,:routerpipeline:mounted_appsdoplug:accepts,["html"]plug:put_secure_browser_headersendscopepath:"/feature-flags"dopipe_through:mounted_appsforward"/",FunWithFlags.UI.Router,namespace:"feature-flags"endend

Note: There is no need to add:protect_from_forgery to the:mounted_apps pipeline because this package already implements CSRF protection. In order to enable it, your host application must use thePlug.Session plug, which is usually configured in the endpoint module in Phoenix.

Mounted in another Plug application

Since it's just a plug, it can also be mounted into any other Plug application usingPlug.Router.forward/2.

defmoduleAnother.AppdousePlug.Routerforward"/feature-flags",to:FunWithFlags.UI.Router,init_opts:[namespace:"feature-flags"]end

Note: If your plug router usesPlug.CSRFProtection,FunWithFlags.UI.Router should be added before your CSRF protection plug because it already implements its own CSRF protection. If you declareFunWithFlags.UI.Router after, your CSRF plug will likely block GET requests for the JS assets of the dashboard.

Standalone

Again, because it's just a plug, it can be runstandalone.

If you clone the repository, the library comes with two convenience functions to accomplish this:

# Simple, let Cowboy sort out the supervision tree:{:ok,pid}=FunWithFlags.UI.run_standalone()# Uses some explicit supervision configuration:{:ok,pid}=FunWithFlags.UI.run_supervised()

These functions come in handy for local development, and arenot necessary when embedding the Plug into a host application.

Please note that even though theFunWithFlags.UI module implements theApplication behavior and comes with a properstart/2 callback, this is not enabled by design and, in fact, the Mixfile doesn't declare an entry module.

If you really need to run it standalone in a reliable manner, you are encouraged to write your own supervision setup.

Security

For obvious reasons, you don't want to make this web control panel publicly accessible.

The library itself doesn't provide any auth functionality because, as a Plug, it is easier to wrap it into the authentication and authorization logic of the host application.

The easiest thing to do is to protect it with HTTP Basic Auth, provided by Plug itself.

For example, in Phoenix:

defmodule MyPhoenixAppWeb.Router do  use MyPhoenixAppWeb, :router+ import Plug.BasicAuth  pipeline :mounted_apps do    plug :accepts, ["html"]    plug :put_secure_browser_headers+   plug :basic_auth, username: "foo", password: "bar"  end  scope path: "/feature-flags" do    pipe_through :mounted_apps    forward "/", FunWithFlags.UI.Router, namespace: "feature-flags"  endend

Caveats

While the basefun_with_flags library is quite relaxed in terms of valid flag names, group names and actor identifers, this web dashboard extension applies some more restrictive rules.The reason is that allfun_with_flags cares about is that some flag and group names can be represented as an Elixir Atom, while actor IDs are just strings. Since you can use that API in your code, the library will only check that the parameters have the right type.

Things change on the web, however. Think about the binary"Ook? Ook!". In code, it can be accepted as a valid flag name:

{:ok,true}=FunWithFlags.enable(:"Ook? Ook!",for_group::"weird, huh?")

On the web, however, the question mark makes working with URLs a bit tricky: inhttp://localhost:8080/flags/Ook?%20Ook!, the flag name will beOok and the rest will be a query string.

For this reason this library enforces some stricter rules when creating flags and groups. Blank values are not allowed,? neither, and flag names must match/^w+$/.

Installation

The package can be installed by addingfun_with_flags_ui to your list of dependencies inmix.exs.
It requiresfun_with_flags, see itsinstallation documentation for more details.

defdepsdo[{:fun_with_flags_ui,"~> 1.1"}]end

About

Web dashboard for the FunWithFlags Elixir package

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp