Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flags): add feature flags #794

Open
wants to merge 1 commit into
base: feature/application-management
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion backend/config/config.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Edgehog.
#
# Copyright 2021-2024 SECO Mind Srl
# Copyright 2021 - 2025 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -112,6 +112,8 @@ config :edgehog, :edgehog_forwarder, %{
enabled?: true
}

config :edgehog, :features, containers: true

config :edgehog,
ecto_repos: [Edgehog.Repo]

Expand Down
3 changes: 2 additions & 1 deletion backend/config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Edgehog.
#
# Copyright 2021 SECO Mind Srl
# Copyright 2021 - 2025 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@ import Config
# which you should run after static files are built and
# before starting your production server.
config :edgehog, EdgehogWeb.Endpoint, url: [host: "example.com", port: 80]
config :edgehog, :features, containers: false

# Configure Logfmt
config :logger, :console, format: {PrettyLog.LogfmtFormatter, :format}
Expand Down
80 changes: 42 additions & 38 deletions backend/lib/edgehog/containers/containers.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Edgehog.
#
# Copyright 2024 SECO Mind Srl
# Copyright 2025 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,8 @@ defmodule Edgehog.Containers do
AshGraphql.Domain
]

import Edgehog.Features

alias Edgehog.Containers.Application
alias Edgehog.Containers.Deployment
alias Edgehog.Containers.DeploymentReadyAction
Expand All @@ -35,55 +37,57 @@ defmodule Edgehog.Containers do
graphql do
root_level_errors? true

queries do
list Application, :applications, :read do
description "Returns all the available applications."
end
if feature_available?(:containers) do
queries do
list Application, :applications, :read do
description "Returns all the available applications."
end

get ImageCredentials, :image_credentials, :read do
description "Returns the desired image credentials."
end
get ImageCredentials, :image_credentials, :read do
description "Returns the desired image credentials."
end

list ImageCredentials, :list_image_credentials, :read do
description "Returns all available image credentials."
end
list ImageCredentials, :list_image_credentials, :read do
description "Returns all available image credentials."
end

get Application, :application, :read do
description "Returns the desired application."
end
get Application, :application, :read do
description "Returns the desired application."
end

get Release, :release, :read do
description "Returns the desired release."
get Release, :release, :read do
description "Returns the desired release."
end
end
end

mutations do
create Application, :create_application, :create do
description "Create a new application."
end
mutations do
create Application, :create_application, :create do
description "Create a new application."
end

create Release, :create_release, :create do
description "Create a new release."
relay_id_translations input: [application_id: :application]
end
create Release, :create_release, :create do
description "Create a new release."
relay_id_translations input: [application_id: :application]
end

create ImageCredentials, :create_image_credentials, :create do
description "Create image credentials."
end
create ImageCredentials, :create_image_credentials, :create do
description "Create image credentials."
end

destroy ImageCredentials, :delete_image_credentials, :destroy
destroy ImageCredentials, :delete_image_credentials, :destroy

create Deployment, :deploy_release, :deploy do
description "Deploy the application on a device"
relay_id_translations input: [release_id: :release, device_id: :device]
end
create Deployment, :deploy_release, :deploy do
description "Deploy the application on a device"
relay_id_translations input: [release_id: :release, device_id: :device]
end

update Deployment, :start_deployment, :start
update Deployment, :stop_deployment, :stop
update Deployment, :delete_deployment, :delete
update Deployment, :start_deployment, :start
update Deployment, :stop_deployment, :stop
update Deployment, :delete_deployment, :delete

update Deployment, :upgrade_deployment, :upgrade_release do
relay_id_translations input: [target: :release]
update Deployment, :upgrade_deployment, :upgrade_release do
relay_id_translations input: [target: :release]
end
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions backend/lib/edgehog/features.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# This file is part of Edgehog.
#
# Copyright 2025 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

defmodule Edgehog.Features do
@moduledoc false
require Logger

def feature_available?(flag) do
value = Application.get_env(:edgehog, :features)[flag]

Logger.info("Flag #{flag} set to #{value}")

value
end
end
Loading