-
Notifications
You must be signed in to change notification settings - Fork 31
/
audit.go
105 lines (86 loc) · 3.24 KB
/
audit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package jira
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
)
type AuditService struct{ client *Client }
type AuditRecordPageScheme struct {
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
Total int `json:"total,omitempty"`
Records []*AuditRecordScheme `json:"records,omitempty"`
}
type AuditRecordScheme struct {
ID int `json:"id,omitempty"`
Summary string `json:"summary,omitempty"`
RemoteAddress string `json:"remoteAddress,omitempty"`
AuthorKey string `json:"authorKey,omitempty"`
Created string `json:"created,omitempty"`
Category string `json:"category,omitempty"`
EventSource string `json:"eventSource,omitempty"`
Description string `json:"description,omitempty"`
ObjectItem *AuditRecordObjectItemScheme `json:"objectItem,omitempty"`
ChangedValues []*AuditRecordChangedValueScheme `json:"changedValues,omitempty"`
AssociatedItems []*AuditRecordAssociatedItemScheme `json:"associatedItems,omitempty"`
}
type AuditRecordObjectItemScheme struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
}
type AuditRecordChangedValueScheme struct {
FieldName string `json:"fieldName,omitempty"`
ChangedFrom string `json:"changedFrom,omitempty"`
ChangedTo string `json:"changedTo,omitempty"`
}
type AuditRecordAssociatedItemScheme struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
}
type AuditRecordGetOptions struct {
Filter string
From, To time.Time
}
// Returns a list of audit records. The list can be filtered to include items:
// Docs: https://docs.go-atlassian.io/jira-software-cloud/audit-records#get-audit-records
func (a *AuditService) Get(ctx context.Context, options *AuditRecordGetOptions, offset, limit int) (result *AuditRecordPageScheme, response *Response, err error) {
params := url.Values{}
params.Add("offset", strconv.Itoa(offset))
params.Add("limit", strconv.Itoa(limit))
if options != nil {
if len(options.Filter) != 0 {
params.Add("filter", options.Filter)
}
if !options.From.IsZero() {
params.Add("from", options.From.Format(DateFormatJira))
}
if !options.To.IsZero() {
params.Add("to", options.To.Format(DateFormatJira))
}
}
var endpoint = fmt.Sprintf("rest/api/3/auditing/record?%s", params.Encode())
request, err := a.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = a.client.Do(request)
if err != nil {
return
}
result = new(AuditRecordPageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return
}
return
}