Skip to content
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

Unblock dev #816

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions src/lib/audit-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const fetch = require('node-fetch')
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const { getCliEnv, PROD_ENV } = require('@adobe/aio-lib-env')

const OPERATIONS = {
AB_APP_DEPLOY: 'ab_app_deploy',
Expand All @@ -33,6 +34,11 @@ const AUDIT_SERVICE_ENPOINTS = {
* @param {string} env valid env stage|prod
*/
async function sendAuditLogs (accessToken, logEvent, env = 'prod') {
// TODO: this is blocked by the audit service only being available in stage
// remove this check once the service is available in prod
if (env !== 'stage') {
return
}
const url = AUDIT_SERVICE_ENPOINTS[env]
const payload = {
event: logEvent
Expand Down Expand Up @@ -60,6 +66,11 @@ async function sendAuditLogs (accessToken, logEvent, env = 'prod') {
* @returns {object} logEvent
*/
function getAuditLogEvent (flags, project, event) {
if (getCliEnv() === PROD_ENV) {
console.log('Audit logging is currently disabled in production environment')
return
}

let logEvent, logStrMsg
if (project && project.org && project.workspace) {
if (event === 'AB_APP_DEPLOY') {
Expand Down
5 changes: 3 additions & 2 deletions test/commands/lib/audit-logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ test('sendAuditLogs with valid params', async () => {
expect(fetch).toHaveBeenCalledWith(auditLogger.AUDIT_SERVICE_ENPOINTS[mockEnv], options)
})

// NOTE: this test is blocked until the audit service is available in prod
test('sendAuditLogs with default params', async () => {
fetch.mockReturnValue(mockResponse)
const options = {
Expand All @@ -86,8 +87,8 @@ test('sendAuditLogs with default params', async () => {
body: JSON.stringify({ event: mockLogEvent })
}
await auditLogger.sendAuditLogs(mockToken, mockLogEvent)
expect(fetch).toHaveBeenCalledTimes(1)
expect(fetch).toHaveBeenCalledWith(auditLogger.AUDIT_SERVICE_ENPOINTS.prod, options)
expect(fetch).toHaveBeenCalledTimes(0)
// expect(fetch).toHaveBeenCalledWith(auditLogger.AUDIT_SERVICE_ENPOINTS.prod, options)
})

test('sendAuditLogs error response', async () => {
Expand Down
Loading