-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from vtex-apps/feature/B2BTEAM-1433-security-m…
…etrics feat: add audit metrics for authenticated access
- Loading branch information
Showing
11 changed files
with
230 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from 'axios' | ||
|
||
const ANALYTICS_URL = 'https://rc.vtex.com/api/analytics/schemaless-events' | ||
|
||
export const B2B_METRIC_NAME = 'b2b-suite-buyerorg-data' | ||
|
||
export interface Metric { | ||
readonly account: string | ||
readonly kind: string | ||
readonly description: string | ||
readonly name: typeof B2B_METRIC_NAME | ||
} | ||
|
||
export const sendMetric = async (metric: Metric) => { | ||
await axios.post(ANALYTICS_URL, metric) | ||
} |
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,43 @@ | ||
import type { Logger } from '@vtex/api/lib/service/logger/logger' | ||
|
||
import type { Metric } from '../clients/metrics' | ||
import { B2B_METRIC_NAME, sendMetric } from '../clients/metrics' | ||
|
||
export interface AuthAuditMetric { | ||
operation: string | ||
forwardedHost: string | ||
caller: string | ||
role?: string | ||
permissions?: string[] | ||
hasAdminToken: boolean | ||
hasStoreToken: boolean | ||
hasApiToken: boolean | ||
} | ||
|
||
export class AuthMetric implements Metric { | ||
public readonly description: string | ||
public readonly kind: string | ||
public readonly account: string | ||
public readonly fields: AuthAuditMetric | ||
public readonly name = B2B_METRIC_NAME | ||
|
||
constructor(account: string, fields: AuthAuditMetric) { | ||
this.account = account | ||
this.fields = fields | ||
this.kind = 'b2b-quotes-graphql-auth-event' | ||
this.description = 'Auth metric event' | ||
} | ||
} | ||
|
||
const sendAuthMetric = async (logger: Logger, authMetric: AuthMetric) => { | ||
try { | ||
await sendMetric(authMetric) | ||
} catch (error) { | ||
logger.error({ | ||
error, | ||
message: `Error to send metrics from auth metric`, | ||
}) | ||
} | ||
} | ||
|
||
export default sendAuthMetric |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.