Skip to content

Commit

Permalink
Prevent duplicity post of creating/replacing elyra secret (#3120)
Browse files Browse the repository at this point in the history
* Prevent duplicity post of creating/replacing elyra secret

* remove comments
  • Loading branch information
DaoDaoNoCode authored Sep 4, 2024
1 parent db1d9e3 commit 7c1a2d9
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions frontend/src/concepts/pipelines/context/useManageElyraSecret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const useManageElyraSecret = (
namespace,
);
const notification = useNotification();
const isCreatingSecretRef = React.useRef(false);

React.useEffect(() => {
const error = elyraSecretError || dataConnectionError;
Expand All @@ -32,24 +33,30 @@ const useManageElyraSecret = (
}, [dataConnectionError, elyraSecretError]);

const fullLoadedState = elyraSecretLoaded && dataConnectionLoaded;
React.useEffect(() => {

const generatedSecret = React.useMemo(() => {
const externalStorage = cr?.spec.objectStorage.externalStorage;
if (fullLoadedState && dataConnection && routePath && externalStorage) {
let generatedSecret;
try {
generatedSecret = generateElyraSecret(externalStorage, dataConnection, routePath);
} catch (e) {
if (e instanceof Error) {
notification.error(e.message);
}
try {
if (externalStorage && dataConnection && routePath) {
return generateElyraSecret(externalStorage, dataConnection, routePath);
}

if (!generatedSecret) {
return;
return null;
} catch (e) {
if (e instanceof Error) {
notification.error(e.message);
}
return null;
}
}, [cr?.spec.objectStorage.externalStorage, dataConnection, notification, routePath]);

React.useEffect(() => {
if (fullLoadedState && generatedSecret) {
if (!elyraSecret) {
// Create a new secret
createSecret(generatedSecret);
if (!isCreatingSecretRef.current) {
isCreatingSecretRef.current = true;
// Create a new secret
createSecret(generatedSecret).then(() => (isCreatingSecretRef.current = false));
}
return;
}
try {
Expand All @@ -61,13 +68,16 @@ const useManageElyraSecret = (
const usingOldUrl = !secretValue.metadata[ELYRA_SECRET_DATA_ENDPOINT].endsWith('/view/');
if (usingOldDataType || usingOldUrl) {
// Secret is out of date, update it
replaceSecret(generateElyraSecret(externalStorage, dataConnection, routePath));
if (!isCreatingSecretRef.current) {
isCreatingSecretRef.current = true;
replaceSecret(generatedSecret).then(() => (isCreatingSecretRef.current = false));
}
}
} catch (e) {
// do nothing
}
}
}, [fullLoadedState, routePath, elyraSecret, dataConnection, cr, notification]);
}, [elyraSecret, fullLoadedState, generatedSecret]);
};

export default useManageElyraSecret;

0 comments on commit 7c1a2d9

Please sign in to comment.