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

Extract psapi into github.com/planetscale/planetscale-go #27

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@ In order to get setup and running with this project, you can run `script/setup`
You can install and use the program using `script/build` or `go install ./...`. After doing so, you can run the tool using `psctl <command> [subcommand] [flags]`.



For using the CLI locally, there's some extra setup involved to get authenticated.

### Updating the vendored API package


To update the vendored `github.com/planetscale/planetscale-go` API package,
first make sure to set up Go for private repositories:

```
go env -w GOPRIVATE="github.com/planetscale/*"
```

Then, use the following commands to fetch the `latest` HEAD version of the CLI:

```
go get github.com/planetscale/planetscale-go
go mod vendor
go mod tidy
```

#### For logging in:
1. Create a Rails OAuth application at `http://auth.planetscaledb.local:3000/oauth/applications/new`. Make sure the `Confidential` box is unchecked and that the scopes are `read_database write_database`. You can make the `Redirect URI` be anything.
2. After creating this application, keep note of the client ID.
Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path"

"github.com/mitchellh/go-homedir"
"github.com/planetscale/cli/psapi"
ps "github.com/planetscale/planetscale-go"
)

const (
Expand Down Expand Up @@ -36,7 +36,7 @@ func New() *Config {

return &Config{
AccessToken: string(accessToken),
BaseURL: psapi.DefaultBaseURL,
BaseURL: ps.DefaultBaseURL,
}
}

Expand All @@ -56,8 +56,8 @@ func AccessTokenPath() string {
}

// NewClientFromConfig creates a PlaentScale API client from our configuration
func (c *Config) NewClientFromConfig(opts ...psapi.ClientOption) (*psapi.Client, error) {
args := []psapi.ClientOption{psapi.SetBaseURL(c.BaseURL)}
func (c *Config) NewClientFromConfig(opts ...ps.ClientOption) (*ps.Client, error) {
args := []ps.ClientOption{ps.SetBaseURL(c.BaseURL)}
args = append(args, opts...)
return psapi.NewClientFromToken(c.AccessToken, args...)
return ps.NewClientFromToken(c.AccessToken, args...)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/browser v0.0.0-20201112035734-206646e67786
github.com/pkg/errors v0.9.1
github.com/planetscale/planetscale-go v0.0.0-20210109112707-8edffde9c156
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.6.1
golang.org/x/oauth2 v0.0.0-20201203001011-0b49973bad19
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/planetscale/planetscale-go v0.0.0-20210109112707-8edffde9c156 h1:HAAXn5h2s2+mRR8xY7K0PRHPzev8SoYWxUorGaQRxBc=
github.com/planetscale/planetscale-go v0.0.0-20210109112707-8edffde9c156/go.mod h1:Q5/JMffdDyOcW21MXiCDI9Pf1H/qPQi3tl1JLBZzzJs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down Expand Up @@ -369,8 +371,8 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20201203001011-0b49973bad19 h1:ZD+2Sd/BnevwJp8PSli8WgGAGzb9IZtxBsv1iZMYeEA=
golang.org/x/oauth2 v0.0.0-20201203001011-0b49973bad19/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5 h1:Lm4OryKCca1vehdsWogr9N4t7NfZxLbJoc/H0w4K4S4=
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/database/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

"github.com/pkg/browser"
"github.com/planetscale/cli/config"
"github.com/planetscale/cli/psapi"
ps "github.com/planetscale/planetscale-go"

"github.com/spf13/cobra"
)

// CreateCmd is the command for creating a database.
func CreateCmd(cfg *config.Config) *cobra.Command {
createReq := &psapi.CreateDatabaseRequest{
Database: new(psapi.Database),
createReq := &ps.CreateDatabaseRequest{
Database: new(ps.Database),
}
cmd := &cobra.Command{
Use: "create",
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/planetscale/cli/config"
"github.com/planetscale/cli/pkg/cmd/auth"
"github.com/planetscale/cli/pkg/cmd/database"
"github.com/planetscale/cli/psapi"
ps "github.com/planetscale/planetscale-go"
"github.com/spf13/cobra"

homedir "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -68,7 +68,7 @@ func init() {

cfg := config.New()

rootCmd.PersistentFlags().StringVar(&cfg.BaseURL, "api-url", psapi.DefaultBaseURL, "The base URL for the PlanetScale API.")
rootCmd.PersistentFlags().StringVar(&cfg.BaseURL, "api-url", ps.DefaultBaseURL, "The base URL for the PlanetScale API.")
rootCmd.PersistentFlags().StringVar(&cfg.AccessToken, "api-token", cfg.AccessToken, "The API token to use for authenticating against the PlanetScale API.")
rootCmd.AddCommand(auth.AuthCmd(cfg))
rootCmd.AddCommand(database.DatabaseCmd(cfg))
Expand Down
113 changes: 0 additions & 113 deletions psapi/client_test.go

This file was deleted.

10 changes: 10 additions & 0 deletions vendor/github.com/planetscale/planetscale-go/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/planetscale/planetscale-go/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading