Skip to content

Commit

Permalink
Merge branch 'master' into tomas/release-websocket-client-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-stripe committed Sep 17, 2024
2 parents 9003e3e + 6c259f0 commit 581a9f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
13 changes: 7 additions & 6 deletions pkg/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type listenCmd struct {
apiBaseURL string
noWSS bool
timeout int64
deviceToken string
}

func newListenCmd() *listenCmd {
Expand Down Expand Up @@ -158,12 +159,13 @@ func (lc *listenCmd) runListenCmd(cmd *cobra.Command, args []string) error {
}

logger := log.StandardLogger()
proxyVisitor := createVisitor(logger, lc.format, lc.printJSON)
proxyVisitor := lc.createVisitor(logger, lc.format, lc.printJSON)
proxyOutCh := make(chan websocket.IElement)

p, err := proxy.Init(ctx, &proxy.Config{
Client: client,
DeviceName: deviceName,
DeviceToken: &lc.deviceToken,
ForwardURL: lc.forwardURL,
ForwardThinURL: lc.forwardThinURL,
ForwardHeaders: lc.forwardHeaders,
Expand Down Expand Up @@ -213,7 +215,7 @@ func withSIGTERMCancel(ctx context.Context, onCancel func()) context.Context {
return ctx
}

func createVisitor(logger *log.Logger, format string, printJSON bool) *websocket.Visitor {
func (lc *listenCmd) createVisitor(logger *log.Logger, format string, printJSON bool) *websocket.Visitor {
var s *spinner.Spinner

return &websocket.Visitor{
Expand Down Expand Up @@ -273,8 +275,8 @@ func createVisitor(logger *log.Logger, format string, printJSON bool) *websocket
color := ansi.Color(os.Stdout)
outputStr := fmt.Sprintf("%s --> %s [%s]",
color.Faint(localTime),
ansi.Linkify(ansi.Bold(data.Type), data.URLForEventType(), logger.Out),
ansi.Linkify(data.ID, data.URLForEventID(), logger.Out),
ansi.Bold(data.Type),
ansi.Linkify(data.ID, data.URLForEventID(lc.deviceToken), logger.Out),
)
fmt.Println(outputStr)
return nil
Expand Down Expand Up @@ -307,8 +309,7 @@ func createVisitor(logger *log.Logger, format string, printJSON bool) *websocket
if event != nil {
link = ansi.Linkify(event.ID, event.URLForEventID(), logger.Out)
} else if v2Event != nil {
// todo(@charliecruzan): Add link support once inspector supports v2 events
link = v2Event.ID
link = ansi.Linkify(v2Event.ID, v2Event.URLForEventID(lc.deviceToken), logger.Out)
}
localTime := time.Now().Format(timeLayout)

Expand Down
5 changes: 3 additions & 2 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func (f FailedToReadResponseError) Error() string {
// Config provides the configuration of a Proxy
type Config struct {
// DeviceName is the name of the device sent to Stripe to help identify the device
DeviceName string
DeviceName string
DeviceToken *string

// Client is a configured stripe client used to execute authenticated calls to the Stripe API.
Client stripe.RequestPerformer
Expand Down Expand Up @@ -156,7 +157,7 @@ func (p *Proxy) Run(ctx context.Context) error {

for nAttempts < maxConnectAttempts {
session, err := p.createSession(ctx)

*p.cfg.DeviceToken = session.DeviceToken
if err != nil {
p.cfg.OutCh <- websocket.ErrorElement{
Error: fmt.Errorf("Error while authenticating with Stripe: %v", err),
Expand Down
9 changes: 2 additions & 7 deletions pkg/proxy/v2_stripe_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ type primaryRelatedObject struct {
}

// URLForEventID builds a full URL from a V2StripeEvent ID.
func (e *V2EventPayload) URLForEventID() string {
return fmt.Sprintf("https://dashboard.stripe.com/events/%s", e.ID)
}

// URLForEventType builds a full URL from a V2StripeEvent Type.
func (e *V2EventPayload) URLForEventType() string {
return fmt.Sprintf("https://dashboard.stripe.com/events?type=%s", e.Type)
func (e *V2EventPayload) URLForEventID(cliEndpointID string) string {
return fmt.Sprintf("https://dashboard.stripe.com/workbench/webhooks/%s?event=%s", cliEndpointID, e.ID)
}
1 change: 1 addition & 0 deletions pkg/stripeauth/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type StripeCLISession struct {
WebSocketURL string `json:"websocket_url"`
DefaultVersion string `json:"default_version"`
LatestVersion string `json:"latest_version"`
DeviceToken string `json:"device_token"`
}

0 comments on commit 581a9f9

Please sign in to comment.