Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from postgres-ai:master #137

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

Merged
pull merged 4 commits into nagyist:master from postgres-ai:master
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/cspell.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
"sparql",
"SPARQL",
"subtransactions",
"mbox"
"mbox",
"SIEM"
]
}
114 changes: 113 additions & 1 deletion ui/packages/platform/src/actions/actions.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const Actions = Reflux.createActions([{
updateOrg: ASYNC_ACTION,
createOrg: ASYNC_ACTION,
updateAiBotSettings: ASYNC_ACTION,
updateAuditSettings: ASYNC_ACTION,
inviteUser: ASYNC_ACTION,
useDemoData: ASYNC_ACTION,
setReportsProject: {},
Expand Down Expand Up @@ -114,7 +115,9 @@ const Actions = Reflux.createActions([{
downloadDblabSessionArtifact: ASYNC_ACTION,
sendUserCode: ASYNC_ACTION,
confirmUserEmail: ASYNC_ACTION,
confirmTosAgreement: ASYNC_ACTION
confirmTosAgreement: ASYNC_ACTION,
testSiemServiceConnection: ASYNC_ACTION,
getAuditEvents: ASYNC_ACTION
}]);

function timeoutPromise(ms, promise) {
Expand Down Expand Up @@ -654,6 +657,42 @@ Actions.updateAiBotSettings.listen(function (token, orgId, orgData) {
});
});

Actions.updateAuditSettings.listen(function (token, orgId, orgData) {
let action = this;

if (!api) {
settings.init(function () {
api = new Api(settings);
});
}

action.progressed({ orgId } + orgData);
timeoutPromise(REQUEST_TIMEOUT, api.updateAuditSettings(token, orgId, orgData))

.then(result => {
result.json()
.then(json => {
if (json) {
action.completed(json);
} else {
action.failed(new Error('wrong_reply'));
}
})
.catch(err => {
console.error(err);
action.failed(new Error('wrong_reply'));
});
})
.catch(err => {
console.error(err);
if (err && err.message && err.message === 'timeout') {
action.failed(new Error('failed_fetch'));
} else {
action.failed(new Error('wrong_reply'));
}
});
});

Actions.createOrg.listen(function (token, orgData) {
let action = this;

Expand Down Expand Up @@ -1571,4 +1610,77 @@ Actions.confirmTosAgreement.listen(function (token) {
);
});


Actions.testSiemServiceConnection.listen(function (token, data) {
let action = this;

if (!api) {
settings.init(function () {
api = new Api(settings);
});
}

action.progressed(data);
timeoutPromise(REQUEST_TIMEOUT, api.testSiemServiceConnection(token, data))

.then(result => {
result.json()
.then(json => {
if (json) {
action.completed(json);
} else {
action.failed(new Error('wrong_reply'));
}
})
.catch(err => {
console.error(err);
action.failed(new Error('wrong_reply'));
});
})
.catch(err => {
console.error(err);
if (err && err.message && err.message === 'timeout') {
action.failed(new Error('failed_fetch'));
} else {
action.failed(new Error('wrong_reply'));
}
});
});

Actions.getAuditEvents.listen(function (token) {
let action = this;

if (!api) {
settings.init(function () {
api = new Api(settings);
});
}

action.progressed();

timeoutPromise(REQUEST_TIMEOUT, api.getAuditEvents(token))
.then(result => {
result.json()
.then(json => {
if (json) {
action.completed({ data: json });
} else {
action.failed(new Error('wrong_reply'));
}
})
.catch(err => {
console.error(err);
action.failed(new Error('wrong_reply'));
});
})
.catch(err => {
console.error(err);
if (err && err.message && err.message === 'timeout') {
action.failed(new Error('failed_fetch'));
} else {
action.failed(new Error('wrong_reply'));
}
});
});

export default Actions;
76 changes: 76 additions & 0 deletions ui/packages/platform/src/api/api.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,71 @@ class Api {
});
}

updateAuditSettings(token, orgId, orgData) {
let params = {};
let headers = {
Authorization: 'Bearer ' + token,
prefer: 'return=representation'
};

if (typeof orgData.enableSiemIntegration !== 'undefined') {
params.siem_integration_enabled = orgData.enableSiemIntegration;
}

if (typeof orgData.urlSchema !== 'undefined') {
params.siem_integration_url = orgData.urlSchema;
}

if (typeof orgData.auditEvents !== "undefined") {
params.audit_events_to_log = orgData.auditEvents.map((item) => item.event_name)
}

if (typeof orgData.headers !== 'undefined' && Array.isArray(orgData.headers)) {
orgData.headers = orgData.headers.filter(item => item.key && item.value);
if (Object.keys(orgData.headers).length > 0) {
params.siem_integration_request_headers = orgData.headers.reduce((acc, item) => {
acc[item.key] = item.value;
return acc;
}, {});
} else {
params.siem_integration_request_headers = null
}
}

return this.patch(`${this.apiServer}/orgs?id=eq.` + orgId, params, {
headers: headers
});
}

testSiemServiceConnection(token, data) {
let params = {};
let headers = {
Accept: 'application/vnd.pgrst.object+json',
Authorization: 'Bearer ' + token,
prefer: 'return=representation'
};

if (typeof data.urlSchema !== 'undefined') {
params.api_url = data.urlSchema;
}

if (typeof data.headers !== 'undefined' && Array.isArray(data.headers)) {
data.headers = data.headers.filter(item => item.key && item.value);
if (Object.keys(data.headers).length > 0) {
params.http_headers_extra = data.headers.reduce((acc, item) => {
acc[item.key] = item.value;
return acc;
}, {});
} else {
params.http_headers_extra = null
}
}

return this.post(`${this.apiServer}/rpc/test_siem_connection`, params, {
headers: headers
});
}

inviteUser(token, orgId, email) {
let headers = {
Authorization: 'Bearer ' + token
Expand Down Expand Up @@ -992,6 +1057,17 @@ class Api {
{ headers }
);
}

getAuditEvents(token) {
let params = {};
let headers = {
Authorization: 'Bearer ' + token
};

return this.get(`${this.apiServer}/audit_events`, params, {
headers: headers
});
}
}

export default Api;
41 changes: 16 additions & 25 deletions ui/packages/platform/src/components/Audit/Audit.tsx
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ interface AuditWithStylesProps extends AuditProps {

export interface AuditLogData {
id: number
data_before: string
data_after: string
action: string
actor: string
action_data: {
processed_rows_count: number
processed_row_count: number
data_before: Record<string, string>[]
data_after: Record<string, string>[]
}
created_at: string
table_name: string
Expand Down Expand Up @@ -155,11 +155,11 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
actorSrc = ' (changed directly in database) '
}

if (r.action_data && r.action_data.processed_rows_count) {
if (r.action_data && r.action_data.processed_row_count) {
rows =
r.action_data.processed_rows_count +
r.action_data.processed_row_count +
' ' +
(r.action_data.processed_rows_count > 1 ? 'rows' : 'row')
(r.action_data.processed_row_count > 1 ? 'rows' : 'row')
}

switch (r.action) {
Expand Down Expand Up @@ -193,12 +193,12 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
}

getChangesTitle = (r: AuditLogData) => {
const displayedCount = r.data_before
? r.data_before?.length
: r.data_after?.length
const displayedCount = r.action_data && r.action_data.data_before
? r.action_data.data_before?.length
: r.action_data?.data_after?.length
const objCount =
r.action_data && r.action_data.processed_rows_count
? r.action_data.processed_rows_count
r.action_data && r.action_data.processed_row_count
? r.action_data.processed_row_count
: null

if (displayedCount && (objCount as number) > displayedCount) {
Expand Down Expand Up @@ -243,15 +243,6 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
const pageTitle = (
<ConsolePageTitle
title={auditTitle}
filterProps={
logs && logs.length > 0
? {
filterValue: this.state.filterValue,
filterHandler: this.filterInputHandler,
placeholder: 'Search audit log',
}
: null
}
/>
)

Expand Down Expand Up @@ -310,7 +301,7 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
<TableRow hover className={classes?.row} key={r.id}>
<TableCell className={classes?.cell}>
{this.formatAction(r)}
{(r.data_before || r.data_after) && (
{((r.action_data && r.action_data.data_before) || (r.action_data && r.action_data.data_after)) && (
<div>
<ExpansionPanel
className={classes?.expansionPanel}
Expand All @@ -326,7 +317,7 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
<ExpansionPanelDetails
className={classes?.expansionPanelDetails}
>
{r.data_before && (
{r.action_data && r.action_data.data_before && (
<div className={classes?.data}>
{this.getDataSectionTitle(r, true)}
<TextField
Expand All @@ -335,7 +326,7 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
multiline
fullWidth
value={JSON.stringify(
r.data_before,
r.action_data.data_before,
null,
4,
)}
Expand All @@ -347,7 +338,7 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
/>
</div>
)}
{r.data_after && (
{r.action_data && r.action_data.data_after && (
<div className={classes?.data}>
{this.getDataSectionTitle(r, false)}
<TextField
Expand All @@ -356,7 +347,7 @@ class Audit extends Component<AuditWithStylesProps, AuditState> {
multiline
fullWidth
value={JSON.stringify(
r.data_after,
r.action_data.data_after,
null,
4,
)}
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /