Skip to content

[WIP] Convert settings authentication form #8961

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

Open
wants to merge 10 commits into
base: master
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
69 changes: 50 additions & 19 deletions app/controllers/ops_controller/settings/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ def settings_update
end
end

def settings_update_amazon_verify
assert_privileges("ops_settings")
require 'byebug'
byebug

server_config = MiqServer.find(@sb[:selected_server_id]).settings
amazon_params = {}
amazon_params[:authentication] = server_config[:authentication]
amazon_params[:authentication][:amazon_key] = params[:authentication][:amazon_key]

if params[:authentication][:amazon_secret]
# server_config = MiqServer.find(@sb[:selected_server_id]).settings
# amazon_params[:authentication][:amazon_secret] = server_config[:authentication][:amazon_secret]
amazon_params[:authentication][:amazon_secret] = params[:authentication][:amazon_secret]
# else
# amazon_params[:authentication][:amazon_secret] = params[:authentication][:amazon_secret]
end
valid, errors = Authenticator::Amazon.validate_connection(amazon_params)
if valid
add_flash(_("Amazon Settings validation was successful"))
else
errors.each do |error|
add_flash("#{error[0]}: #{error[1]}", :error)
end
end
javascript_flash
end

def smartproxy_affinity_field_changed
assert_privileges("zone_admin")

Expand Down Expand Up @@ -324,25 +352,28 @@ def settings_update_ldap_verify
javascript_flash
end

def settings_update_amazon_verify
settings_get_form_vars
return unless @edit

server_config = MiqServer.find(@sb[:selected_server_id]).settings
server_config.each_key do |category|
server_config[category] = @edit[:new][category].dup
end

valid, errors = Authenticator::Amazon.validate_connection(server_config)
if valid
add_flash(_("Amazon Settings validation was successful"))
else
errors.each do |error|
add_flash("#{error.attribute.to_s.titleize}: #{error.message}", :error)
end
end
javascript_flash
end
# def settings_update_amazon_verify
# require 'byebug'
# byebug

# settings_get_form_vars
# return unless @edit

# server_config = MiqServer.find(@sb[:selected_server_id]).settings
# server_config.each_key do |category|
# server_config[category] = @edit[:new][category].dup
# end

# valid, errors = Authenticator::Amazon.validate_connection(server_config)
# if valid
# add_flash(_("Amazon Settings validation was successful"))
# else
# errors.each do |error|
# add_flash("#{error[0]}: #{error[1]}", :error)
# end
# end
# javascript_flash
# end

def settings_update_email_verify
settings_get_form_vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const PasswordField = ({
}) => {
const formOptions = useFormApi();
const [editMode, setEditMode] = useState(!edit);

console.log(edit);
const secretField = {
type: 'password',
autoComplete: 'new-password',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { componentTypes, validatorTypes } from '@@ddf';
import { getTimeOptions, secretKeyPlaceholder } from './helper';

const createSchema = (amazonEdit, editMode, setState, key, setKey) => {
console.log(key);
const fields = [
{
component: componentTypes.SUB_FORM,
id: 'session_timeout',
name: 'session_timeout',
title: __('Session Timeout'),
fields: [
{
component: componentTypes.SELECT,
id: 'session_timeout_hours',
name: 'session_timeout_hours',
label: __('Hours'),
options: getTimeOptions(24, 1),
},
{
component: componentTypes.SELECT,
id: 'session_timeout_mins',
name: 'session_timeout_mins',
label: __('Minutes'),
options: getTimeOptions(12, 5),
},
],
},
{
component: componentTypes.SELECT,
id: 'mode',
name: 'mode',
label: __('Mode'),
options: [
{ value: 'database', label: __('Database') },
{ value: 'amazon', label: __('Amazon') },
{ value: 'httpd', label: __('External (httpd)') },
],
},
{
component: componentTypes.SUB_FORM,
id: 'amazon_subform',
name: 'amazon_subform',
title: __('Amazon Primary AWS Account Settings for IAM'),
condition: {
when: 'mode',
is: 'amazon',
},
fields: [
{
component: componentTypes.TEXT_FIELD,
id: 'amazon_key',
name: 'amazon_key',
validate: [{ type: validatorTypes.REQUIRED }],
isRequired: true,
label: __('Access Key'),
maxLength: 50,
},
{
component: 'password-field',
id: 'amazon_secret',
name: 'amazon_secret',
label: __('Secret Key'),
maxLength: 50,
edit: amazonEdit,
// onChange: (test) => { console.log(test); },
validate: [{ type: validatorTypes.REQUIRED }],
isRequired: true,
},
],
},
{
component: componentTypes.SUB_FORM,
id: 'amazon_role_subform',
name: 'amazon_role_subform',
title: __('Role Settings'),
condition: {
when: 'mode',
is: 'amazon',
},
fields: [
{
component: componentTypes.CHECKBOX,
id: 'amazon_role',
name: 'amazon_role',
label: __('Get User Groups from Amazon'),
},
],
},
{
component: componentTypes.SUB_FORM,
id: 'httpd_subform',
name: 'httpd_subform',
title: __('External Authentication (httpd) Settings'),
condition: {
when: 'mode',
is: 'httpd',
},
fields: [
{
component: componentTypes.CHECKBOX,
id: 'sso_enabled',
name: 'sso_enabled',
label: __('Enable Single Sign-On'),
},
{
component: componentTypes.RADIO,
id: 'provider_type',
name: 'provider_type',
label: __('Provider Type'),
options: [
{ value: 'none', label: 'None' },
{ value: 'saml', label: 'Enable SAML' },
{ value: 'oidc', label: ' Enable OpenID-Connect' },
],
},
{
component: componentTypes.CHECKBOX,
id: 'local_login_disabled',
name: 'local_login_disabled',
label: __('Disable Local Login'),
condition: {
or: [
{
when: 'provider_type',
is: 'saml',
},
{
when: 'provider_type',
is: 'oidc',
},
],
},
},
],
},
{
component: componentTypes.SUB_FORM,
id: 'httpd_role_subform',
name: 'httpd_role_subform',
title: __('External Authentication (httpd) Settings'),
condition: {
when: 'mode',
is: 'httpd',
},
fields: [
{
component: componentTypes.CHECKBOX,
id: 'httpd_role',
name: 'httpd_role',
label: __('Get User Groups from External Authentication (httpd)'),
},
],
},
];

return { fields };
};

export default createSchema;
17 changes: 17 additions & 0 deletions app/javascript/components/authentication-form/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const getTimeOptions = (numOptions, multiplier) => {
const options = [];
const temp = [...Array(numOptions).keys()];
temp.forEach((timeOption) => {
options.push({ value: (timeOption * multiplier).toString(), label: (timeOption * multiplier).toString() });
});
return options;
};

export const secretKeyPlaceholder = () => {
let placeholder = '';
const length = [...Array(8).keys()];
length.forEach(() => {
placeholder += '\u25cf';
});
return placeholder;
};
Loading