-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
feat: Use Environment variables for secrets capabilities #1702 #1877
base: main
Are you sure you want to change the base?
Changes from 4 commits
d7d9dde
5f3e163
9b2688f
fc17cb3
9e8f5a4
26a67d7
f8d5a9c
3497162
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import _ from 'lodash'; | ||
|
||
import {SAVED_FRAMEWORK, SET_SAVED_GESTURES} from '../../shared/setting-defs'; | ||
import { | ||
ENVIRONMENT_VARIABLES, | ||
SAVED_FRAMEWORK, | ||
SET_SAVED_GESTURES, | ||
} from '../../shared/setting-defs'; | ||
import {POINTER_TYPES} from '../constants/gestures'; | ||
import {APP_MODE, NATIVE_APP} from '../constants/session-inspector'; | ||
import i18n from '../i18next'; | ||
|
@@ -116,6 +120,9 @@ export const TOGGLE_SHOW_ATTRIBUTES = 'TOGGLE_SHOW_ATTRIBUTES'; | |
export const TOGGLE_REFRESHING_STATE = 'TOGGLE_REFRESHING_STATE'; | ||
|
||
export const SET_GESTURE_UPLOAD_ERROR = 'SET_GESTURE_UPLOAD_ERROR'; | ||
export const SET_ENVIRONMENT_VARIABLES = 'SET_ENVIRONMENT_VARIABLES'; | ||
export const ADD_ENVIRONMENT_VARIABLE = 'ADD_ENVIRONMENT_VARIABLE'; | ||
export const DELETE_ENVIRONMENT_VARIABLE = 'DELETE_ENVIRONMENT_VARIABLE'; | ||
|
||
const KEEP_ALIVE_PING_INTERVAL = 20 * 1000; | ||
const NO_NEW_COMMAND_LIMIT = 24 * 60 * 60 * 1000; // Set timeout to 24 hours | ||
|
@@ -357,6 +364,9 @@ export function quitSession(reason, killedByUser = true) { | |
const applyAction = applyClientMethod({methodName: 'quit'}); | ||
await applyAction(dispatch, getState); | ||
dispatch({type: QUIT_SESSION_DONE}); | ||
// Reload environment variables from persistent settings after session ends | ||
const loadEnvAction = loadEnvironmentVariables(); | ||
await loadEnvAction(dispatch); | ||
Comment on lines
+365
to
+367
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this code is necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above, I don't think this code is necessary because we only care about loading the env var values in the context of an active session. Quitting a session won't delete them from the persistent settings in any case. |
||
if (!killedByUser) { | ||
showError(new Error(reason || i18n.t('Session has been terminated')), {secs: 0}); | ||
} | ||
|
@@ -919,6 +929,38 @@ export function setGestureUploadErrors(errors) { | |
}; | ||
} | ||
|
||
export function setEnvironmentVariables(envVars) { | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return async (dispatch) => { | ||
await setSetting(ENVIRONMENT_VARIABLES, envVars); | ||
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars}); | ||
}; | ||
} | ||
|
||
export function addEnvironmentVariable(key, value) { | ||
return async (dispatch, getState) => { | ||
const currentEnvVars = getState().inspector.environmentVariables || []; | ||
const newEnvVars = [...currentEnvVars, {key, value}]; | ||
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars); | ||
dispatch({type: ADD_ENVIRONMENT_VARIABLE, key, value}); | ||
}; | ||
} | ||
|
||
export function deleteEnvironmentVariable(key) { | ||
return async (dispatch, getState) => { | ||
const currentEnvVars = getState().inspector.environmentVariables || []; | ||
const newEnvVars = currentEnvVars.filter((v) => v.key !== key); | ||
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars); | ||
dispatch({type: DELETE_ENVIRONMENT_VARIABLE, key}); | ||
}; | ||
} | ||
|
||
export function loadEnvironmentVariables() { | ||
return async (dispatch) => { | ||
const envVars = (await getSetting(ENVIRONMENT_VARIABLES)) || []; | ||
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars}); | ||
}; | ||
} | ||
|
||
export function uploadGesturesFromFile(fileList) { | ||
return async (dispatch) => { | ||
const gestures = await readTextFromUploadedFiles(fileList); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import {DeleteOutlined, PlusOutlined} from '@ant-design/icons'; | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import {Button, Input, Popconfirm, Space, Table, Tooltip} from 'antd'; | ||
import {useState} from 'react'; | ||
import {connect} from 'react-redux'; | ||
|
||
import { | ||
addEnvironmentVariable, | ||
deleteEnvironmentVariable, | ||
setEnvironmentVariables, | ||
} from '../../actions/Inspector'; | ||
import styles from './Inspector.module.css'; | ||
|
||
const EnvironmentVariables = ({t, envVars, addVariable, deleteVariable}) => { | ||
const [newVar, setNewVar] = useState({key: '', value: ''}); | ||
|
||
const columns = [ | ||
{ | ||
title: t('Variable Name'), | ||
dataIndex: 'key', | ||
key: 'key', | ||
width: '40%', | ||
}, | ||
{ | ||
title: t('Value'), | ||
dataIndex: 'value', | ||
key: 'value', | ||
width: '40%', | ||
render: (text) => <Input.Password value={text} readOnly />, | ||
}, | ||
{ | ||
title: t('Actions'), | ||
key: 'action', | ||
width: '20%', | ||
render: (_, record) => ( | ||
<Tooltip zIndex={3} title={t('Delete Variable')}> | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Popconfirm | ||
zIndex={4} | ||
title={t('Are you sure you want to delete this variable?')} | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
placement="topRight" | ||
okText={t('OK')} | ||
cancelText={t('Cancel')} | ||
onConfirm={() => deleteVariable(record.key)} | ||
> | ||
<Button type="text" danger icon={<DeleteOutlined />} /> | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Popconfirm> | ||
</Tooltip> | ||
), | ||
}, | ||
]; | ||
|
||
const handleAddVariable = () => { | ||
if (!newVar.key || !newVar.value) { | ||
return; | ||
} | ||
|
||
// Check for duplicate keys | ||
if (envVars.some((v) => v.key === newVar.key)) { | ||
return; | ||
} | ||
|
||
addVariable(newVar.key, newVar.value); | ||
setNewVar({key: '', value: ''}); | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.addForm}> | ||
<Space.Compact style={{width: '100%'}}> | ||
<Input | ||
placeholder={t('Variable Name')} | ||
value={newVar.key} | ||
onChange={(e) => setNewVar({...newVar, key: e.target.value})} | ||
/> | ||
<Input.Password | ||
placeholder={t('Value')} | ||
value={newVar.value} | ||
onChange={(e) => setNewVar({...newVar, value: e.target.value})} | ||
/> | ||
<Button | ||
type="primary" | ||
icon={<PlusOutlined />} | ||
onClick={handleAddVariable} | ||
disabled={!newVar.key || !newVar.value} | ||
> | ||
{t('Add')} | ||
</Button> | ||
</Space.Compact> | ||
</div> | ||
<Table columns={columns} dataSource={envVars} pagination={false} rowKey="key" size="small" /> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state) => ({ | ||
envVars: state.inspector.environmentVariables || [], | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
addVariable: (key, value) => dispatch(addEnvironmentVariable(key, value)), | ||
deleteVariable: (key) => dispatch(deleteEnvironmentVariable(key)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(EnvironmentVariables); | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ import {downloadFile} from '../../utils/file-handling'; | |
import Commands from './Commands.jsx'; | ||
import GestureEditor from './GestureEditor.jsx'; | ||
import HeaderButtons from './HeaderButtons.jsx'; | ||
import InspectorStyles from './Inspector.module.css'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the changes in this file are renaming and can be omitted in this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still not resolved |
||
import styles from './Inspector.module.css'; | ||
import Recorder from './Recorder.jsx'; | ||
import SavedGestures from './SavedGestures.jsx'; | ||
import Screenshot from './Screenshot.jsx'; | ||
|
@@ -221,7 +221,7 @@ const Inspector = (props) => { | |
}, [showKeepAlivePrompt]); | ||
|
||
const screenShotControls = ( | ||
<div className={InspectorStyles['screenshot-controls']}> | ||
<div className={styles['screenshot-controls']}> | ||
<Space size="middle"> | ||
<Tooltip | ||
title={t(showCentroids ? 'Hide Element Handles' : 'Show Element Handles')} | ||
|
@@ -263,22 +263,22 @@ const Inspector = (props) => { | |
); | ||
|
||
const main = ( | ||
<div className={InspectorStyles['inspector-main']}> | ||
<div className={styles['inspector-main']}> | ||
<div | ||
id="screenshotContainer" | ||
className={InspectorStyles['screenshot-container']} | ||
className={styles['screenshot-container']} | ||
ref={screenshotContainerEl} | ||
> | ||
{screenShotControls} | ||
{showScreenshot && <Screenshot {...props} scaleRatio={scaleRatio} />} | ||
{screenshotError && t('couldNotObtainScreenshot', {screenshotError})} | ||
{!showScreenshot && ( | ||
<Spin size="large" spinning={true}> | ||
<div className={InspectorStyles.screenshotBox} /> | ||
<div className={styles.screenshotBox} /> | ||
</Spin> | ||
)} | ||
</div> | ||
<div id="sourceTreeContainer" className={InspectorStyles['interaction-tab-container']}> | ||
<div id="sourceTreeContainer" className={styles['interaction-tab-container']}> | ||
<Tabs | ||
activeKey={selectedInspectorTab} | ||
size="small" | ||
|
@@ -331,15 +331,15 @@ const Inspector = (props) => { | |
</div> | ||
<div | ||
id="selectedElementContainer" | ||
className={`${InspectorStyles['interaction-tab-container']} ${InspectorStyles['element-detail-container']} action-col`} | ||
className={`${styles['interaction-tab-container']} ${styles['element-detail-container']} action-col`} | ||
> | ||
<Card | ||
title={ | ||
<span> | ||
<TagOutlined /> {t('selectedElement')} | ||
</span> | ||
} | ||
className={InspectorStyles['selected-element-card']} | ||
className={styles['selected-element-card']} | ||
> | ||
{selectedElement.path && <SelectedElement {...props} />} | ||
{!selectedElement.path && <i>{t('selectElementInSource')}</i>} | ||
|
@@ -359,7 +359,7 @@ const Inspector = (props) => { | |
<ThunderboltOutlined /> {t('Execute Commands')} | ||
</span> | ||
} | ||
className={InspectorStyles['interaction-tab-card']} | ||
className={styles['interaction-tab-card']} | ||
> | ||
<Commands {...props} /> | ||
</Card> | ||
|
@@ -376,7 +376,7 @@ const Inspector = (props) => { | |
<HighlightOutlined /> {t('Gesture Builder')} | ||
</span> | ||
} | ||
className={InspectorStyles['interaction-tab-card']} | ||
className={styles['interaction-tab-card']} | ||
> | ||
<GestureEditor {...props} /> | ||
</Card> | ||
|
@@ -387,7 +387,7 @@ const Inspector = (props) => { | |
<HighlightOutlined /> {t('Saved Gestures')} | ||
</span> | ||
} | ||
className={InspectorStyles['interaction-tab-card']} | ||
className={styles['interaction-tab-card']} | ||
> | ||
<SavedGestures {...props} /> | ||
</Card> | ||
|
@@ -410,7 +410,7 @@ const Inspector = (props) => { | |
<InfoCircleOutlined /> {t('Session Information')} | ||
</span> | ||
} | ||
className={InspectorStyles['interaction-tab-card']} | ||
className={styles['interaction-tab-card']} | ||
> | ||
<SessionInfo {...props} /> | ||
</Card> | ||
|
@@ -423,7 +423,7 @@ const Inspector = (props) => { | |
); | ||
|
||
return ( | ||
<div className={InspectorStyles['inspector-container']}> | ||
<div className={styles['inspector-container']}> | ||
<HeaderButtons quitCurrentSession={quitCurrentSession} {...props} /> | ||
{main} | ||
<Modal | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This specific key is not used anymore