Commit 418fcce7 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Working post-installation request

parent 82216c97
......@@ -8,22 +8,27 @@ import (
"github.com/sirupsen/logrus"
)
type InstallationConfig struct {
Token string `yaml:"token,omitempty"`
ServerPublicKey string `yaml:"serverPublicKey,omitempty"`
}
type installationRequest struct {
ClientPublicKey string `json:"client_public_key"`
}
type installationResponse struct {
Response []struct {
ID BunqID `json:"Id"`
ID *BunqID `json:"Id"`
Token struct {
Token *struct {
ID int `json:"id"`
Created string `json:"created"`
Updated string `json:"updated"`
Token string `json:"token"`
} `json:"Token"`
ServerPublicKey struct {
ServerPublicKey *struct {
Key string `json:"server_public_key"`
} `json:"ServerPublicKey"`
} `json:"Response"`
......@@ -57,8 +62,29 @@ func (c *Client) PostInstallation() {
log.WithFields(errResp.LogFields()).Fatal("error performing installation request")
}
for _, subResponse := range response.Response {
if subResponse.ServerPublicKey != nil {
c.creds.ServerPublicKey = subResponse.ServerPublicKey.Key
}
if subResponse.Token != nil {
c.creds.InstallationToken = subResponse.Token.Token
}
}
log.WithFields(logrus.Fields{
"installationToken": response.Response[0].Token.Token,
"serverPublicKey": response.Response[0].ServerPublicKey.Key,
"installationToken": c.creds.InstallationToken,
"serverPublicKey": c.creds.ServerPublicKey,
}).Info("installation token obtained")
c.creds.Save()
}
func (c *Client) CheckInstallation() {
if c.creds.InstallationToken != "" && c.creds.ServerPublicKey != "" {
log.WithFields(logrus.Fields{
"installationToken": c.creds.InstallationToken,
}).Debug("installation token present")
return
}
c.PostInstallation()
}
......@@ -20,7 +20,7 @@ func main() {
logrus.WithField("apiMode", creds.APIMode).Info("loaded credentials")
client := bunqapi.NewClient(creds)
client.PostInstallation()
client.CheckInstallation()
// req := client.NewRequest("POST", "user", nil)
// client.SignRequest(req)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment