diff --git a/backend/config/config.exs b/backend/config/config.exs index 78dbfb5dc..4efc21857 100644 --- a/backend/config/config.exs +++ b/backend/config/config.exs @@ -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. @@ -112,6 +112,8 @@ config :edgehog, :edgehog_forwarder, %{ enabled?: true } +config :edgehog, :features, containers: true + config :edgehog, ecto_repos: [Edgehog.Repo] diff --git a/backend/config/prod.exs b/backend/config/prod.exs index fdd909377..681123f64 100644 --- a/backend/config/prod.exs +++ b/backend/config/prod.exs @@ -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. @@ -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} diff --git a/backend/lib/edgehog/containers/containers.ex b/backend/lib/edgehog/containers/containers.ex index 2f33efd06..315a94f8d 100644 --- a/backend/lib/edgehog/containers/containers.ex +++ b/backend/lib/edgehog/containers/containers.ex @@ -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. @@ -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 @@ -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 diff --git a/backend/lib/edgehog/features.ex b/backend/lib/edgehog/features.ex new file mode 100644 index 000000000..4f8ca70ba --- /dev/null +++ b/backend/lib/edgehog/features.ex @@ -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