Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion front/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CONTAINER_ENV_VARS = \


CONTAINER_CE_ENV_VARS =\
-e CE_ROLES=true \
-e EDITION=ce \
-e SEED_CLOUD_MACHINES=false \
-e SEED_SELF_HOSTED_AGENTS=true \
-e SEED_CE_FEATURES=true \
Expand Down
35 changes: 11 additions & 24 deletions front/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ config :front,
cookie_name: System.get_env("COOKIE_NAME"),
use_rbac_api: if(System.get_env("USE_RBAC_API") == "true", do: true, else: false)

on_prem? = if(System.get_env("ON_PREM") == "true", do: true, else: false)

# Internal API endpoints - always read from environment variables for all environments
# Test environment will need these env vars set, or use stubs in test setup
config :front,
Expand Down Expand Up @@ -131,16 +129,10 @@ config :front,
zendesk_snippet_id: System.get_env("ZENDESK_SNIPPET_ID"),
google_gtag: System.get_env("GOOGLE_GTAG")

config :front, :on_prem?, on_prem?
edition = System.get_env("EDITION", "") |> String.trim() |> String.downcase()
is_saas? = !(edition in ["ce", "ee"])

if on_prem? do
config :front,
feature_provider:
{FeatureProvider.YamlProvider,
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}

config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
else
if is_saas? do
config :front,
feature_provider:
{Front.FeatureHubProvider,
Expand All @@ -149,6 +141,13 @@ else
{FeatureProvider.CachexCache,
name: :feature_provider_cache, ttl_ms: :timer.minutes(10)}
]}
else
config :front,
feature_provider:
{FeatureProvider.YamlProvider,
[yaml_path: System.get_env("FEATURE_YAML_PATH"), agent_name: :feature_provider_agent]}

config :front, JobPage.Api.Loghub, timeout: :timer.minutes(2)
end

if System.get_env("AMQP_URL") != nil do
Expand All @@ -166,8 +165,6 @@ end

config :front, :audit_logging, System.get_env("AUDIT_LOGGING") == "true"

config :front, :ce_roles, System.get_env("CE_ROLES") == "true"

config :front,
:hide_promotions,
System.get_env("HIDE_PROMOTIONS") == "true"
Expand All @@ -180,18 +177,8 @@ config :front,
:new_project_onboarding_workflow_templates_path,
System.fetch_env!("WORKFLOW_TEMPLATES_YAMLS_PATH") <> "_new"

config :front,
:hide_bitbucket_me_page,
System.get_env("HIDE_BITBUCKET_ME_PAGE") == "true"

config :front,
:hide_gitlab_me_page,
System.get_env("HIDE_GITLAB_ME_PAGE") == "true"

config :front,
:single_tenant,
System.get_env("SINGLE_TENANT") == "true"

config :front,
:edition,
System.get_env("EDITION", "") |> String.trim() |> String.downcase()
config :front, :edition, edition
4 changes: 0 additions & 4 deletions front/helm/templates/job-page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ spec:
{{- end }}
- name: METRICS_SERVICE
value: "front"
- name: ON_PREM
value: "true"
- name: FEATURE_YAML_PATH
value: {{ .Values.featureFlags.mountPath | quote }}
- name: GETTING_STARTED_YAML_PATH
Expand All @@ -124,8 +122,6 @@ spec:
{{- if eq .Values.global.edition "ce" }}
- name: "SKIP_VELOCITY"
value: "true"
- name: "CE_ROLES"
value: "true"
- name: "HIDE_PROMOTIONS"
value: "true"
{{- end }}
Expand Down
4 changes: 0 additions & 4 deletions front/helm/templates/project-page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ spec:
{{- end }}
- name: METRICS_SERVICE
value: "front"
- name: ON_PREM
value: "true"
- name: START_TELEMETRY
value: {{ .Values.global.telemetry.enabled | quote }}
- name: TELEMETRY_CRON
Expand All @@ -154,8 +152,6 @@ spec:
{{- if eq .Values.global.edition "ce" }}
- name: "SKIP_VELOCITY"
value: "true"
- name: "CE_ROLES"
value: "true"
- name: "HIDE_PROMOTIONS"
value: "true"
{{- end }}
Expand Down
4 changes: 0 additions & 4 deletions front/helm/templates/ui-cache-reactor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ spec:
- name: METRICS_NAMESPACE
value: {{ .Values.global.statsd.metricsNamespace }}
{{- end }}
- name: ON_PREM
value: "true"
- name: FEATURE_YAML_PATH
value: {{ .Values.featureFlags.mountPath | quote }}
- name: GETTING_STARTED_YAML_PATH
Expand All @@ -106,8 +104,6 @@ spec:
{{- if eq .Values.global.edition "ce" }}
- name: "SKIP_VELOCITY"
value: "true"
- name: "CE_ROLES"
value: "true"
- name: "HIDE_PROMOTIONS"
value: "true"
{{- end }}
Expand Down
21 changes: 8 additions & 13 deletions front/lib/front.ex
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
defmodule Front do
@doc """
Checks if application is running on-prem environment
"""
@spec on_prem?() :: boolean()
def on_prem? do
Application.get_env(:front, :on_prem?)
end

