Skip to content

Commit

Permalink
New project layout (stripe#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe authored Jul 8, 2019
1 parent 4016f72 commit 9b25dbc
Show file tree
Hide file tree
Showing 50 changed files with 152 additions and 139 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Goreleaser
dist/
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project_name: stripe
builds:
-
- main: ./cmd/stripe/main.go
env:
- CGO_ENABLED=0
- GO111MODULE=on
Expand All @@ -11,7 +11,7 @@ builds:
goarch:
- amd64
ldflags:
- -s -w -X github.com/stripe/stripe-cli/version.Version={{.Version}}
- -s -w -X github.com/stripe/stripe-cli/pkg/version.Version={{.Version}}
archives:
-
replacements:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif
golint -set_exit_status ./...

vet:
go vet $(go list ./... | grep -v /vendor/)
go vet $(shell go list ./... | grep -v /vendor/)

test: install-deps lint vet
go test -race -cover -v ./...
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion main.go → cmd/stripe/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "github.com/stripe/stripe-cli/cmd"
import "github.com/stripe/stripe-cli/pkg/cmd"

func main() {
cmd.Execute()
Expand Down
1 change: 0 additions & 1 deletion ansi/ansi.go → pkg/ansi/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/briandowns/spinner"
"github.com/logrusorgru/aurora"
"github.com/tidwall/pretty"

"golang.org/x/crypto/ssh/terminal"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/completion.go → pkg/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package cmd

import (
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/validators"

"github.com/stripe/stripe-cli/pkg/validators"
)

type completionCmd struct {
Expand Down
5 changes: 3 additions & 2 deletions cmd/delete.go → pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package cmd

import (
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/requests"
"github.com/stripe/stripe-cli/validators"

"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/validators"
)

type deleteCmd struct {
Expand Down
5 changes: 3 additions & 2 deletions cmd/get.go → pkg/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package cmd

import (
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/requests"
"github.com/stripe/stripe-cli/validators"

"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/validators"
)

type getCmd struct {
Expand Down
8 changes: 4 additions & 4 deletions cmd/listen.go → pkg/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"strconv"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/proxy"
"github.com/stripe/stripe-cli/requests"
"github.com/stripe/stripe-cli/validators"

log "github.com/sirupsen/logrus"
"github.com/stripe/stripe-cli/pkg/proxy"
"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/validators"
)

type listenCmd struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/listen_test.go → pkg/cmd/listen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"testing"

assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-cli/requests"

"github.com/stripe/stripe-cli/pkg/requests"
)

func TestParseUrl(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions cmd/login.go → pkg/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package cmd

import (
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/login"
"github.com/stripe/stripe-cli/validators"

"github.com/stripe/stripe-cli/pkg/login"
"github.com/stripe/stripe-cli/pkg/validators"
)

type loginCmd struct {
cmd *cobra.Command
cmd *cobra.Command
interactive bool
url string
url string
}

func newLoginCmd() *loginCmd {
Expand All @@ -19,8 +20,8 @@ func newLoginCmd() *loginCmd {
Use: "login",
Args: validators.NoArgs,
Short: "Log into your Stripe account",
Long: `Log into your Stripe account to write your configuration file`,
RunE: lc.runLoginCmd,
Long: `Log into your Stripe account to write your configuration file`,
RunE: lc.runLoginCmd,
}
lc.cmd.Flags().BoolVarP(&lc.interactive, "interactive", "i", false, "interactive configuration mode")
lc.cmd.Flags().StringVarP(&lc.url, "url", "u", "", "Testing URL for login ")
Expand All @@ -29,7 +30,6 @@ func newLoginCmd() *loginCmd {
return lc
}


func (lc *loginCmd) runLoginCmd(cmd *cobra.Command, args []string) error {
if lc.interactive {
return login.InteractiveLogin(Profile)
Expand Down
23 changes: 11 additions & 12 deletions cmd/login_test.go → pkg/cmd/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stripe/stripe-cli/login"
"github.com/stripe/stripe-cli/profile"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/stripe/stripe-cli/pkg/login"
"github.com/stripe/stripe-cli/pkg/profile"
)

func TestLogin(t *testing.T) {
configFile := filepath.Join(os.TempDir(), "stripe", "config.toml")
p := profile.Profile{
Color: "auto",
ConfigFile: configFile,
LogLevel: "info",
LogLevel: "info",
ProfileName: "tests",
DeviceName: "st-testing",
DeviceName: "st-testing",
}



var pollURL string
var browserURL string

Expand All @@ -41,13 +40,13 @@ func TestLogin(t *testing.T) {
}
json.NewEncoder(w).Encode(expectedLinks)
}
if strings.Contains(r.URL.Path,"browser") {
if strings.Contains(r.URL.Path, "browser") {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/html")
w.Write([]byte("<HTML></HTML>"))

}
if strings.Contains(r.URL.Path,"poll") {
if strings.Contains(r.URL.Path, "poll") {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
data := []byte(`{"redeemed": true, "account_id": "acct_123", "testmode_key_secret": "sk_test_1234"}`)
Expand All @@ -57,9 +56,9 @@ func TestLogin(t *testing.T) {
}))
defer ts.Close()

authURL := fmt.Sprintf( "%s%s", ts.URL, "/auth")
pollURL = fmt.Sprintf( "%s%s", ts.URL, "/poll")
browserURL = fmt.Sprintf( "%s%s", ts.URL, "/browser")
authURL := fmt.Sprintf("%s%s", ts.URL, "/auth")
pollURL = fmt.Sprintf("%s%s", ts.URL, "/poll")
browserURL = fmt.Sprintf("%s%s", ts.URL, "/browser")

err := login.Login(authURL, p)
assert.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/post.go → pkg/cmd/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package cmd

import (
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/requests"
"github.com/stripe/stripe-cli/validators"

"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/validators"
)

type postCmd struct {
Expand Down Expand Up @@ -32,7 +33,6 @@ $ stripe post /payment_intents -d amount=2000 -d currency=usd -d payment_method_
RunE: gc.reqs.RunRequestsCmd,
}


gc.reqs.InitFlags()

return gc
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go → pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"
prof "github.com/stripe/stripe-cli/profile"
"github.com/stripe/stripe-cli/version"

prof "github.com/stripe/stripe-cli/pkg/profile"
"github.com/stripe/stripe-cli/pkg/version"
)

// Profile is the cli configuration for the user
Expand Down
File renamed without changes.
36 changes: 18 additions & 18 deletions cmd/trigger.go → pkg/cmd/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/requests"
"github.com/stripe/stripe-cli/validators"

"github.com/stripe/stripe-cli/pkg/requests"
"github.com/stripe/stripe-cli/pkg/validators"
)

const apiVersion = "2019-03-14"
Expand Down Expand Up @@ -50,7 +51,6 @@ Supported events:
},
}


return tc
}

Expand All @@ -62,28 +62,28 @@ func triggerEvent(event string) error {

examples := requests.Examples{
Profile: Profile,
APIUrl: stripeURL,
APIUrl: stripeURL,
APIVersion: apiVersion,
SecretKey: secretKey,
}

supportedEvents := map[string]interface{}{
"charge.captured": examples.ChargeCaptured,
"charge.failed": examples.ChargeFailed,
"charge.succeeded": examples.ChargeSucceeded,
"customer.created": examples.CustomerCreated,
"customer.updated": examples.CustomerUpdated,
"customer.source.created": examples.CustomerSourceCreated,
"customer.source.updated": examples.CustomerSourceUpdated,
"charge.captured": examples.ChargeCaptured,
"charge.failed": examples.ChargeFailed,
"charge.succeeded": examples.ChargeSucceeded,
"customer.created": examples.CustomerCreated,
"customer.updated": examples.CustomerUpdated,
"customer.source.created": examples.CustomerSourceCreated,
"customer.source.updated": examples.CustomerSourceUpdated,
"customer.subscription.updated": examples.CustomerSubscriptionUpdated,
"invoice.created": examples.InvoiceCreated,
"invoice.finalized": examples.InvoiceFinalized,
"invoice.payment_succeeded": examples.InvoicePaymentSucceeded,
"invoice.updated": examples.InvoiceUpdated,
"payment_intent.created": examples.PaymentIntentCreated,
"invoice.created": examples.InvoiceCreated,
"invoice.finalized": examples.InvoiceFinalized,
"invoice.payment_succeeded": examples.InvoicePaymentSucceeded,
"invoice.updated": examples.InvoiceUpdated,
"payment_intent.created": examples.PaymentIntentCreated,
"payment_intent.payment_failed": examples.PaymentIntentFailed,
"payment_intent.succeeded": examples.PaymentIntentSucceeded,
"payment_method.attached": examples.PaymentMethodAttached,
"payment_intent.succeeded": examples.PaymentIntentSucceeded,
"payment_method.attached": examples.PaymentMethodAttached,
}
function, ok := supportedEvents[event]
if !ok {
Expand Down
5 changes: 3 additions & 2 deletions cmd/version.go → pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/validators"
"github.com/stripe/stripe-cli/version"

"github.com/stripe/stripe-cli/pkg/validators"
"github.com/stripe/stripe-cli/pkg/version"
)

type versionCmd struct {
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions login/client_login.go → pkg/login/client_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package login
import (
"encoding/json"
"fmt"
"github.com/stripe/stripe-cli/profile"
"github.com/stripe/stripe-cli/stripeauth"
"github.com/stripe/stripe-cli/validators"
"io/ioutil"
"net/http"
"net/url"
"os/exec"
"runtime"

"github.com/stripe/stripe-cli/pkg/profile"
"github.com/stripe/stripe-cli/pkg/stripeauth"
"github.com/stripe/stripe-cli/pkg/validators"
)

const stripeCLIAuthURL = "https://dashboard.stripe.com/stripecli/auth"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package login

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetLinks(t *testing.T) {
Expand Down
12 changes: 7 additions & 5 deletions login/interactive_login.go → pkg/login/interactive_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"bufio"
"errors"
"fmt"
"github.com/stripe/stripe-cli/ansi"
"github.com/stripe/stripe-cli/profile"
"github.com/stripe/stripe-cli/validators"
"golang.org/x/crypto/ssh/terminal"
"io"
"os"
"strings"
"syscall"

"golang.org/x/crypto/ssh/terminal"

"github.com/stripe/stripe-cli/pkg/ansi"
"github.com/stripe/stripe-cli/pkg/profile"
"github.com/stripe/stripe-cli/pkg/validators"
)

// InteractiveLogin lets the user set configuration on the command line
Expand Down Expand Up @@ -80,7 +82,7 @@ func redactAPIKey(apiKey string) string {
return b.String()
}

func securePrompt(input io.Reader) (string, error) {
func securePrompt(input io.Reader) (string, error) {
if input == os.Stdin {
buf, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package login

import (
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestAPIKeyInput(t *testing.T) {
Expand Down
Loading

0 comments on commit 9b25dbc

Please sign in to comment.