Use built in function for special FetchSessionKey

This commit is contained in:
Kalle Carlbark 2021-11-27 23:52:51 +01:00
parent 36ba50352a
commit 72862609c5
No known key found for this signature in database

View file

@ -10,6 +10,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -198,7 +199,7 @@ func (c *Client) FetchSessionKey(privatekey string) error {
query := form.Encode() query := form.Encode()
ctx := context.Background() ctx := context.Background()
req, err := c.newRequest(ctx, "POST", secretsPath+"/get-session-key/", "", query) req, err := http.NewRequestWithContext(ctx, "POST", secretsPath+"/get-session-key/", strings.NewReader(query))
if err != nil { if err != nil {
return err return err
} }
@ -213,6 +214,7 @@ func (c *Client) FetchSessionKey(privatekey string) error {
req.Header.Add("Authorization", " Token "+c.Token) req.Header.Add("Authorization", " Token "+c.Token)
var sessionkey NetBoxSessionKey var sessionkey NetBoxSessionKey
res, err := c.do(req, sessionkey) res, err := c.do(req, sessionkey)
if err != nil { if err != nil {
return err return err