-
Notifications
You must be signed in to change notification settings - Fork 45
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(ui): Add secret management UI #627
base: main
Are you sure you want to change the base?
Changes from all commits
46d22e6
b1d0af3
2391b75
6a8671e
7df5aee
86b78e8
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright 2020 The Merlin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
.Secrets { | ||
.euiTableRowCell > .euiTableCellContent { | ||
display: block; | ||
} | ||
} | ||
|
||
input[type="text"].inlineTableInput { | ||
float: left; | ||
padding: 0; | ||
font-size: inherit !important; | ||
line-height: inherit !important; | ||
font-family: inherit !important; | ||
height: inherit !important; | ||
transition: inherit !important; | ||
background-color: inherit !important; | ||
box-shadow: none !important; | ||
min-width: 90px; | ||
|
||
&:focus { | ||
background-size: 0 100%; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2020 The Merlin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { EuiInMemoryTable, EuiText } from "@elastic/eui"; | ||
|
||
export const SecretsConfigTable = ({ variables = [] }) => { | ||
const columns = [ | ||
{ | ||
field: "mlp_secret_name", | ||
name: "MLP Secret Name", | ||
width: "40%", | ||
sortable: true | ||
}, | ||
{ | ||
field: "env_var_name", | ||
name: "Environment Variable Name", | ||
width: "60%", | ||
sortable: true | ||
} | ||
]; | ||
|
||
return variables.length ? ( | ||
<EuiInMemoryTable | ||
items={variables} | ||
columns={columns} | ||
itemId="name" | ||
/> | ||
) : ( | ||
<EuiText size="s" color="subdued"> | ||
Not available | ||
</EuiText> | ||
); | ||
}; | ||
|
||
SecretsConfigTable.propTypes = { | ||
variables: PropTypes.array.isRequired | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,6 @@ export const EnvironmentVariablesForm = ({ variables, onChange }) => { | |
className="EnvVariables" | ||
columns={columns} | ||
items={items} | ||
hasActions={true} | ||
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 change is to prevent some errors that appear due to this deprecated prop. |
||
/> | ||
</Fragment> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/** | ||
* Copyright 2020 The Merlin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React, { Fragment, useCallback, useEffect, useState } from "react"; | ||
|
||
import { | ||
EuiButtonIcon, | ||
EuiFieldText, | ||
EuiInMemoryTable, | ||
EuiTitle, | ||
EuiSuperSelect | ||
} from "@elastic/eui"; | ||
import PropTypes from "prop-types"; | ||
import { useParams } from "react-router-dom"; | ||
import { useMerlinApi } from "../../../../hooks/useMerlinApi"; | ||
|
||
require("../../../../assets/scss/Secrets.scss"); | ||
|
||
export const SecretsForm = ({ variables, onChange }) => { | ||
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 component is more or less a simplified copy of the |
||
const [items, setItems] = useState([ | ||
...variables.map((v, idx) => ({ idx, ...v })), | ||
{ idx: variables.length }, | ||
]); | ||
|
||
const setVars = useCallback((items) => onChange(items), [onChange]); | ||
|
||
useEffect(() => { | ||
const trimmedVars = [ | ||
...items | ||
.slice(0, items.length - 1) | ||
.map((item) => ({ mlp_secret_name: item.mlp_secret_name.trim(), env_var_name: item.env_var_name })), | ||
]; | ||
if (JSON.stringify(variables) !== JSON.stringify(trimmedVars)) { | ||
setVars(trimmedVars); | ||
} | ||
}, [variables, items, setVars]); | ||
|
||
const removeRow = (idx) => { | ||
items.splice(idx, 1); | ||
setItems([...items.map((v, idx) => ({ ...v, idx }))]); | ||
}; | ||
|
||
const onChangeMLPSecretName = (idx) => { | ||
return (e) => { | ||
items[idx] = { ...items[idx], mlp_secret_name: e }; | ||
|
||
setItems((_) => | ||
items[items.length - 1].mlp_secret_name && | ||
items[items.length - 1].mlp_secret_name.trim() | ||
? [...items, { idx: items.length }] | ||
: [...items], | ||
); | ||
}; | ||
}; | ||
|
||
const onChangeEnvironmentVariableName = (idx) => { | ||
return (e) => { | ||
items[idx] = { ...items[idx], env_var_name: e.target.value }; | ||
setItems((_) => [...items]); | ||
}; | ||
}; | ||
|
||
const { projectId } = useParams(); | ||
const [options, setOptions] = useState([]); | ||
|
||
const [{ data: secrets }] = useMerlinApi( | ||
`/projects/${projectId}/secrets`, | ||
{}, | ||
[], | ||
); | ||
|
||
useEffect(() => { | ||
if (secrets) { | ||
const options = []; | ||
secrets | ||
.sort((a, b) => (a.name > b.name ? -1 : 1)) | ||
.forEach((secret) => { | ||
options.push({ | ||
value: secret.name, | ||
inputDisplay: secret.name, | ||
textWrap: "truncate", | ||
}); | ||
}); | ||
setOptions(options); | ||
} | ||
}, [secrets]); | ||
|
||
const columns = [ | ||
{ | ||
name: "MLP Secret Name", | ||
field: "mlp_secret_name", | ||
width: "45%", | ||
textOnly: false, | ||
render: (name, item) => ( | ||
<EuiSuperSelect | ||
placeholder={"Select MLP secret"} | ||
compressed={true} | ||
options={options} | ||
valueOfSelected={name} | ||
onChange={onChangeMLPSecretName(item.idx)} | ||
hasDividers | ||
/> | ||
), | ||
}, | ||
{ | ||
name: "Environment Variable Name", | ||
field: "env_var_name", | ||
width: "45%", | ||
render: (value, item) => ( | ||
<EuiFieldText | ||
controlOnly | ||
className="inlineTableInput" | ||
placeholder="Environment Variable Name" | ||
value={value || ""} | ||
onChange={onChangeEnvironmentVariableName(item.idx)} | ||
/> | ||
), | ||
}, | ||
{ | ||
width: "10%", | ||
actions: [ | ||
{ | ||
render: (item) => { | ||
return item.idx < items.length - 1 ? ( | ||
<EuiButtonIcon | ||
size="s" | ||
color="danger" | ||
iconType="trash" | ||
onClick={() => removeRow(item.idx)} | ||
aria-label="Remove variable" | ||
/> | ||
) : ( | ||
<div /> | ||
); | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
return ( | ||
<Fragment> | ||
<EuiTitle size="xs"> | ||
<h4>Secrets</h4> | ||
</EuiTitle> | ||
|
||
<EuiInMemoryTable | ||
className="Secrets" | ||
columns={columns} | ||
items={items} | ||
/> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
SecretsForm.propTypes = { | ||
variables: PropTypes.array, | ||
onChange: PropTypes.func, | ||
}; |
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 change was made to prevent some error that's being thrown about the argument
selected
containing an integer instead of a string.