-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_history.go
105 lines (88 loc) · 2.21 KB
/
get_history.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 bsshgo
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
)
//implementation for
//https://developer.basespace.illumina.com/docs/content/documentation/rest-api/history-api-reference#HistoryAPIReference
//support the token is history token with scope=AUDIT USER
type HistoryResp struct {
Items []map[string]interface{}
Paging struct {
// "TotalCount": 1247,
TotalCount int64
// "DisplayedCount": 10,
DisplayedCount int64
// "Limit": 10,
Limit int64
// "SortBy": "DateCreated",
SortBy string
// "SortDir": "desc",
SortDir string
// "After": "184181146749957033",
After string
// "Before": "184181438804378115"
Before string
}
}
type FieldChange struct {
NewValue string
OldValue string
}
//BsshEventPre likely the common attributes accross all event's Items
type BsshEventPre struct {
ActingUserId string
ActingUserName string
EventType string
DateCreated string
Id string //unique event ID at bssh
LoggedInUserName string
ResourceId string
ResourceType string
FieldChanges map[string]*FieldChange
// Metadata map[string]string
}
func (self *Client) SearchHistory(ctx context.Context, params map[string]string) (*HistoryResp, error) {
if self.User == nil {
user, err := self.GetCurrentUser(ctx)
if err != nil {
return nil, fmt.Errorf(`GetCurrentUser:%s`, err.Error())
}
self.User = user
}
_url := self.User.Response.HrefHistory
if _url == "" {
return nil, fmt.Errorf(`self.User.Response.HrefHistory is empty`)
}
base, err := url.Parse(_url)
if err != nil {
return nil, err
}
q := url.Values{}
if params != nil {
for k, v := range params {
q.Add(k, v)
}
}
base.RawQuery = q.Encode()
resp, err := self.NewRequestWithContext(ctx, `GET`, base.String(), nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf(`bad status code-%d:%s`, resp.StatusCode, string(body))
}
ret := new(HistoryResp)
if err := json.Unmarshal(body, ret); err != nil {
return nil, fmt.Errorf(`Unmarshal:%s`, err.Error())
}
return ret, nil
}