-
Notifications
You must be signed in to change notification settings - Fork 2
/
readsession.go
45 lines (35 loc) · 1.17 KB
/
readsession.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
package hintegrate
import (
"encoding/json"
"github.com/hailo-platform/H2O/hintegrate/request"
"github.com/hailo-platform/H2O/hintegrate/validators"
"github.com/hailo-platform/H2O/hintegrate/variables"
)
type readSessionResponse struct {
SessionId string `json:"sessId,omitempty"`
Token string `json:"token,omitempty"`
}
// ReadSession will attempt to call `readsession` on the login service
func ReadSession(c *request.Context, sessionId string, noRenew bool) (*request.ApiReturn, error) {
requestData := map[string]interface{}{
"sessId": sessionId,
"noRenew": noRenew,
}
reqJson, _ := json.Marshal(requestData)
endpoint := "readsession"
postData := map[string]string{
"service": serviceName,
"endpoint": endpoint,
"request": string(reqJson),
}
rsp, err := c.Post().SetHost("callapi_host").
PostDataMap(postData).SetPath("/rpc").
Run(serviceName+"."+endpoint, validators.Status2xxValidator())
vars := variables.NewVariables()
parsed := &readSessionResponse{}
json.Unmarshal(rsp.Body, parsed)
vars.SetVar("Token", parsed.Token)
vars.SetVar("SessionId", parsed.SessionId)
ret := &request.ApiReturn{Raw: rsp, ParsedVars: vars}
return ret, err
}