Skip to content

Commit 3beae9f

Browse files
committed
toil(front): introduce Front.saas?/0 to determine environment
1 parent 5e8003e commit 3beae9f

File tree

13 files changed

+113
-102
lines changed

13 files changed

+113
-102
lines changed

front/config/runtime.exs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ config :front,
131131

132132
config :front, :on_prem?, on_prem?
133133

134-
if on_prem? do
135-
config :front,
136-
feature_provider:
137-
{FeatureProvider.YamlProvider,
138-
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}
139134

140-
config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
141-
else
135+
edition = System.get_env("EDITION", "") |> String.trim() |> String.downcase()
136+
is_saas? = !(on_prem? or edition in ["ce", "ee"])
137+
138+
if is_saas? do
142139
config :front,
143140
feature_provider:
144141
{Front.FeatureHubProvider,
@@ -147,6 +144,13 @@ else
147144
{FeatureProvider.CachexCache,
148145
name: :feature_provider_cache, ttl_ms: :timer.minutes(10)}
149146
]}
147+
else
148+
config :front,
149+
feature_provider:
150+
{FeatureProvider.YamlProvider,
151+
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}
152+
153+
config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
150154
end
151155

152156
if System.get_env("AMQP_URL") != nil do
@@ -190,6 +194,4 @@ config :front,
190194
:single_tenant,
191195
System.get_env("SINGLE_TENANT") == "true"
192196

193-
config :front,
194-
:edition,
195-
System.get_env("EDITION", "") |> String.trim() |> String.downcase()
197+
config :front, :edition, edition

front/lib/front.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ defmodule Front do
3535
def os? do
3636
ee?() || ce?()
3737
end
38+
39+
@doc """
40+
Check if we're running on saas or not
41+
"""
42+
@spec saas?() :: boolean()
43+
def saas? do
44+
!(on_prem?() or os?())
45+
end
3846
end

front/lib/front/clients/billing.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,26 +314,26 @@ defmodule Front.Clients.Billing do
314314

315315
defp call_grpc(error = {:error, err}, _, _, _, _, _) do
316316
Logger.error("""
317-
Unexpected error when connecting to Velocity: #{inspect(err)}
317+
Unexpected error when connecting to Billing: #{inspect(err)}
318318
""")
319319

320320
error
321321
end
322322

323323
defp call_grpc({:ok, channel}, module, function_name, request, metadata, timeout) do
324-
if Front.on_prem?() do
325-
{:error, "Billing service is not running on on-prem instance"}
326-
else
324+
if Front.saas?() do
327325
apply(module, function_name, [channel, request, [metadata: metadata, timeout: timeout]])
326+
else
327+
{:error, "Billing service is running only on saas instance"}
328328
end
329329
end
330330

331331
defp channel do
332-
if Front.on_prem?() do
333-
{:error, "Billing service is not running on on-prem instance"}
334-
else
332+
if Front.saas?() do
335333
Application.fetch_env!(:front, :billing_api_grpc_endpoint)
336334
|> GRPC.Stub.connect()
335+
else
336+
{:error, "Billing service is running only on saas instance"}
337337
end
338338
end
339339

front/lib/front/layout/cache_invalidator.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ defmodule Front.Layout.CacheInvalidator do
314314
end
315315

316316
def invalidate_billing(org_id) do
317-
if not Front.on_prem?() do
317+
if Front.saas?() do
318318
Front.Clients.Billing.invalidate_cache(:list_spendings, %{org_id: org_id})
319319
Front.Clients.Billing.invalidate_cache(:current_spending, %{org_id: org_id})
320320
Front.Clients.Billing.invalidate_cache(:credits_usage, %{org_id: org_id})

front/lib/front/models/organization_onboarding.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ defmodule Front.Models.OrganizationOnboarding do
125125

126126
@spec validate_billing(model :: t()) :: :ok | {:error, String.t()}
127127
defp validate_billing(model) do
128-
if Front.on_prem?() do
129-
:ok
130-
else
128+
if Front.saas?() do
131129
BillingClient.can_setup_organization(%{
132130
owner_id: model.user_id
133131
})
@@ -136,6 +134,8 @@ defmodule Front.Models.OrganizationOnboarding do
136134
{:ok, %{allowed: false, errors: messages}} -> {:error, Enum.join(messages, ", ")}
137135
{:error, _} -> {:error, "Account check failed"}
138136
end
137+
else
138+
:ok
139139
end
140140
end
141141

front/lib/front_web/controllers/project_onboarding_controller.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ defmodule FrontWeb.ProjectOnboardingController do
630630
) do
631631
project_onboarding_path(conn, :onboarding_index, project.name, [""])
632632
else
633+
# TODO: check with Amir
633634
if Front.on_prem?() do
634635
if Models.Project.file_exists?(project.id, project.initial_pipeline_file) do
635636
project_onboarding_path(conn, :existing_configuration, project.name)

front/lib/front_web/templates/account/show.html.eex

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,48 @@
2727
<%= case {@user.github_scope, @user.github_login} do %>
2828
<% {:NONE, nil} -> %>
2929
<span class="red">Not Connected</span>
30-
<%= unless Front.on_prem?() do %>
31-
<div>
32-
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
33-
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
34-
</div>
30+
<%= if Front.saas?() do %>
31+
<div>
32+
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
33+
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
34+
</div>
3535
<% else %>
36-
<div>
37-
<%= link "Connect…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :email]), method: :post %>
38-
</div>
36+
<div>
37+
<%= link "Connect…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :email]), method: :post %>
38+
</div>
3939
<% end %>
4040
<% {:NONE, _} -> %>
4141
<span class="red">Not Connected</span>
4242
·
4343
<span><a href="https://github.com/<%= @user.github_login %>" target="_blank">@<%= @user.github_login %></a></span>
44-
<%= unless Front.on_prem?() do %>
45-
<div>
46-
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
47-
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
48-
</div>
44+
<%= if Front.saas?() do %>
45+
<div>
46+
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
47+
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
48+
</div>
4949
<% end %>
5050
<% {:EMAIL, _} -> %>
5151
<span class="green">Connected</span>
5252
·
5353
<span class="gray">email only</span>
5454
·
5555
<span><a href="https://github.com/<%= @user.github_login %>" target="_blank">@<%= @user.github_login %></a></span>
56-
<%= unless Front.on_prem?() do %>
57-
<div>
58-
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
59-
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
60-
</div>
56+
<%= if Front.saas?() do %>
57+
<div>
58+
<%= link "Grant public access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :public]), method: :post %>
59+
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
60+
</div>
6161
<% end %>
6262
<% {:PUBLIC, _} -> %>
6363
<span class="green">Connected</span>
6464
·
6565
<span class="gray">public repositories</span>
6666
·
6767
<span><a href="https://github.com/<%= @user.github_login %>" target="_blank">@<%= @user.github_login %></a></span>
68-
<%= unless Front.on_prem?() do %>
69-
<div>
70-
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
71-
</div>
68+
<%= if Front.saas?() do %>
69+
<div>
70+
<%= link "Grant private access…", to: account_path(@conn, :update_repo_scope, "github", [access_level: :private]), method: :post %>
71+
</div>
7272
<% end %>
7373
<% {:PRIVATE, _} -> %>
7474
<span class="green">Connected</span>

front/lib/front_web/templates/error/404.html.eex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<a href="https://me.<%= Application.fetch_env!(:front, :domain) %>/" class="db">
4545
<img src="<%= assets_path() %>/images/semaphore-logo-full-white.svg" alt="Semaphore Logo">
4646
</a>
47-
<%= if not Front.on_prem?() do %>
47+
<%= if Front.saas?() do %>
4848
<div class="flex-ns items-center">
4949
<div class="f5 fw5 pr2 mv3 mv0-m flex justify-center">
5050
<a href="https://<%= Application.fetch_env!(:front, :domain) %>/product" class="link white-90 hover-white ph2">Product</a>
@@ -72,7 +72,7 @@
7272
<%= if anonymous?(@conn) do %>
7373
<p class="f4 black-80 mb3=0">Perhaps you need to <a href="<%= login_url(@conn) %>" class="link black-50 hover-black-80">log in →</a></p>
7474
<% else %>
75-
<%= if not Front.on_prem?() do %>
75+
<%= if Front.saas?() do %>
7676
<%= if Enum.all?([:user, :project], fn m -> Enum.member?(Map.keys(@conn.assigns), m) end) do %>
7777
<%= if @conn.assigns.user.gitlab_scope == :NONE &&
7878
@conn.assigns.project.integration_type == :GITLAB do %>

front/lib/front_web/templates/layout/_anonymous_page_header.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="flex items-center flex-shrink-0">
99
<p class="f6 mb0">Blazing-fast build and deploy!</p>
1010
<a href="<%= login_url(@conn) %>" class="btn btn-secondary btn-small ml3">Log in</a>
11-
<%= if not Front.on_prem?() do %>
11+
<%= if Front.saas?() do %>
1212
<a href="<%= signup_url(@conn) %>" class="btn btn-secondary btn-small ml3">Sign up</a>
1313
<% end %>
1414
</div>

front/lib/front_web/templates/layout/organization_settings.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<%= link "Okta Integration", to: organization_okta_path(@conn, :show), class: "link db pv1 ph3 br3 dark-gray hover-bg-lightest-gray" %>
5151
<% end %>
5252
<% end %>
53-
<%= if not Front.on_prem?() do %>
53+
<%= if Front.saas?() do %>
5454
<%= if @conn.request_path =~ organization_contacts_path(@conn, :show) do %>
5555
<%= link "Contacts", to: organization_contacts_path(@conn, :show), class: "link db pv1 ph3 br3 bg-green white" %>
5656
<% else %>

0 commit comments

Comments
 (0)