Skip to content

Commit f1182d0

Browse files
committed
chore: clean stack v1 support
1 parent c1d85d5 commit f1182d0

File tree

21 files changed

+183
-421
lines changed

21 files changed

+183
-421
lines changed

cmd/orchestration/instances/describe.go

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
type InstancesDescribeStore struct {
19-
WorkflowInstancesHistory []shared.WorkflowInstanceHistory `json:"workflowInstanceHistory"`
19+
WorkflowInstancesHistory []shared.V2WorkflowInstanceHistory `json:"workflowInstanceHistory"`
2020
}
2121
type InstancesDescribeController struct {
2222
store *InstancesDescribeStore
@@ -51,14 +51,14 @@ func (c *InstancesDescribeController) GetStore() *InstancesDescribeStore {
5151
func (c *InstancesDescribeController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
5252
store := fctl.GetStackStore(cmd.Context())
5353

54-
response, err := store.Client().Orchestration.V1.GetInstanceHistory(cmd.Context(), operations.GetInstanceHistoryRequest{
54+
response, err := store.Client().Orchestration.V2.GetInstanceHistory(cmd.Context(), operations.V2GetInstanceHistoryRequest{
5555
InstanceID: args[0],
5656
})
5757
if err != nil {
5858
return nil, err
5959
}
6060

61-
c.store.WorkflowInstancesHistory = response.GetWorkflowInstanceHistoryResponse.Data
61+
c.store.WorkflowInstancesHistory = response.V2GetWorkflowInstanceHistoryResponse.Data
6262

6363
return c, nil
6464
}
@@ -74,15 +74,15 @@ func (c *InstancesDescribeController) Render(cmd *cobra.Command, args []string)
7474
return nil
7575
}
7676

77-
func printHistoryBaseInfo(out io.Writer, name string, ind int, history shared.WorkflowInstanceHistory) {
77+
func printHistoryBaseInfo(out io.Writer, name string, ind int, history shared.V2WorkflowInstanceHistory) {
7878
fctl.Section.WithWriter(out).Printf("Stage %d : %s\n", ind, name)
7979
fctl.BasicText.WithWriter(out).Printfln("Started at: %s", history.StartedAt.Format(time.RFC3339))
8080
if history.Terminated {
81-
fctl.BasicText.WithWriter(out).Printfln("Terminated at: %s", history.StartedAt.Format(time.RFC3339))
81+
fctl.BasicText.WithWriter(out).Printfln("Terminated at: %s", history.TerminatedAt.Format(time.RFC3339))
8282
}
8383
}
8484

85-
func stageSourceName(src *shared.StageSendSource) string {
85+
func stageSourceName(src *shared.V2StageSendSource) string {
8686
switch {
8787
case src.Wallet != nil:
8888
return fmt.Sprintf("wallet '%s' (balance: %s)", src.Wallet.ID, *src.Wallet.Balance)
@@ -95,7 +95,7 @@ func stageSourceName(src *shared.StageSendSource) string {
9595
}
9696
}
9797

98-
func stageDestinationName(dst *shared.StageSendDestination) string {
98+
func stageDestinationName(dst *shared.V2StageSendDestination) string {
9999
switch {
100100
case dst.Wallet != nil:
101101
return fmt.Sprintf("wallet '%s' (balance: %s)", dst.Wallet.ID, *dst.Wallet.Balance)
@@ -108,12 +108,12 @@ func stageDestinationName(dst *shared.StageSendDestination) string {
108108
}
109109
}
110110

111-
func subjectName(src shared.Subject) string {
111+
func subjectName(src shared.V2Subject) string {
112112
switch {
113-
case src.WalletSubject != nil:
114-
return fmt.Sprintf("wallet %s (balance: %s)", src.WalletSubject.Identifier, *src.WalletSubject.Balance)
115-
case src.LedgerAccountSubject != nil:
116-
return fmt.Sprintf("account %s", src.LedgerAccountSubject.Identifier)
113+
case src.V2WalletSubject != nil:
114+
return fmt.Sprintf("wallet %s (balance: %s)", src.V2WalletSubject.Identifier, *src.V2WalletSubject.Balance)
115+
case src.V2LedgerAccountSubject != nil:
116+
return fmt.Sprintf("account %s", src.V2LedgerAccountSubject.Identifier)
117117
default:
118118
return "unknown_subject_type"
119119
}
@@ -131,29 +131,31 @@ func printMetadata(metadata map[string]string) []pterm.BulletListItem {
131131
return ret
132132
}
133133

134-
func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, history shared.WorkflowInstanceHistory) error {
134+
func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string, history shared.V2WorkflowInstanceHistory) error {
135135
cyanWriter := fctl.BasicTextCyan
136136
defaultWriter := fctl.BasicText
137137

138138
listItems := make([]pterm.BulletListItem, 0)
139139

140140
switch history.Input.Type {
141-
case shared.StageTypeStageSend:
141+
case shared.V2StageTypeV2StageSend:
142142
printHistoryBaseInfo(cmd.OutOrStdout(), "send", i, history)
143-
cyanWriter.Printfln("Send %v %s from %s to %s", history.Input.StageSend.Amount.Amount,
144-
history.Input.StageSend.Amount.Asset, stageSourceName(history.Input.StageSend.Source),
145-
stageDestinationName(history.Input.StageSend.Destination))
143+
if history.Input.V2StageSend != nil {
144+
cyanWriter.Printfln("Send %v %s from %s to %s", history.Input.V2StageSend.Amount.Amount,
145+
history.Input.V2StageSend.Amount.Asset, stageSourceName(history.Input.V2StageSend.Source),
146+
stageDestinationName(history.Input.V2StageSend.Destination))
147+
}
146148
fctl.Println()
147149

148-
stageResponse, err := client.Orchestration.V1.GetInstanceStageHistory(cmd.Context(), operations.GetInstanceStageHistoryRequest{
150+
stageResponse, err := client.Orchestration.V2.GetInstanceStageHistory(cmd.Context(), operations.V2GetInstanceStageHistoryRequest{
149151
InstanceID: id,
150152
Number: int64(i),
151153
})
152154
if err != nil {
153155
return err
154156
}
155157

156-
for _, historyStage := range stageResponse.GetWorkflowInstanceHistoryStageResponse.Data {
158+
for _, historyStage := range stageResponse.V2GetWorkflowInstanceHistoryStageResponse.Data {
157159
switch {
158160
case historyStage.Input.StripeTransfer != nil:
159161
listItems = append(listItems, historyItemTitle("Send %v %s to Stripe connected account: %s",
@@ -162,19 +164,26 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
162164
*historyStage.Input.StripeTransfer.Destination,
163165
))
164166
case historyStage.Input.CreateTransaction != nil:
165-
listItems = append(listItems, historyItemTitle("Send %v %s from account %s to account %s (ledger %s)",
166-
historyStage.Input.CreateTransaction.Data.Postings[0].Amount,
167-
historyStage.Input.CreateTransaction.Data.Postings[0].Asset,
168-
historyStage.Input.CreateTransaction.Data.Postings[0].Source,
169-
historyStage.Input.CreateTransaction.Data.Postings[0].Destination,
170-
*historyStage.Input.CreateTransaction.Ledger,
171-
))
167+
if historyStage.Input.CreateTransaction.Data != nil && len(historyStage.Input.CreateTransaction.Data.Postings) > 0 {
168+
listItems = append(listItems, historyItemTitle("Send %v %s from account %s to account %s (ledger %s)",
169+
historyStage.Input.CreateTransaction.Data.Postings[0].Amount,
170+
historyStage.Input.CreateTransaction.Data.Postings[0].Asset,
171+
historyStage.Input.CreateTransaction.Data.Postings[0].Source,
172+
historyStage.Input.CreateTransaction.Data.Postings[0].Destination,
173+
*historyStage.Input.CreateTransaction.Ledger,
174+
))
175+
}
172176
if historyStage.Error == nil && historyStage.LastFailure == nil && historyStage.Terminated {
173-
listItems = append(listItems, historyItemDetails("Created transaction: %d", historyStage.Output.CreateTransaction.Data.ID))
174-
if historyStage.Input.CreateTransaction.Data.Reference != nil {
175-
listItems = append(listItems, historyItemDetails("Reference: %s", *historyStage.Output.CreateTransaction.Data.Reference))
177+
if historyStage.Output.CreateTransaction != nil && len(historyStage.Output.CreateTransaction.Data) > 0 {
178+
txid := historyStage.Output.CreateTransaction.Data[0].Txid
179+
if txid != nil {
180+
listItems = append(listItems, historyItemDetails("Created transaction: %d", txid.Int64()))
181+
}
176182
}
177-
if len(historyStage.Input.CreateTransaction.Data.Metadata) > 0 {
183+
if historyStage.Input.CreateTransaction != nil && historyStage.Input.CreateTransaction.Data != nil && historyStage.Input.CreateTransaction.Data.Reference != nil {
184+
listItems = append(listItems, historyItemDetails("Reference: %s", *historyStage.Input.CreateTransaction.Data.Reference))
185+
}
186+
if historyStage.Input.CreateTransaction != nil && historyStage.Input.CreateTransaction.Data != nil && len(historyStage.Input.CreateTransaction.Data.Metadata) > 0 {
178187
listItems = append(listItems, printMetadata(historyStage.Input.CreateTransaction.Data.Metadata)...)
179188
}
180189
}
@@ -221,11 +230,7 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
221230
historyStage.Input.GetPayment.ID))
222231
case historyStage.Input.GetWallet != nil:
223232
listItems = append(listItems, historyItemTitle("Read wallet '%s'", historyStage.Input.GetWallet.ID))
224-
case historyStage.Input.RevertTransaction != nil:
225-
listItems = append(listItems, historyItemTitle("Revert transaction %s", historyStage.Input.RevertTransaction.ID))
226-
if historyStage.Error == nil {
227-
listItems = append(listItems, historyItemTitle("Created transaction: %d", historyStage.Output.RevertTransaction.Data.ID))
228-
}
233+
// V2 doesn't have RevertTransaction, skip it
229234
case historyStage.Input.VoidHold != nil:
230235
listItems = append(listItems, historyItemTitle("Cancel debit hold %s", historyStage.Input.VoidHold.ID))
231236
case historyStage.Input.ListWallets != nil:
@@ -242,31 +247,37 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
242247
listItems = append(listItems, historyItemError(*historyStage.Error))
243248
}
244249
}
245-
case shared.StageTypeStageDelay:
250+
case shared.V2StageTypeV2StageDelay:
246251
printHistoryBaseInfo(cmd.OutOrStdout(), "delay", i, history)
247-
switch {
248-
case history.Input.StageDelay.Duration != nil:
249-
listItems = append(listItems, historyItemTitle("Pause workflow for a delay of %s", *history.Input.StageDelay.Duration))
250-
case history.Input.StageDelay.Until != nil:
251-
listItems = append(listItems, historyItemTitle("Pause workflow until %s", *history.Input.StageDelay.Until))
252+
if history.Input.V2StageDelay != nil {
253+
switch {
254+
case history.Input.V2StageDelay.Duration != nil:
255+
listItems = append(listItems, historyItemTitle("Pause workflow for a delay of %s", *history.Input.V2StageDelay.Duration))
256+
case history.Input.V2StageDelay.Until != nil:
257+
listItems = append(listItems, historyItemTitle("Pause workflow until %s", *history.Input.V2StageDelay.Until))
258+
}
252259
}
253-
case shared.StageTypeStageWaitEvent:
260+
case shared.V2StageTypeV2StageWaitEvent:
254261
printHistoryBaseInfo(cmd.OutOrStdout(), "wait_event", i, history)
255-
listItems = append(listItems, historyItemTitle("Waiting event '%s'", history.Input.StageWaitEvent.Event))
262+
if history.Input.V2StageWaitEvent != nil {
263+
listItems = append(listItems, historyItemTitle("Waiting event '%s'", history.Input.V2StageWaitEvent.Event))
264+
}
256265
if history.Error == nil {
257266
if history.Terminated {
258267
listItems = append(listItems, historyItemDetails("Event received!"))
259268
} else {
260269
listItems = append(listItems, historyItemDetails("Still waiting event..."))
261270
}
262271
}
263-
case shared.StageTypeUpdate:
272+
case shared.V2StageTypeV2Update:
264273
printHistoryBaseInfo(cmd.OutOrStdout(), "update", i, history)
265-
switch {
266-
case history.Input.Update.Account != nil:
267-
account := history.Input.Update.Account
268-
listItems = append(listItems, historyItemTitle("Update account '%s' of ledger '%s'", account.ID, account.Ledger))
269-
listItems = append(listItems, printMetadata(account.Metadata)...)
274+
if history.Input.V2Update != nil {
275+
switch {
276+
case history.Input.V2Update.Account != nil:
277+
account := history.Input.V2Update.Account
278+
listItems = append(listItems, historyItemTitle("Update account '%s' of ledger '%s'", account.ID, account.Ledger))
279+
listItems = append(listItems, printMetadata(account.Metadata)...)
280+
}
270281
}
271282
default:
272283
// Display error?

cmd/orchestration/instances/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ func (c *InstancesListController) GetStore() *InstancesListStore {
6464
func (c *InstancesListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
6565
store := fctl.GetStackStore(cmd.Context())
6666

67-
response, err := store.Client().Orchestration.V1.ListInstances(cmd.Context(), operations.ListInstancesRequest{
67+
response, err := store.Client().Orchestration.V2.ListInstances(cmd.Context(), operations.V2ListInstancesRequest{
6868
Running: fctl.Ptr(fctl.GetBool(cmd, c.runningFlag)),
6969
WorkflowID: fctl.Ptr(fctl.GetString(cmd, c.workflowFlag)),
7070
})
7171
if err != nil {
7272
return nil, err
7373
}
7474

75-
c.store.WorkflowInstance = fctl.Map(response.ListRunsResponse.Data, func(src shared.WorkflowInstance) WorkflowInstance {
75+
c.store.WorkflowInstance = fctl.Map(response.V2ListRunsResponse.Cursor.Data, func(src shared.V2WorkflowInstance) WorkflowInstance {
7676
return WorkflowInstance{
7777
InstanceID: src.ID,
7878
WorkflowID: src.WorkflowID,

cmd/orchestration/instances/send_event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (c *InstancesSendEventController) GetStore() *InstancesSendEventStore {
4949

5050
func (c *InstancesSendEventController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
5151
store := fctl.GetStackStore(cmd.Context())
52-
_, err := store.Client().Orchestration.V1.SendEvent(cmd.Context(), operations.SendEventRequest{
53-
RequestBody: &operations.SendEventRequestBody{
52+
_, err := store.Client().Orchestration.V2.SendEvent(cmd.Context(), operations.V2SendEventRequest{
53+
RequestBody: &operations.V2SendEventRequestBody{
5454
Name: args[1],
5555
},
5656
InstanceID: args[0],

cmd/orchestration/instances/show.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
)
1616

1717
type InstancesShowStore struct {
18-
WorkflowInstance shared.WorkflowInstance `json:"workflowInstance"`
19-
Workflow shared.Workflow `json:"workflow"`
18+
WorkflowInstance shared.V2WorkflowInstance `json:"workflowInstance"`
19+
Workflow shared.Workflow `json:"workflow"`
2020
}
2121
type InstancesShowController struct {
2222
store *InstancesShowStore
@@ -50,22 +50,29 @@ func (c *InstancesShowController) GetStore() *InstancesShowStore {
5050
func (c *InstancesShowController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
5151
store := fctl.GetStackStore(cmd.Context())
5252

53-
res, err := store.Client().Orchestration.V1.GetInstance(cmd.Context(), operations.GetInstanceRequest{
53+
res, err := store.Client().Orchestration.V2.GetInstance(cmd.Context(), operations.V2GetInstanceRequest{
5454
InstanceID: args[0],
5555
})
5656
if err != nil {
5757
return nil, errors.Wrap(err, "reading instance")
5858
}
5959

60-
c.store.WorkflowInstance = res.GetWorkflowInstanceResponse.Data
61-
response, err := store.Client().Orchestration.V1.GetWorkflow(cmd.Context(), operations.GetWorkflowRequest{
62-
FlowID: res.GetWorkflowInstanceResponse.Data.WorkflowID,
60+
c.store.WorkflowInstance = res.V2GetWorkflowInstanceResponse.Data
61+
response, err := store.Client().Orchestration.V2.GetWorkflow(cmd.Context(), operations.V2GetWorkflowRequest{
62+
FlowID: res.V2GetWorkflowInstanceResponse.Data.WorkflowID,
6363
})
6464
if err != nil {
6565
return nil, err
6666
}
6767

68-
c.store.Workflow = response.GetWorkflowResponse.Data
68+
// Convert V2Workflow to Workflow
69+
v2Workflow := response.V2GetWorkflowResponse.Data
70+
c.store.Workflow = shared.Workflow{
71+
ID: v2Workflow.ID,
72+
CreatedAt: v2Workflow.CreatedAt,
73+
UpdatedAt: v2Workflow.UpdatedAt,
74+
Config: shared.WorkflowConfig(v2Workflow.Config),
75+
}
6976

7077
return c, nil
7178
}
@@ -91,7 +98,25 @@ func (c *InstancesShowController) Render(cmd *cobra.Command, args []string) erro
9198
return err
9299
}
93100

94-
if err := internal.PrintWorkflowInstance(cmd.OutOrStdout(), c.store.Workflow, c.store.WorkflowInstance); err != nil {
101+
// Convert V2WorkflowInstance to WorkflowInstance
102+
v2Instance := c.store.WorkflowInstance
103+
instance := shared.WorkflowInstance{
104+
ID: v2Instance.ID,
105+
WorkflowID: v2Instance.WorkflowID,
106+
CreatedAt: v2Instance.CreatedAt,
107+
UpdatedAt: v2Instance.UpdatedAt,
108+
Terminated: v2Instance.Terminated,
109+
TerminatedAt: v2Instance.TerminatedAt,
110+
Error: v2Instance.Error,
111+
Status: fctl.Map(v2Instance.Status, func(src shared.V2StageStatus) shared.StageStatus {
112+
return shared.StageStatus{
113+
StartedAt: src.StartedAt,
114+
TerminatedAt: src.TerminatedAt,
115+
Error: src.Error,
116+
}
117+
}),
118+
}
119+
if err := internal.PrintWorkflowInstance(cmd.OutOrStdout(), c.store.Workflow, instance); err != nil {
95120
return err
96121
}
97122

cmd/orchestration/instances/stop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (c *InstancesStopController) GetStore() *InstancesStopStore {
4545
func (c *InstancesStopController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
4646
store := fctl.GetStackStore(cmd.Context())
4747

48-
_, err := store.Client().Orchestration.V1.CancelEvent(cmd.Context(), operations.CancelEventRequest{
48+
_, err := store.Client().Orchestration.V2.CancelEvent(cmd.Context(), operations.V2CancelEventRequest{
4949
InstanceID: args[0],
5050
})
5151
if err != nil {

cmd/orchestration/triggers/create.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (c *TriggersCreateController) Run(cmd *cobra.Command, args []string) (fctl.
6666
workflow = args[1]
6767
)
6868

69-
data := &shared.TriggerData{
69+
data := &shared.V2TriggerData{
7070
Event: event,
7171
Name: &name,
7272
WorkflowID: workflow,
@@ -85,12 +85,22 @@ func (c *TriggersCreateController) Run(cmd *cobra.Command, args []string) (fctl.
8585
}
8686
}
8787

88-
res, err := store.Client().Orchestration.V1.CreateTrigger(cmd.Context(), data)
88+
res, err := store.Client().Orchestration.V2.CreateTrigger(cmd.Context(), data)
8989
if err != nil {
9090
return nil, errors.Wrap(err, "reading trigger")
9191
}
9292

93-
c.store.Trigger = res.CreateTriggerResponse.Data
93+
// Convert V2Trigger to Trigger
94+
v2Trigger := res.V2CreateTriggerResponse.Data
95+
c.store.Trigger = shared.Trigger{
96+
ID: v2Trigger.ID,
97+
Name: v2Trigger.Name,
98+
WorkflowID: v2Trigger.WorkflowID,
99+
Event: v2Trigger.Event,
100+
Filter: v2Trigger.Filter,
101+
Vars: v2Trigger.Vars,
102+
CreatedAt: v2Trigger.CreatedAt,
103+
}
94104

95105
return c, nil
96106
}

cmd/orchestration/triggers/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (c *TriggersDeleteController) GetStore() *TriggersDeleteStore {
4545

4646
func (c *TriggersDeleteController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
4747
store := fctl.GetStackStore(cmd.Context())
48-
_, err := store.Client().Orchestration.V1.DeleteTrigger(cmd.Context(), operations.DeleteTriggerRequest{
48+
_, err := store.Client().Orchestration.V2.DeleteTrigger(cmd.Context(), operations.V2DeleteTriggerRequest{
4949
TriggerID: args[0],
5050
})
5151
if err != nil {

cmd/orchestration/triggers/list.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,27 @@ func (c *TriggersListController) GetStore() *TriggersListStore {
5252
func (c *TriggersListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
5353
store := fctl.GetStackStore(cmd.Context())
5454
var name = fctl.GetString(cmd, c.nameFlag)
55-
response, err := store.Client().Orchestration.V1.ListTriggers(cmd.Context(), operations.ListTriggersRequest{
55+
response, err := store.Client().Orchestration.V2.ListTriggers(cmd.Context(), operations.V2ListTriggersRequest{
5656
Name: &name,
5757
})
5858

5959
if err != nil {
6060
return nil, err
6161
}
6262

63-
c.store.WorkflowTrigger = response.ListTriggersResponse.Data
63+
// Convert V2Trigger to Trigger
64+
v2Triggers := response.V2ListTriggersResponse.Cursor.Data
65+
c.store.WorkflowTrigger = fctl.Map(v2Triggers, func(v2Trigger shared.V2Trigger) shared.Trigger {
66+
return shared.Trigger{
67+
ID: v2Trigger.ID,
68+
Name: v2Trigger.Name,
69+
WorkflowID: v2Trigger.WorkflowID,
70+
Event: v2Trigger.Event,
71+
Filter: v2Trigger.Filter,
72+
Vars: v2Trigger.Vars,
73+
CreatedAt: v2Trigger.CreatedAt,
74+
}
75+
})
6476

6577
return c, nil
6678
}

0 commit comments

Comments
 (0)