-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventsapi.go
More file actions
57 lines (49 loc) · 1.8 KB
/
eventsapi.go
File metadata and controls
57 lines (49 loc) · 1.8 KB
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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
)
func main() {
api_token := os.Getenv("EVENTS_API_TOKEN")
url := "https://events.1password.com"
start_time := time.Now().AddDate(0, 0, -1)
payload := []byte(fmt.Sprintf(`{
"limit": 20,
"start_time": "%s"
}`, start_time.Format(time.RFC3339)))
client := &http.Client{}
signinsRequest, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/v1/signinattempts", url), bytes.NewBuffer(payload))
signinsRequest.Header.Set("Content-Type", "application/json")
signinsRequest.Header.Set("Authorization", "Bearer "+api_token)
signinsResponse, signinsError := client.Do(signinsRequest)
if signinsError != nil {
panic(signinsError)
}
defer signinsResponse.Body.Close()
signinsBody, _ := ioutil.ReadAll(signinsResponse.Body)
fmt.Println(string(signinsBody))
usagesRequest, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/v1/itemusages", url), bytes.NewBuffer(payload))
usagesRequest.Header.Set("Content-Type", "application/json")
usagesRequest.Header.Set("Authorization", "Bearer "+api_token)
usagesResponse, usagesError := client.Do(usagesRequest)
if usagesError != nil {
panic(usagesError)
}
defer usagesResponse.Body.Close()
usagesBody, _ := ioutil.ReadAll(usagesResponse.Body)
fmt.Println(string(usagesBody))
auditEventsRequest, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/v1/auditevents", url), bytes.NewBuffer(payload))
auditEventsRequest.Header.Set("Content-Type", "application/json")
auditEventsRequest.Header.Set("Authorization", "Bearer "+api_token)
auditEventsResponse, auditEventsError := client.Do(auditEventsRequest)
if auditEventsError != nil {
panic(auditEventsError)
}
defer auditEventsResponse.Body.Close()
auditEventsBody, _ := ioutil.ReadAll(auditEventsResponse.Body)
fmt.Println(string(auditEventsBody))
}