go-jira icon indicating copy to clipboard operation
go-jira copied to clipboard

Added the AuditService

Open ctreminiom opened this issue 3 years ago • 3 comments

Description

Added the feature to interacts with the Jira Data Center/Server Audit Logs such as Search Audit Logs and Create new entries.

Information that is useful here:

  • The What: Added a new Service called AuditService with the methods Search and Add
  • The Why: It's useful for Jira administrators to extract security audits requested by the company SO
  • Type of change: New Feature and added documentation
  • Breaking change: NO, Backward compatible: YES
  • Related to an issue: Nop
  • Jira Version + Type: Jira 8.5.13 on-prem

Example:

Let us know how users can use or test this functionality.

Search Audit Records

See examples/audit/get/get.go

// the the records associated with the creation on the last 2 hours
	options := &jira.AuditSearchOptionsScheme{
		Filter:     "created",
		From:       time.Now().Add(time.Duration(-2) * time.Hour), // Last 2 hours
		To:         time.Time{},
		ProjectIDs: nil,
		UserIDs:    nil,
	}

	records, response, err := client.Audit.Search(context.Background(), options, 0, 50)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.StatusCode)
		}
		log.Fatal(err)
	}

	for index, record := range records.Records {

		log.Println("----------------------------------")
		log.Printf("Record #%v", index+1)
		log.Printf("Record ID: %v", record.ID)
		log.Printf("Record Created by: %v", record.Created)
		log.Printf("Record Category: %v", record.Category)
		log.Printf("Record Source IP: %v", record.RemoteAddress)
		log.Printf("Record Event: %v", record.EventSource)
		log.Println("----------------------------------")
	}

Add Audit Record

newRecord := &jira.AuditRecord{
		Summary:  "User created",
		Category: "USER_MANAGEMENT",
		ObjectItem: &jira.AuditRecordObjectItem{
			ID:       "usr",
			Name:     "user",
			TypeName: "USER",
		},
		ChangedValues: []*jira.AuditRecordChangedValue{
			{
				FieldName:   "email",
				ChangedTo:   "[email protected]",
				ChangedFrom: "[email protected]",
			},
		},

		AssociatedItems: []*jira.AuditRecordAssociatedItem{
			{
				ID:         "jira-software-users",
				Name:       "jira-software-users",
				TypeName:   "GROUP",
				ParentID:   "1",
				ParentName: "Jira Internal Directory",
			},
		},
	}

	response, err := client.Audit.Add(context.Background(), newRecord)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.StatusCode)
		}
		log.Fatal(err)
	}

	log.Println(response.StatusCode)

Checklist

ctreminiom avatar Mar 27 '21 10:03 ctreminiom

@ctreminiom Is there a way to update this so it works with v2 and v3? That way it can support cloud? https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-audit-records/

benjivesterby avatar Feb 20 '22 15:02 benjivesterby

Hey,

I am very sorry that this pull request has been open for a long time with no final feedback or merge/decline. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in https://github.com/andygrunwald/go-jira/issues/489

The development will take some time; however, I hope you can benefit from the changes. If you seek priority development for your pull request + you like to sponsor it, please contact me.

What does this mean for my pull request?

We will work on this pull request indirectly. We might merge it during the development or pull parts of it into the new version. This means that during the development phase, we aim to tackle it. Maybe in a different way like it is currently handled. Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using and contributing to this library. If there is anything else you would like to tell us, let us know!

andygrunwald avatar Aug 21 '22 15:08 andygrunwald

@ctreminiom I see that this PR was closed automatically. I will re-open it, because I do think this is a valuable contribution. I will also take care on adjusting this PR to the current codebase later on.

andygrunwald avatar Oct 30 '22 11:10 andygrunwald