Skip to content

Commit

Permalink
Merge pull request #48 from pluralsh/multiurl-oicd
Browse files Browse the repository at this point in the history
Allow for multi-url recipes to be used for installation
  • Loading branch information
michaeljguarino authored May 25, 2022
2 parents b09c1d7 + c08747c commit 3323332
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/console/plural/models.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Console.Plural.Repository do
end

defmodule Console.Plural.OIDCSettings do
defstruct [:authMethod, :domainKey, :uriFormat, :subdomain]
defstruct [:authMethod, :domainKey, :uriFormat, :uriFormats, :subdomain]
end

defmodule Console.Plural.ProviderBinding do
Expand Down
1 change: 1 addition & 0 deletions lib/console/plural/queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ defmodule Console.Plural.Queries do
oidcSettings {
domainKey
uriFormat
uriFormats
authMethod
subdomain
}
Expand Down
17 changes: 10 additions & 7 deletions lib/console/services/plural.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,24 @@ defmodule Console.Services.Plural do
true) do
with {:ok, %{id: me}} <- Users.me(),
{:ok, %{id: inst_id} = installation} <- Repositories.get_installation(name),
{:ok, url} <- format_url(oidc_settings, context[name]),
{:ok, manifest} <- Manifest.get(),
{:ok, _} <- Repositories.upsert_oidc_provider(inst_id, merge_provider(%{
redirectUris: [url],
redirectUris: format_urls(oidc_settings, context[name], manifest),
authMethod: method,
bindings: [%{userId: me}]
}, installation)),
do: :ok
end
def configure_oidc(_, _, _), do: :ok

def format_url(%{uriFormat: uri} = oidc_settings, ctx) do
with {:ok, manifest} <- Manifest.get() do
uri = format_oidc(:domain, uri, oidc_settings, ctx)
{:ok, format_oidc(:subdomain, uri, oidc_settings, manifest)}
end
defp format_urls(%{uriFormats: [_ | _] = uris} = settings, ctx, man),
do: Enum.map(uris, &format_url(&1, settings, ctx, man))
defp format_urls(%{uriFormat: uri} = settings, ctx, man),
do: [format_url(uri, settings, ctx, man)]

defp format_url(uri, oidc_settings, ctx, manifest) do
uri = format_oidc(:domain, uri, oidc_settings, ctx)
format_oidc(:subdomain, uri, oidc_settings, manifest)
end

defp format_oidc(:domain, uri, %{domainKey: key}, ctx) when is_binary(key),
Expand Down

0 comments on commit 3323332

Please sign in to comment.