Skip to content

Commit

Permalink
Fixes #36595 - Don't show the value for hidden ansible variables
Browse files Browse the repository at this point in the history
  • Loading branch information
girijaasoni committed Jan 25, 2024
1 parent 415543f commit 08f3d12
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/graphql/mutations/ansible_variable_overrides/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ 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

def resolve(host_id:, ansible_variable_id:, **kwargs)
result = super kwargs
host = Host.find host_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ 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

def initialize(ansible_variable, override_resolver)
def initialize(ansible_variable, override_resolver)
@ansible_variable = ansible_variable
@override_resolver = override_resolver
end
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
self.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-`}

Check failure on line 200 in webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js

View workflow job for this annotation

GitHub Actions / test_js (12)

Curly braces are unnecessary here

Check failure on line 200 in webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js

View workflow job for this annotation

GitHub Actions / test_js (14)

Curly braces are unnecessary here
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 "*****"

Check failure on line 15 in webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js

View workflow job for this annotation

GitHub Actions / test_js (12)

Expected exception block, space or tab after '//' in comment

Check failure on line 15 in webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js

View workflow job for this annotation

GitHub Actions / test_js (14)

Expected exception block, space or tab after '//' in comment
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

0 comments on commit 08f3d12

Please sign in to comment.