Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to authenticate/work with different host #26

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/writeas/api.go
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"path/filepath"

"github.com/atotto/clipboard"
"github.com/writeas/web-core/posts"
"github.com/writeas/writeas-cli/fileutils"
"go.code.as/writeas.v2"
"gopkg.in/urfave/cli.v1"
"path/filepath"
)

const (
Expand Down Expand Up @@ -40,12 +41,17 @@ func newClient(c *cli.Context, authRequired bool) (*writeas.Client, error) {
} else {
client = writeas.NewClient()
}

if c.String("host") != "" {
client.SetBaseUrl(c.String("host") + "/api")
}
}
client.UserAgent = userAgent(c)
// TODO: load user into var shared across the app
u, _ := loadUser()
if u != nil {
client.SetToken(u.AccessToken)
client.SetBaseUrl(u.BaseURL)
} else if authRequired {
return nil, fmt.Errorf("Not currently logged in. Authenticate with: writeas auth <username>")
}
Expand Down Expand Up @@ -177,7 +183,7 @@ func DoDelete(c *cli.Context, friendlyID, token string, tor bool) error {
}

func DoLogIn(c *cli.Context, username, password string) error {
cl := client(userAgent(c), isTor(c))
cl, _ := newClient(c, false)

u, err := cl.LogIn(username, password)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions cmd/writeas/cli.go
Expand Up @@ -2,11 +2,12 @@ package main

import (
"bufio"
"go.code.as/writeas.v2"
"gopkg.in/urfave/cli.v1"
"io"
"log"
"os"

"go.code.as/writeas.v2"
"gopkg.in/urfave/cli.v1"
)

// API constants for communicating with Write.as.
Expand Down Expand Up @@ -254,6 +255,10 @@ func main() {
Usage: "Authenticate with Write.as",
Action: cmdAuth,
Flags: []cli.Flag{
cli.StringFlag{
Name: "host",
Usage: "Set host address",
},
cli.BoolFlag{
Name: "tor, t",
Usage: "Authenticate via Tor hidden service",
Expand Down