forked from data-dot-all/dataall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow DA admins to view share logs (data-dot-all#1274)
### Feature or Bugfix <!-- please choose --> - Feature ### Detail - The latest logstream (last 24 hours) is loaded into modal window on Share Object page - User can see "Logs" button, if they are admins, stewards or owner of the dataset ### Relates - data-dot-all#1215 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users? - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Sofia Sazonova <[email protected]>
- Loading branch information
1 parent
a0fc4b0
commit 6c59e9d
Showing
9 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import Editor from '@monaco-editor/react'; | ||
import { RefreshRounded } from '@mui/icons-material'; | ||
import { | ||
Box, | ||
Button, | ||
CircularProgress, | ||
Dialog, | ||
Grid, | ||
Typography | ||
} from '@mui/material'; | ||
import PropTypes from 'prop-types'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import { THEMES, useSettings } from 'design'; | ||
import { SET_ERROR, useDispatch } from 'globalErrors'; | ||
import { getShareLogs, useClient } from 'services'; | ||
|
||
export const ShareLogs = (props) => { | ||
const { shareUri, onClose, open } = props; | ||
const { settings } = useSettings(); | ||
const client = useClient(); | ||
const dispatch = useDispatch(); | ||
const [logs, setLogs] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const getLogs = useCallback(async () => { | ||
setLoading(true); | ||
try { | ||
const response = await client.query(getShareLogs(shareUri)); | ||
if (response && !response.errors) { | ||
setLogs(response.data.getShareLogs.map((l) => l.message)); | ||
} else { | ||
dispatch({ type: SET_ERROR, error: response.errors[0].message }); | ||
} | ||
} catch (e) { | ||
dispatch({ type: SET_ERROR, error: e.message }); | ||
} | ||
setLoading(false); | ||
}, [client, dispatch, shareUri]); | ||
|
||
useEffect(() => { | ||
if (client && open) { | ||
getLogs().catch((e) => dispatch({ type: SET_ERROR, error: e.message })); | ||
} | ||
}, [client, dispatch, getLogs, open]); | ||
|
||
return ( | ||
<Dialog maxWidth="md" fullWidth onClose={onClose} open={open}> | ||
<Box sx={{ p: 3 }}> | ||
<Grid container justifyContent="space-between" spacing={3}> | ||
<Grid item> | ||
<Typography color="textPrimary" gutterBottom variant="h6"> | ||
Logs for share {shareUri} | ||
</Typography> | ||
</Grid> | ||
<Grid item /> | ||
<Box sx={{ m: -1, mt: 2 }}> | ||
<Button | ||
color="primary" | ||
startIcon={<RefreshRounded fontSize="small" />} | ||
variant="outlined" | ||
onClick={getLogs} | ||
> | ||
Refresh | ||
</Button> | ||
</Box> | ||
</Grid> | ||
<Box sx={{ height: '35rem' }}> | ||
{loading ? ( | ||
<CircularProgress /> | ||
) : ( | ||
<Box> | ||
{logs && ( | ||
<Box sx={{ mt: 1 }}> | ||
<div | ||
style={{ | ||
width: '100%', | ||
border: | ||
settings.theme === THEMES.LIGHT ? '1px solid #eee' : '' | ||
}} | ||
> | ||
<Editor | ||
value={ | ||
logs.length > 0 | ||
? logs.join('\n') | ||
: 'No logs available for the last 24 hours. Logs may take few minutes after the share is processed...' | ||
} | ||
options={{ minimap: { enabled: false } }} | ||
theme="vs-dark" | ||
inDiffEditor={false} | ||
height="35rem" | ||
language="text" | ||
showPrintMargin | ||
showGutter | ||
highlightActiveLine | ||
editorProps={{ | ||
$blockScrolling: Infinity | ||
}} | ||
setOptions={{ | ||
enableBasicAutocompletion: true, | ||
enableLiveAutocompletion: true, | ||
enableSnippets: true, | ||
showLineNumbers: true, | ||
tabSize: 2 | ||
}} | ||
/> | ||
</div> | ||
</Box> | ||
)} | ||
</Box> | ||
)} | ||
</Box> | ||
</Box> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
ShareLogs.propTypes = { | ||
shareUri: PropTypes.string.isRequired | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { gql } from 'apollo-boost'; | ||
|
||
export const getShareLogs = (shareUri) => ({ | ||
variables: { | ||
shareUri | ||
}, | ||
query: gql` | ||
query getShareLogs($shareUri: String!) { | ||
getShareLogs(shareUri: $shareUri) { | ||
message | ||
timestamp | ||
} | ||
} | ||
` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './createShareObject'; | ||
export * from './getShareRequestsToMe'; | ||
export * from './getShareLogs'; |