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

Small connect fixes for billing meters #1246

Merged
merged 2 commits into from
Sep 20, 2024
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
12 changes: 11 additions & 1 deletion pkg/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,22 @@ func (lc *listenCmd) createVisitor(logger *log.Logger, format string, printJSON
VisitData: func(de websocket.DataElement) error {
switch data := de.Data.(type) {
case proxy.V2EventPayload:
if strings.ToUpper(format) == outputFormatJSON || printJSON {
fmt.Println(de.Marshaled)
return nil
}

maybeConnect := ""
if data.IsConnect() {
maybeConnect = "connect "
}

localTime := time.Now().Format(timeLayout)

color := ansi.Color(os.Stdout)
outputStr := fmt.Sprintf("%s --> %s [%s]",
outputStr := fmt.Sprintf("%s --> %s%s [%s]",
color.Faint(localTime),
maybeConnect,
ansi.Bold(data.Type),
ansi.Linkify(data.ID, data.URLForEventID(lc.deviceToken), logger.Out),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@
"Authorization": "Bearer ${billing_meter_event_session:authentication_token}"
},
"params": {
"event_name": "${list_billing_meters_after_creation:data.0.event_name}",
"timestamp":"${time-now-RFC3339}",
"identifier": "${generate-uuid}",
"payload": {
"value":"1"
"events": [
{
"event_name": "${list_billing_meters_after_creation:data.0.event_name}",
"timestamp":"${time-now-RFC3339}",
"identifier": "${generate-uuid}",
"payload": {
"value":"1"
}
}
}
]
}
}
]
}
12 changes: 8 additions & 4 deletions pkg/fixtures/triggers/v1.billing.meter.no_meter_found.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
"Authorization": "Bearer ${billing_meter_event_session:authentication_token}"
},
"params": {
"event_name": "${generate-uuid}",
"timestamp":"${time-now-RFC3339}",
"payload": {
"value":"10"
"events": [
{
"event_name": "${generate-uuid}",
"timestamp":"${time-now-RFC3339}",
"payload": {
"value":"10"
}
}
]
}
}
]
Expand Down
5 changes: 5 additions & 0 deletions pkg/proxy/v2_stripe_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ type primaryRelatedObject struct {
func (e *V2EventPayload) URLForEventID(cliEndpointID string) string {
return fmt.Sprintf("https://dashboard.stripe.com/workbench/webhooks/%s?event=%s", cliEndpointID, e.ID)
}

// IsConnect returns true if this event is associated with a connected account
func (e *V2EventPayload) IsConnect() bool {
return e.Context != ""
}
Loading