-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
134 additions
and
127 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Triplex.EnsurePlugConfig do | ||
@moduledoc """ | ||
This is a struct that holds the configuration for `Triplex.EnsurePlug`. | ||
Here are the config keys allowed: | ||
- `assign`: the name of the assign where we must save the tenant. | ||
- `callback`: function that might be called when the plug succeeded. It | ||
must return a connection. | ||
- `failure_callback`: function that might be called when the plug failed. | ||
It must return a connection. | ||
""" | ||
|
||
defstruct [:callback, :failure_callback, assign: :current_tenant] | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Triplex.ParamPlug do | ||
@moduledoc """ | ||
This is a basic plug that loads the current tenant assign from a given | ||
param. | ||
To plug it on your router, you can use: | ||
plug Triplex.ParamPlug, | ||
param: :subdomain, | ||
tenant_handler: &TenantHelper.tenant_handler/1 | ||
See `Triplex.ParamPlugConfig` to check all the allowed `config` flags. | ||
""" | ||
|
||
import Triplex.Plug | ||
alias Triplex.ParamPlugConfig | ||
|
||
@doc false | ||
def init(opts), do: struct(ParamPlugConfig, opts) | ||
|
||
@doc false | ||
def call(conn, config), | ||
do: put_tenant(conn, get_param(conn, config.param), config) | ||
|
||
defp get_param(conn, %ParamPlugConfig{param: key}), | ||
do: get_param(conn, key) | ||
defp get_param(conn, key) when is_atom(key), | ||
do: get_param(conn, Atom.to_string(key)) | ||
defp get_param(conn, key), | ||
do: conn.params[key] | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Triplex.ParamPlugConfig do | ||
@moduledoc """ | ||
This is a struct that holds all configuration for `Triplex.ParamPlug`. | ||
Here are the config keys allowed: | ||
- `tenant_handler`: function to handle the tenant param. Its return will | ||
be used as the tenant. | ||
- `assign`: the name of the assign where we must save the tenant. | ||
- `param`: the param name to load the tenant from. | ||
""" | ||
|
||
defstruct [:tenant_handler, assign: :current_tenant, param: "tenant"] | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Triplex.SessionPlugConfig do | ||
@moduledoc """ | ||
This is a struct that holds the configuration for `Triplex.SessionPlug`. | ||
Here are the config keys allowed: | ||
- `tenant_handler`: function to handle the tenant param. Its return will | ||
be used as the tenant. | ||
- `assign`: the name of the assign where we must save the tenant. | ||
- `session`: the session param name to load the tenant from. | ||
""" | ||
|
||
defstruct [ | ||
:tenant_handler, | ||
assign: :current_tenant, | ||
session: :tenant | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Triplex.SubdomainPlugConfig do | ||
@moduledoc """ | ||
This is a struct that holds the configuration for `Triplex.SubdomainPlug`. | ||
Here are the config keys allowed: | ||
- `tenant_handler`: function to handle the tenant param. Its return will | ||
be used as the tenant. | ||
- `assign`: the name of the assign where we must save the tenant. | ||
- `endpoint`: the Phoenix.Endpoint to get the host name to dicover the | ||
subdomain. | ||
""" | ||
|
||
defstruct [ | ||
:endpoint, | ||
:tenant_handler, | ||
assign: :current_tenant, | ||
] | ||
end |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.