Skip to content
Closed
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
1 change: 1 addition & 0 deletions app/graphql/mutations/ansible_variable_overrides/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Update < ::Mutations::UpdateMutation
argument :omit, Boolean, required: false
argument :host_id, Int, required: true
argument :ansible_variable_id, Int, required: true
argument :hidden_value, Boolean, required: true

field :overriden_ansible_variable, ::Types::OverridenAnsibleVariable, :null => true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class OverridenAnsibleVariablePresenter
attr_reader :ansible_variable

delegate :id, :key, :description, :override?,
:parameter_type, :hidden_value?, :omit, :required,
:parameter_type, :hidden_value, :omit, :required,
:validator_type, :validator_rule, :default_value,
:ansible_role, :current_value, :to => :ansible_variable

Expand Down
4 changes: 4 additions & 0 deletions app/models/ansible_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def ansible?
true
end

def hidden_value
hidden_value?
end

def self.humanize_class_name(options = nil)
if options.present?
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Th,
Td,
} from '@patternfly/react-table';
import { Flex, FlexItem } from '@patternfly/react-core';
import { Flex, FlexItem, Checkbox } from '@patternfly/react-core';

import Pagination from 'foremanReact/components/Pagination';
import deleteAnsibleVariableOverride from '../../../../graphql/mutations/deleteAnsibleVariableOverride.gql';
Expand All @@ -26,6 +26,7 @@ import {
validateValue,
onCompleted,
onError,
formatValue,
} from './AnsibleVariableOverridesTableHelper';

import withLoading from '../../../withLoading';
Expand All @@ -44,6 +45,7 @@ const initState = vars =>
value: variable.currentValue
? variable.currentValue.value
: variable.defaultValue,
hiddenValue: variable.hiddenValue,
validation: { key: 'noval', msg: '' },
working: false,
}));
Expand Down Expand Up @@ -77,6 +79,10 @@ const AnsibleVariableOverridesTable = ({
innerDispatch({ idx, payload: { open: flag } });
};

const setHiddenValue = idx => isHide => {
innerDispatch({ idx, payload: { hiddenValue: isHide } });
};

const onValueChange = (idx, variable) => value => {
const payload = {
value,
Expand Down Expand Up @@ -174,14 +180,31 @@ const AnsibleVariableOverridesTable = ({
<Td>{variable.ansibleRoleName}</Td>
<Td>{variable.parameterType}</Td>
<Td>
<EditableValue
variable={variable}
editing={editableState[idx].open}
onChange={onValueChange(idx, variable)}
value={editableState[idx].value}
validation={editableState[idx].validation}
working={editableState[idx].working}
/>
{!editableState[idx].open ? (
formatValue(variable)
) : (
<>
<EditableValue
variable={variable}
editing={editableState[idx].open}
setHiddenValue={setHiddenValue(
idx,
variable.hiddenValue
)}
onChange={onValueChange(idx, variable)}
value={editableState[idx].value}
validation={editableState[idx].validation}
working={editableState[idx].working}
/>
<Checkbox
ouiaId={`edit-parameters-table-row-hide-`}
label={__('Hide value')}
isChecked={editableState[idx].hiddenValue}
onChange={setHiddenValue(idx)}
id="hide value checkbox"
/>
</>
)}
</Td>
<Td>{formatSourceAttr(variable)}</Td>
<Td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function formatSourceLink(currentValue) {
return `${__(element)}: ${currentValue.elementName}`;
}

//here we can add the condition for hidden value to "*****"
export const formatSourceAttr = variable =>
variable.currentValue
? formatSourceLink(variable.currentValue)
Expand All @@ -21,7 +22,9 @@ export const formatValue = variable => {
const value = variable.currentValue
? variable.currentValue.value
: variable.defaultValue;

if (variable.hiddenValue) {
return '••••••••';
}
switch (variable.parameterType) {
case 'boolean':
return value ? <CheckIcon /> : <TimesIcon />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const EditableAction = ({
variables: {
id: lookupValue.id,
value: state.value,
hiddenValue: state.hiddenValue,
hostId,
ansibleVariableId: decodeModelId(variable),
match,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';

import { formatValue } from './AnsibleVariableOverridesTableHelper';

import {
TextAreaField,
TextInputField,
SelectField,
} from './EditableValueHelper';

const EditableValue = props => {
if (!props.editing) {
return formatValue(props.variable);
}

const type = props.variable.parameterType;

if (['json', 'yaml', 'array', 'hash'].includes(type)) {
Expand Down Expand Up @@ -61,7 +54,6 @@ const EditableValue = props => {
};

EditableValue.propTypes = {
editing: PropTypes.bool.isRequired,
variable: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
value: PropTypes.any,
Expand Down
6 changes: 4 additions & 2 deletions webpack/graphql/mutations/updateAnsibleVariableOverride.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ mutation UpdateAnsibleVariableOverride(
$hostId: Int!,
$ansibleVariableId: Int!,
$value: RawJson!
$match: String!) {
updateAnsibleVariableOverride(input: { id: $id, hostId: $hostId, value: $value, ansibleVariableId: $ansibleVariableId }) {
$match: String!
$hiddenValue: Boolean!) {
updateAnsibleVariableOverride(input: { id: $id, hostId: $hostId, value: $value, ansibleVariableId: $ansibleVariableId, hiddenValue: $hiddenValue }) {
overridenAnsibleVariable {
id
lookupValues(match: $match) {
Expand All @@ -15,6 +16,7 @@ mutation UpdateAnsibleVariableOverride(
omit
}
}
hiddenValue
currentValue {
element
value
Expand Down
1 change: 1 addition & 0 deletions webpack/graphql/queries/hostVariableOverrides.gql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ query($id: String!, $match: String, $first: Int, $last: Int) {
canEdit
}
defaultValue
hiddenValue
parameterType
ansibleRoleName
validatorType
Expand Down