wizard use state
This commit is contained in:
parent
77efe1eae7
commit
248744dc3d
12 changed files with 751 additions and 406 deletions
151
proto/wizard_service/autogenerated/go/http_client.go
Normal file
151
proto/wizard_service/autogenerated/go/http_client.go
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
// This file was autogenerated from a .proto file, DO NOT EDIT!
|
||||
|
||||
package lightning_pub
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func doPostRequest(url string, body []byte, auth string) ([]byte, error) {
|
||||
bodyReader := bytes.NewReader(body)
|
||||
req, err := http.NewRequest(http.MethodPost, url, bodyReader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("authorization", auth)
|
||||
return doRequest(req)
|
||||
}
|
||||
|
||||
func doGetRequest(url string, auth string) ([]byte, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("authorization", auth)
|
||||
return doRequest(req)
|
||||
}
|
||||
|
||||
func doRequest(req *http.Request) ([]byte, error) {
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resBody, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resBody, nil
|
||||
}
|
||||
|
||||
type ClientParams struct {
|
||||
BaseURL string
|
||||
RetrieveGuestAuth func() (string, error)
|
||||
}
|
||||
type Client struct {
|
||||
GetAdminConnectInfo func() (*AdminConnectInfoResponse, error)
|
||||
GetServiceState func() (*ServiceStateResponse, error)
|
||||
WizardConfig func(req ConfigRequest) error
|
||||
WizardState func() (*StateResponse, error)
|
||||
}
|
||||
|
||||
func NewClient(params ClientParams) *Client {
|
||||
return &Client{
|
||||
GetAdminConnectInfo: func() (*AdminConnectInfoResponse, error) {
|
||||
auth, err := params.RetrieveGuestAuth()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalRoute := "/wizard/admin_connect_info"
|
||||
resBody, err := doGetRequest(params.BaseURL+finalRoute, auth)
|
||||
result := ResultError{}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result.Status == "ERROR" {
|
||||
return nil, fmt.Errorf(result.Reason)
|
||||
}
|
||||
res := AdminConnectInfoResponse{}
|
||||
err = json.Unmarshal(resBody, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
},
|
||||
GetServiceState: func() (*ServiceStateResponse, error) {
|
||||
auth, err := params.RetrieveGuestAuth()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalRoute := "/wizard/service_state"
|
||||
resBody, err := doGetRequest(params.BaseURL+finalRoute, auth)
|
||||
result := ResultError{}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result.Status == "ERROR" {
|
||||
return nil, fmt.Errorf(result.Reason)
|
||||
}
|
||||
res := ServiceStateResponse{}
|
||||
err = json.Unmarshal(resBody, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
},
|
||||
WizardConfig: func(req ConfigRequest) error {
|
||||
auth, err := params.RetrieveGuestAuth()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
finalRoute := "/wizard/config"
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resBody, err := doPostRequest(params.BaseURL+finalRoute, body, auth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result := ResultError{}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.Status == "ERROR" {
|
||||
return fmt.Errorf(result.Reason)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
WizardState: func() (*StateResponse, error) {
|
||||
auth, err := params.RetrieveGuestAuth()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalRoute := "/wizard/state"
|
||||
resBody, err := doGetRequest(params.BaseURL+finalRoute, auth)
|
||||
result := ResultError{}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result.Status == "ERROR" {
|
||||
return nil, fmt.Errorf(result.Reason)
|
||||
}
|
||||
res := StateResponse{}
|
||||
err = json.Unmarshal(resBody, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
60
proto/wizard_service/autogenerated/go/types.go
Normal file
60
proto/wizard_service/autogenerated/go/types.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// This file was autogenerated from a .proto file, DO NOT EDIT!
|
||||
|
||||
package lightning_pub
|
||||
|
||||
type ResultError struct {
|
||||
Status string `json:"status"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
type GuestContext struct {
|
||||
}
|
||||
type LndState string
|
||||
|
||||
const (
|
||||
OFFLINE LndState = "OFFLINE"
|
||||
ONLINE LndState = "ONLINE"
|
||||
SYNCING LndState = "SYNCING"
|
||||
)
|
||||
|
||||
type AdminConnectInfoResponse struct {
|
||||
Connect_info *AdminConnectInfoResponse_connect_info `json:"connect_info"`
|
||||
Nprofile string `json:"nprofile"`
|
||||
}
|
||||
type ConfigRequest struct {
|
||||
Automate_liquidity bool `json:"automate_liquidity"`
|
||||
Push_backups_to_nostr bool `json:"push_backups_to_nostr"`
|
||||
Relay_url string `json:"relay_url"`
|
||||
Source_name string `json:"source_name"`
|
||||
}
|
||||
type Empty struct {
|
||||
}
|
||||
type ServiceStateResponse struct {
|
||||
Admin_npub string `json:"admin_npub"`
|
||||
Automate_liquidity bool `json:"automate_liquidity"`
|
||||
Http_url string `json:"http_url"`
|
||||
Lnd_state LndState `json:"lnd_state"`
|
||||
Nprofile string `json:"nprofile"`
|
||||
Provider_name string `json:"provider_name"`
|
||||
Push_backups_to_nostr bool `json:"push_backups_to_nostr"`
|
||||
Relay_connected bool `json:"relay_connected"`
|
||||
Relay_url string `json:"relay_url"`
|
||||
Relays []string `json:"relays"`
|
||||
Source_name string `json:"source_name"`
|
||||
Watchdog_ok bool `json:"watchdog_ok"`
|
||||
}
|
||||
type StateResponse struct {
|
||||
Admin_linked bool `json:"admin_linked"`
|
||||
Config_sent bool `json:"config_sent"`
|
||||
}
|
||||
type AdminConnectInfoResponse_connect_info_type string
|
||||
|
||||
const (
|
||||
ADMIN_TOKEN AdminConnectInfoResponse_connect_info_type = "admin_token"
|
||||
ENROLLED_NPUB AdminConnectInfoResponse_connect_info_type = "enrolled_npub"
|
||||
)
|
||||
|
||||
type AdminConnectInfoResponse_connect_info struct {
|
||||
Type AdminConnectInfoResponse_connect_info_type `json:"type"`
|
||||
Admin_token *string `json:"admin_token"`
|
||||
Enrolled_npub *string `json:"enrolled_npub"`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue