-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (48 loc) · 1.14 KB
/
main.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
package main
import (
"context"
"flag"
"io"
"log"
"net/http"
"github.com/jmczerk/instance-id/utils"
)
var (
threads = flag.Int("threads", 1, "Number of threads")
iterations = flag.Int("iterations", 1, "Number of times to run per thread")
sleepTime = flag.Int("max-sleep-time", 10, "Max time to sleep between iterations")
)
func do(idr *utils.PresignedEC2InstanceIdentityRequest) {
req := &http.Request{
Method: idr.Method,
URL: &idr.URL,
Header: idr.SignedHeader,
}
rsp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalf("Perf req failed: %v", err)
}
body, err := io.ReadAll(rsp.Body)
if err != nil {
log.Fatalf("Reading body failed: %v", err)
}
log.Println(string(body))
}
func main() {
ctx := context.Background()
auth, err := utils.AuthenticateInstance(ctx)
if err != nil {
log.Fatalf("AuthenticateInstance failed: %v", err)
}
do(auth)
enc, err := auth.MarshalAndEncode()
if err != nil {
log.Fatalf("Encoding req failed: %v", err)
}
log.Printf("Encoded request:\n%v", enc)
dec, err := utils.DecodeAndUnmarshal(enc)
if err != nil {
log.Fatalf("Decoding req failed: %v", err)
}
do(dec)
}