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

Modified the audit log file name and Added deletion of empty file #503

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

KeerthanaAP
Copy link
Contributor

Fix #152

@ppc64le-cloud-bot ppc64le-cloud-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 27, 2023
@@ -70,3 +71,10 @@ func (a *Audit) Log(name, op, value string) {
}
a.mutex.Unlock()
}

func Delete(file string) {
check_file, _ := os.Stat(file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when file doesn't exist for some reason? its better to check for err and do nothing if error occurred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


func Delete(file string) {
check_file, _ := os.Stat(file)
if check_file.Size() == 0 && file == "pvsadm_audit.log" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you wanna check the filename here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to delete the file only if its created by the tool and not to delete the user provided audit file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO its okay to delete the use provided as well if file is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. will remove the condition and delete the user provided file as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

cmd/root.go Outdated
if err := rootCmd.Execute(); err != nil {
klog.Errorln(err)
audit.Delete(pkg.Options.AuditFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we calling this again if its already mentioned above as defer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Defer will not be executed after os.Exit. we are calling the Delete explicitly before that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm..., lets handle the exit in the main() by returning err from here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cmd/root.go Outdated
if err := rootCmd.Execute(); err != nil {
klog.Errorln(err)
audit.Delete(pkg.Options.AuditFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm..., lets handle the exit in the main() by returning err from here

@ppc64le-cloud-bot ppc64le-cloud-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 6, 2023
Copy link
Member

@mkumatag mkumatag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@ppc64le-cloud-bot ppc64le-cloud-bot added the lgtm Indicates that a PR is ready to be merged. label Nov 9, 2023
@ppc64le-cloud-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KeerthanaAP, mkumatag

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ppc64le-cloud-bot ppc64le-cloud-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 9, 2023
@ppc64le-cloud-bot ppc64le-cloud-bot merged commit f3fdc21 into ppc64le-cloud:main Nov 9, 2023
5 checks passed
@KeerthanaAP KeerthanaAP deleted the audit_log branch January 9, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty pvsadm.log file
3 participants