-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtruelayer.go
More file actions
71 lines (57 loc) · 1.69 KB
/
truelayer.go
File metadata and controls
71 lines (57 loc) · 1.69 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package truelayer
import (
"net/url"
"time"
"go.k6.io/k6/js/modules"
tlsigning "github.com/Truelayer/truelayer-signing/go"
)
func init() {
modules.Register("k6/x/truelayer", New())
}
type (
// RootModule is the global module instance that will create Truelayer
// instances for each VU.
RootModule struct{}
// TruelayerModule represents an instance of the JS module.
TruelayerModuleInstance struct {
// Truelayer is the exported module instance.
*Truelayer
}
)
// Ensure the interfaces are implemented correctly.
var (
_ modules.Instance = &TruelayerModuleInstance{}
_ modules.Module = &RootModule{}
)
// New returns a pointer to a new RootModule instance.
func New() *RootModule {
return &RootModule{}
}
// NewModuleInstance implements the modules.Module interface and returns
// a new instance for each VU.
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
return &TruelayerModuleInstance{Truelayer: &Truelayer{}}
}
// Truelayer is the exported module instance.
type Truelayer struct{}
func (*Truelayer) Sign(kid string, pem string, path string, method string, headers map[string][]byte, body string) string {
signature, _ := tlsigning.SignWithPem(kid, []byte(pem)).
Path(path).
Method(method).
Headers(headers).
Body([]byte(body)).
Sign()
return signature
}
func (*Truelayer) ParseUrl(urlToParse string) *url.URL {
returnValue, _ := url.Parse(urlToParse)
return returnValue
}
func (*Truelayer) GetTimeMicro() int64 {
return time.Now().UnixMicro()
}
// Exports implements the modules.Instance interface and returns the exports
// of the JS module.
func (t *TruelayerModuleInstance) Exports() modules.Exports {
return modules.Exports{Default: t.Truelayer}
}