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

Add flag for "SUSE Manager config enabled" #2362

Merged
merged 1 commit into from
Feb 23, 2024
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: 2 additions & 0 deletions assets/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ module.exports = {
globals: {
config: {
checksServiceBaseUrl: '',
suseManagerEnabled: true,
aTestVariable: 123,
},
},

Expand Down
2 changes: 2 additions & 0 deletions assets/js/lib/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-undef
export const getFromConfig = (key) => config[key];
16 changes: 16 additions & 0 deletions assets/js/lib/config/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getFromConfig } from '.';

describe('getFromConfig', () => {
it('should retrieve variable from the config', () => {
// See jest.config.js for global config used in testing
const fetchedConfigVariable = getFromConfig('aTestVariable');

expect(fetchedConfigVariable).toEqual(123);
});

it('should return undefined when variable is not available the config', () => {
const fetchedConfigVariable = getFromConfig('variableThatDoesntExist');

expect(fetchedConfigVariable).toBeUndefined();
});
});
3 changes: 3 additions & 0 deletions assets/js/lib/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getFromConfig } from './config';

export { getFromConfig };
83 changes: 45 additions & 38 deletions assets/js/pages/SettingsPage/SettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import classNames from 'classnames';

import { logError } from '@lib/log';
import { get } from '@lib/network';
import { getFromConfig } from '@lib/config';

import LoadingBox from '@common/LoadingBox';
import PageHeader from '@common/PageHeader';
Expand Down Expand Up @@ -182,47 +183,53 @@ function SettingsPage() {
</div>
</div>
</div>
<div className="py-4">
{softwareUpdatesSettingsLoading ? (
<LoadingBox
className="shadow-none rounded-lg"
text="Loading Settings..."
/>
) : (
<SuseManagerConfig
url={settings.url}
username={settings.username}
{getFromConfig('suseManagerEnabled') && (
<div className="py-4">
{softwareUpdatesSettingsLoading ? (
<LoadingBox
className="shadow-none rounded-lg"
text="Loading Settings..."
/>
) : (
<SuseManagerConfig
url={settings.url}
username={settings.username}
certUploadDate={settings.ca_uploaded_at}
onEditClick={() =>
dispatch(setEditingSoftwareUpdatesSettings(true))
}
clearSettingsDialogOpen={clearingSoftwareUpdatesSettings}
onClearClick={() => setClearingSoftwareUpdatesSettings(true)}
onClearSettings={() => {
setClearingSoftwareUpdatesSettings(false);
dispatch(clearSoftwareUpdatesSettings());
}}
onCancel={() => setClearingSoftwareUpdatesSettings(false)}
/>
)}
<SuseManagerSettingsModal
key={`${settings.url}-${settings.username}-${settings.ca_uploaded_at}-${editingSoftwareUpdatesSettings}`}
open={editingSoftwareUpdatesSettings}
errors={suseManagerValidationErrors}
loading={softwareUpdatesSettingsLoading}
initialUsername={settings.username}
initialUrl={settings.url}
certUploadDate={settings.ca_uploaded_at}
onEditClick={() =>
dispatch(setEditingSoftwareUpdatesSettings(true))
}
clearSettingsDialogOpen={clearingSoftwareUpdatesSettings}
onClearClick={() => setClearingSoftwareUpdatesSettings(true)}
onClearSettings={() => {
setClearingSoftwareUpdatesSettings(false);
dispatch(clearSoftwareUpdatesSettings());
onSave={(payload) => {
if (
settings.username ||
settings.url ||
settings.ca_uploaded_at
) {
dispatch(updateSoftwareUpdatesSettings(payload));
} else {
dispatch(saveSoftwareUpdatesSettings(payload));
}
}}
onCancel={() => setClearingSoftwareUpdatesSettings(false)}
onCancel={() => dispatch(setEditingSoftwareUpdatesSettings(false))}
/>
)}
<SuseManagerSettingsModal
key={`${settings.url}-${settings.username}-${settings.ca_uploaded_at}-${editingSoftwareUpdatesSettings}`}
open={editingSoftwareUpdatesSettings}
errors={suseManagerValidationErrors}
loading={softwareUpdatesSettingsLoading}
initialUsername={settings.username}
initialUrl={settings.url}
certUploadDate={settings.ca_uploaded_at}
onSave={(payload) => {
if (settings.username || settings.url || settings.ca_uploaded_at) {
dispatch(updateSoftwareUpdatesSettings(payload));
} else {
dispatch(saveSoftwareUpdatesSettings(payload));
}
}}
onCancel={() => dispatch(setEditingSoftwareUpdatesSettings(false))}
/>
</div>
</div>
)}
</section>
);
}
Expand Down
2 changes: 2 additions & 0 deletions config/demo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ config :trento, Trento.Infrastructure.Prometheus,

config :trento, Trento.Charts,
host_data_fetcher: Trento.Infrastructure.Prometheus.MockPrometheusApi

config :trento, suse_manager_enabled: true
3 changes: 2 additions & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ config :phoenix, :stacktrace_depth, 20
config :phoenix, :plug_init_mode, :runtime

config :trento,
api_key_authentication_enabled: false
api_key_authentication_enabled: false,
suse_manager_enabled: true

config :joken,
access_token_signer: "s2ZdE+3+ke1USHEJ5O45KT364KiXPYaB9cJPdH3p60t8yT0nkLexLBNw8TFSzC7k",
Expand Down
2 changes: 2 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ config :trento, TrentoWeb.Endpoint,

config :swoosh, local: false

config :trento, suse_manager_enabled: false

# Do not print debug messages in production
# config :logger, level: :info
3 changes: 2 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ config :trento, deregistration_debounce: :timer.seconds(5)

config :trento,
api_key_authentication_enabled: false,
jwt_authentication_enabled: false
jwt_authentication_enabled: false,
suse_manager_enabled: true

config :trento, Trento.Infrastructure.Checks.AMQP.Consumer,
processor: GenRMQ.Processor.Mock,
Expand Down
4 changes: 3 additions & 1 deletion lib/trento_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ defmodule TrentoWeb.PageController do
check_service_base_url = Application.fetch_env!(:trento, :checks_service)[:base_url]
charts_enabled = Application.fetch_env!(:trento, Trento.Charts)[:enabled]
deregistration_debounce = Application.fetch_env!(:trento, :deregistration_debounce)
suse_manager_enabled = Application.fetch_env!(:trento, :suse_manager_enabled)

render(conn, "index.html",
check_service_base_url: check_service_base_url,
charts_enabled: charts_enabled,
deregistration_debounce: deregistration_debounce
deregistration_debounce: deregistration_debounce,
suse_manager_enabled: suse_manager_enabled
)
end
end
8 changes: 5 additions & 3 deletions lib/trento_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ defmodule TrentoWeb.Router do

get "/hosts/:id/exporters_status", PrometheusController, :exporters_status

resources "/settings/suma_credentials", SUMACredentialsController,
only: [:show, :create, :update, :delete],
singleton: true
if Application.compile_env!(:trento, :suse_manager_enabled) do
resources "/settings/suma_credentials", SUMACredentialsController,
only: [:show, :create, :update, :delete],
singleton: true
end

scope "/charts" do
pipe_through :charts_feature
Expand Down
1 change: 1 addition & 0 deletions lib/trento_web/templates/page/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const config = {
checksServiceBaseUrl: '<%= @check_service_base_url %>',
deregistrationDebounce: <%= @deregistration_debounce %>,
chartsEnabled: <%= @charts_enabled %>,
suseManagerEnabled: <%= @suse_manager_enabled %>,
};
</script>

Expand Down
Loading