Skip to content

Commit

Permalink
Merge pull request #3303 from uselagoon/testing/activity_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Oct 7, 2022
2 parents 6794ece + 89a078d commit 42f754e
Show file tree
Hide file tree
Showing 20 changed files with 130 additions and 168 deletions.
40 changes: 18 additions & 22 deletions services/api/src/resources/backup/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,18 @@ export const addBackup: ResolverFn = async (

pubSub.publish(EVENTS.BACKUP.ADDED, backup);

userActivityLogger(
`User deployed backup '${backupId}' to '${environment.name}' on project '${environment.project}'`,
{
userActivityLogger(`User deployed backup '${backupId}' to '${environment.name}' on project '${environment.project}'`, {
project: '',
event: 'api:addBackup',
payload: {
id,
environment,
project: environment.project,
event: 'api:addBackup',
payload: {
id,
environment,
source,
backupId,
created
}
source,
backupId,
created
}
);
});

return backup;
};
Expand Down Expand Up @@ -310,18 +308,16 @@ export const addRestore: ResolverFn = async (
project: projectData
};

userActivityLogger(
`User restored a backup '${backupId}' for project ${projectData.name}`,
{
userActivityLogger(`User restored a backup '${backupId}' for project ${projectData.name}`, {
project: '',
event: 'api:addRestore',
payload: {
restoreId: restoreData.id,
project: projectData.name,
event: 'api:addRestore',
payload: {
restoreId: restoreData.id,
backupId,
data
}
backupId,
data
}
);
});

try {
await createMiscTask({ key: 'restic:backup:restore', data });
Expand Down
78 changes: 32 additions & 46 deletions services/api/src/resources/deployment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,14 @@ export const cancelDeployment: ResolverFn = async (
project
};

userActivityLogger(
`User cancelled deployment for '${deployment.environment}'`,
{
project: '',
event: 'api:cancelDeployment',
payload: {
deploymentInput,
data: data.build
}
userActivityLogger(`User cancelled deployment for '${deployment.environment}'`, {
project: '',
event: 'api:cancelDeployment',
payload: {
deploymentInput,
data: data.build
}
);
});

try {
await createMiscTask({ key: 'build:cancel', data });
Expand Down Expand Up @@ -654,16 +651,13 @@ export const deployEnvironmentLatest: ResolverFn = async (
return `Error: Unknown deploy type ${environment.deployType}`;
}

userActivityLogger(
`User triggered a deployment on '${deployData.projectName}' for '${environment.name}'`,
{
project: deployData.projectName || '',
event: 'api:deployEnvironmentLatest',
payload: {
deployData
}
userActivityLogger(`User triggered a deployment on '${deployData.projectName}' for '${environment.name}'`, {
project: '',
event: 'api:deployEnvironmentLatest',
payload: {
deployData
}
);
});

try {
await taskFunction(deployData);
Expand Down Expand Up @@ -756,16 +750,13 @@ export const deployEnvironmentBranch: ResolverFn = async (
branchName: deployData.branchName
};

userActivityLogger(
`User triggered a deployment on '${deployData.projectName}' for '${deployData.branchName}'`,
{
project: deployData.projectName || '',
event: 'api:deployEnvironmentBranch',
payload: {
deployData
}
userActivityLogger(`User triggered a deployment on '${deployData.projectName}' for '${deployData.branchName}'`, {
project: '',
event: 'api:deployEnvironmentBranch',
payload: {
deployData
}
);
});

try {
await createDeployTask(deployData);
Expand Down Expand Up @@ -869,16 +860,13 @@ export const deployEnvironmentPullrequest: ResolverFn = async (
pullrequestTitle: deployData.pullrequestTitle
};

userActivityLogger(
`User triggered a pull-request deployment on '${deployData.projectName}' for '${deployData.branchName}'`,
{
project: deployData.projectName || '',
event: 'api:deployEnvironmentPullrequest',
payload: {
deployData
}
userActivityLogger(`User triggered a pull-request deployment on '${deployData.projectName}' for '${deployData.branchName}'`, {
project: '',
event: 'api:deployEnvironmentPullrequest',
payload: {
deployData
}
);
});

try {
await createDeployTask(deployData);
Expand Down Expand Up @@ -993,16 +981,14 @@ export const deployEnvironmentPromote: ResolverFn = async (
promoteSourceEnvironment: deployData.promoteSourceEnvironment
};

userActivityLogger(
`User promoted the environment on '${deployData.projectName}' from '${deployData.promoteSourceEnvironment}' to '${deployData.branchName}'`,
{
project: deployData.projectName || '',
event: 'api:deployEnvironmentPromote',
payload: {
deployData
}
userActivityLogger(`User promoted the environment on '${deployData.projectName}'
from '${deployData.promoteSourceEnvironment}' to '${deployData.branchName}'`, {
project: '',
event: 'api:deployEnvironmentPromote',
payload: {
deployData
}
);
});

try {
await createPromoteTask(deployData);
Expand Down
8 changes: 4 additions & 4 deletions services/api/src/resources/deploytargetconfig/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const updateEnvironmentDeployTarget: ResolverFn = async (
).getProjectByEnvironmentId(environment);

userActivityLogger(`User changed DeployTarget for environment`, {
project: projectObj.name,
project: '',
event: 'api:updateEnvironmentDeployTarget',
payload: {
...input
Expand Down Expand Up @@ -212,7 +212,7 @@ export const addDeployTargetConfig: ResolverFn = async (
const rows = await query(sqlClientPool, Sql.selectDeployTargetConfigById(insertId));

userActivityLogger(`User added DeployTargetConfig`, {
project: input.name || '',
project: '',
event: 'api:addDeployTargetConfig',
payload: {
...input
Expand Down Expand Up @@ -248,8 +248,8 @@ export const deleteDeployTargetConfig: ResolverFn = async (
}

userActivityLogger(`User deleted DeployTargetConfig'`, {
project: project || '',
event: 'api:deleteEnvironment',
project: '',
event: 'api:deleteDeployTargetConfig',
payload: {
id,
project,
Expand Down
6 changes: 2 additions & 4 deletions services/api/src/resources/env-variables/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ const addEnvVariableToProject = async (

const rows = await query(sqlClientPool, Sql.selectEnvVariable(insertId));

userActivityLogger(`User added environment variable to project '${typeId}'`, {
userActivityLogger(`User added environment variable '${name}' with scope '${scope}' to project '${typeId}'`, {
project: '',
event: 'api:addEnvVariableToProject',
payload: {
id,
name,
value,
scope,
typeId
}
Expand Down Expand Up @@ -136,13 +135,12 @@ const addEnvVariableToEnvironment = async (

const rows = await query(sqlClientPool, Sql.selectEnvVariable(insertId));

userActivityLogger(`User added environment variable to environment '${environment.name}' on '${environment.project}'`, {
userActivityLogger(`User added environment variable '${name}' with scope '${scope}' to environment '${environment.name}' on '${environment.project}'`, {
project: '',
event: 'api:addEnvVariableToEnvironment',
payload: {
id,
name,
value,
scope,
typeId,
environment
Expand Down
8 changes: 4 additions & 4 deletions services/api/src/resources/environment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const addOrUpdateEnvironment: ResolverFn = async (
const rows = await query(sqlClientPool, Sql.selectEnvironmentById(insertId));

userActivityLogger(`User updated environment`, {
project: projectOpenshift.name || '',
project: '',
event: 'api:addOrUpdateEnvironment',
payload: {
...input
Expand Down Expand Up @@ -445,7 +445,7 @@ export const addOrUpdateEnvironmentStorage: ResolverFn = async (
const { name: projectName } = await projectHelpers(sqlClientPool).getProjectByEnvironmentId(environment['environment']);

userActivityLogger(`User updated environment storage on project '${projectName}'`, {
project: projectName || '',
project: '',
event: 'api:addOrUpdateEnvironmentStorage',
payload: {
projectName,
Expand Down Expand Up @@ -557,7 +557,7 @@ export const deleteEnvironment: ResolverFn = async (
}

userActivityLogger(`User deleted environment '${environment.name}' on project '${projectName}'`, {
project: data.projectName || '',
project: '',
event: 'api:deleteEnvironment',
payload: {
projectName,
Expand Down Expand Up @@ -634,7 +634,7 @@ export const updateEnvironment: ResolverFn = async (
const withK8s = Helpers(sqlClientPool).aliasOpenshiftToK8s(rows);

userActivityLogger(`User updated environment '${curEnv.name}' on project '${curEnv.project}'`, {
project: curEnv.project || '',
project: '',
event: 'api:updateEnvironment',
payload: {
openshiftProjectName,
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/resources/file/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const uploadFilesForTask: ResolverFn = async (

const rows = await query(sqlClientPool, taskSql.selectTask(task));

userActivityLogger(
`User uploaded files for task '${task}' on project '${R.path(
userActivityLogger(`User uploaded files for task '${task}' on project
'${R.path(
['0', 'pid'],
rowsPerms
)}'`,
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/resources/group/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export const addGroupsToProject: ResolverFn = async (
}

userActivityLogger(`User synced groups to a project`, {
project: project.name || '',
project: '',
event: 'api:addGroupsToProject',
payload: {
input: {
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/resources/notification/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const addNotificationToProject: ResolverFn = async (


userActivityLogger(`User added a notification to project '${pid}'`, {
project: input.project || '',
project: '',
event: 'api:addNotificationToProject',
payload: {
projectNotification
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/resources/problem/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export const addProblemHarborScanMatch: ResolverFn = async (
);

userActivityLogger(`User added harbor scan regex matcher`, {
project: defaultLagoonProject || '',
project: '',
event: 'api:addProblemHarborScanMatch',
payload: {
input: {
Expand Down
7 changes: 4 additions & 3 deletions services/api/src/resources/project/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export const addProject = async (
}

userActivityLogger(`User added a project '${project.name}'`, {
project: project.name,
project: '',
event: 'api:addProject',
payload: {
input,
Expand Down Expand Up @@ -496,7 +496,7 @@ export const deleteProject: ResolverFn = async (
// }

userActivityLogger(`User deleted a project '${project.name}'`, {
project: project.name,
project: '',
event: 'api:deleteProject',
payload: {
input: {
Expand Down Expand Up @@ -714,9 +714,10 @@ export const updateProject: ResolverFn = async (
// }

userActivityLogger(`User updated project '${oldProject.name}'`, {
project: oldProject.name,
project: '',
event: 'api:updateProject',
payload: {
project: oldProject.name,
patch: {
name,
gitUrl,
Expand Down
Loading

0 comments on commit 42f754e

Please sign in to comment.