ready to get a real token
parent
7a946b7604
commit
c38e8529af
18
cmd/main.go
18
cmd/main.go
|
|
@ -1,14 +1,32 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"gogs.inhome.blapointe.com/ana-ledger/cmd/cli"
|
"gogs.inhome.blapointe.com/ana-ledger/cmd/cli"
|
||||||
"gogs.inhome.blapointe.com/ana-ledger/cmd/http"
|
"gogs.inhome.blapointe.com/ana-ledger/cmd/http"
|
||||||
|
"gogs.inhome.blapointe.com/ana-ledger/src/bank/teller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
|
case "tel":
|
||||||
|
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
|
||||||
|
defer can()
|
||||||
|
|
||||||
|
if c, err := teller.New(); err != nil {
|
||||||
|
} else if _, err := c.Accounts(ctx); err != nil {
|
||||||
|
} else {
|
||||||
|
log.Println("teller already init")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := teller.Init(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
case "http":
|
case "http":
|
||||||
os.Args = append([]string{os.Args[0]}, os.Args[2:]...)
|
os.Args = append([]string{os.Args[0]}, os.Args[2:]...)
|
||||||
http.Main()
|
http.Main()
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ var (
|
||||||
certificate []byte
|
certificate []byte
|
||||||
//go:embed private_key.pem
|
//go:embed private_key.pem
|
||||||
privateKey []byte
|
privateKey []byte
|
||||||
|
//go:embed token.txt
|
||||||
|
Token string
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() (Client, error) {
|
func New() (Client, error) {
|
||||||
|
|
@ -54,7 +56,7 @@ func (c Client) get(ctx context.Context, url string, ptr interface{}) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
req.SetBasicAuth("test_token_bfu2cyvq3il6o", "") // TODO
|
req.SetBasicAuth(Token, "")
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
|
|
||||||
resp, err := httpc.Do(req)
|
resp, err := httpc.Do(req)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
|
teller.Token = "test_token_bfu2cyvq3il6o"
|
||||||
|
|
||||||
c, err := teller.New()
|
c, err := teller.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,13 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gogs.inhome.blapointe.com/ana-ledger/src/bank/teller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
|
teller.Token = "test_token_bfu2cyvq3il6o"
|
||||||
|
|
||||||
//curl --cert certificate.pem --cert-key private_key.pem --auth test_token_bfu2cyvq3il6o: https://api.teller.io/accounts
|
//curl --cert certificate.pem --cert-key private_key.pem --auth test_token_bfu2cyvq3il6o: https://api.teller.io/accounts
|
||||||
cert, err := tls.LoadX509KeyPair("./certificate.pem", "./private_key.pem")
|
cert, err := tls.LoadX509KeyPair("./certificate.pem", "./private_key.pem")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
Loading…
Reference in New Issue