@spec ce_roles?() :: boolean()
def ce_roles? do
Application.get_env(:front, :ce_roles)
end

@doc """
Check if it's CE edition
"""
Expand All @@ -35,4 +22,12 @@ defmodule Front do
def os? do
ee?() || ce?()
end

@doc """
Check if we're running on saas or not
"""
@spec saas?() :: boolean()
def saas? do
!os?()
end
end
14 changes: 7 additions & 7 deletions front/lib/front/clients/billing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,26 @@ defmodule Front.Clients.Billing do

defp call_grpc(error = {:error, err}, _, _, _, _, _) do
Logger.error("""
Unexpected error when connecting to Velocity: #{inspect(err)}
Unexpected error when connecting to Billing: #{inspect(err)}
""")

error
end

defp call_grpc({:ok, channel}, module, function_name, request, metadata, timeout) do
if Front.on_prem?() do
{:error, "Billing service is not running on on-prem instance"}
else
if Front.saas?() do
apply(module, function_name, [channel, request, [metadata: metadata, timeout: timeout]])
else
{:error, "Billing service is running only on saas instance"}
end
end

defp channel do
if Front.on_prem?() do
{:error, "Billing service is not running on on-prem instance"}
else
if Front.saas?() do
Application.fetch_env!(:front, :billing_api_grpc_endpoint)
|> GRPC.Stub.connect()
else
{:error, "Billing service is running only on saas instance"}
end
end

Expand Down
33 changes: 32 additions & 1 deletion front/lib/front/feature_hub_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@ defmodule Front.FeatureHubProvider do
Availability,
Machine,
OrganizationFeature,
Feature,
OrganizationMachine
}

import Front.Utils

@impl FeatureProvider.Provider
def provide_features(org_id, _opts \\ []) do
def provide_features(org_id, opts \\ [])

def provide_features(nil, _opts) do
%InternalApi.Feature.ListFeaturesRequest{}
|> FeatureClient.list_features()
|> unwrap(fn response ->
features =
response.features
|> Enum.map(&feature_from_grpc/1)
|> Enum.filter(&FeatureProvider.Feature.visible?/1)

ok(features)
end)
end

def provide_features(org_id, _opts) do
FeatureClient.list_organization_features(%{org_id: org_id})
|> unwrap(fn response ->
features =
Expand All @@ -38,6 +54,21 @@ defmodule Front.FeatureHubProvider do
end)
end

defp feature_from_grpc(%Feature{
availability: availability,
name: name,
type: type,
description: description
}) do
%FeatureProvider.Feature{
name: name,
type: type,
description: description,
quantity: quantity_from_availability(availability),
state: state_from_availability(availability)
}
end

defp feature_from_grpc(%OrganizationFeature{feature: feature, availability: availability}) do
%FeatureProvider.Feature{
name: feature.name,
Expand Down
2 changes: 1 addition & 1 deletion front/lib/front/layout/cache_invalidator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ defmodule Front.Layout.CacheInvalidator do
end

def invalidate_billing(org_id) do
if not Front.on_prem?() do
if Front.saas?() do
Front.Clients.Billing.invalidate_cache(:list_spendings, %{org_id: org_id})
Front.Clients.Billing.invalidate_cache(:current_spending, %{org_id: org_id})
Front.Clients.Billing.invalidate_cache(:credits_usage, %{org_id: org_id})
Expand Down
6 changes: 3 additions & 3 deletions front/lib/front/models/organization_onboarding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ defmodule Front.Models.OrganizationOnboarding do

@spec validate_billing(model :: t()) :: :ok | {:error, String.t()}
defp validate_billing(model) do
if Front.on_prem?() do
:ok
else
if Front.saas?() do
BillingClient.can_setup_organization(%{
owner_id: model.user_id
})
Expand All @@ -136,6 +134,8 @@ defmodule Front.Models.OrganizationOnboarding do
{:ok, %{allowed: false, errors: messages}} -> {:error, Enum.join(messages, ", ")}
{:error, _} -> {:error, "Account check failed"}
end
else
:ok
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule FrontWeb.OrganizationOktaController do
with {:ok, model} <- create_integration(org_id, user_id, integration),
{:ok, token} <- gen_token(model) do
Watchman.increment(watchman_name(:create, :success))
if Front.on_prem?(), do: log_create(conn, user_id, model)
if Front.os?(), do: log_create(conn, user_id, model)

conn
|> put_flash(:notice, "Success: Your organization is connected with Okta")
Expand Down
2 changes: 1 addition & 1 deletion front/lib/front_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule FrontWeb.PageController do
def status404(conn, _params) do
# On onprem, if user isn't logged in, we want to redirect user to okta login
# right away, without showing the 404 page
if anonymous?(conn) == true and Front.on_prem?() do
if anonymous?(conn) == true and Front.os?() do
conn
|> put_resp_header("location", login_url(conn))
|> send_resp(302, "")
Expand Down
8 changes: 4 additions & 4 deletions front/lib/front_web/controllers/people_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ defmodule FrontWeb.PeopleController do
user_type = params["type"] || ""

member_role_id =
if Front.ce_roles?() do
if Front.ce?() do
{:ok, roles} = RoleManagement.list_possible_roles(org_id, "org_scope")

member_role = Enum.find(roles, fn role -> role.name == "Member" end)
Expand Down Expand Up @@ -501,7 +501,7 @@ defmodule FrontWeb.PeopleController do

defp create_email_member(conn, params) do
Watchman.benchmark("people.create_member", fn ->
if email_members_supported?(conn.assigns.organization_id) || Front.ce_roles?() do
if email_members_supported?(conn.assigns.organization_id) || Front.ce?() do
user_id = conn.assigns.user_id
org_id = conn.assigns.organization_id

Expand Down Expand Up @@ -800,7 +800,7 @@ defmodule FrontWeb.PeopleController do

defp change_user_email(conn, user_id, email) do
Watchman.benchmark("people.change_email", fn ->
if email_members_supported?(conn.assigns.organization_id) || Front.ce_roles?() do
if email_members_supported?(conn.assigns.organization_id) || Front.ce?() do
conn
|> Audit.new(:User, :Modified)
|> Audit.add(description: "Change Email")
Expand Down Expand Up @@ -867,7 +867,7 @@ defmodule FrontWeb.PeopleController do

defp reset_user_password(conn, user_id) do
Watchman.benchmark("people.reset_password", fn ->
if email_members_supported?(conn.assigns.organization_id) || Front.ce_roles?() do
if email_members_supported?(conn.assigns.organization_id) || Front.ce?() do
conn
|> Audit.new(:User, :Modified)
|> Audit.add(description: "Reset Password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,14 @@ defmodule FrontWeb.ProjectOnboardingController do
) do
project_onboarding_path(conn, :onboarding_index, project.name, [""])
else
if Front.on_prem?() do
if Front.saas?() do
project_onboarding_path(conn, :invite_collaborators, project.name)
else
if Models.Project.file_exists?(project.id, project.initial_pipeline_file) do
project_onboarding_path(conn, :existing_configuration, project.name)
else
project_onboarding_path(conn, :template, project.name)
end
else
project_onboarding_path(conn, :invite_collaborators, project.name)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ defmodule FrontWeb.ProjectSettingsController do

changeset = DeletionValidator.run(project, params)

if Front.on_prem?() or changeset.valid? do
if Front.os?() or changeset.valid? do
case Project.destroy(project.id, user_id, org_id) do
{:ok, _} ->
conn
Expand Down
2 changes: 1 addition & 1 deletion front/lib/front_web/controllers/roles_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule FrontWeb.RolesController do
case Async.await(async_role) do
{:ok, role} ->
async_roles = fetch_roles_async(conn.assigns.organization_id)
scope = if Front.ce_roles?(), do: "", else: role.scope
scope = if Front.ce?(), do: "", else: role.scope
async_permissions = fetch_permissions_async(scope)

{:ok, roles} = Async.await(async_roles)
Expand Down
2 changes: 1 addition & 1 deletion front/lib/front_web/plugs/onprem_blocker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule FrontWeb.Plugs.OnPremBlocker do
def init(default), do: default

def call(conn, _opts) do
if Front.on_prem?() do
if Front.os?() do
Logger.info("Blocking access to #{conn.request_path} because of on-premises")

conn
Expand Down
Loading