-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
291 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package accounts | ||
|
||
import ( | ||
"github.com/formancehq/fctl/cmd/ledger/internal" | ||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/operations" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DeleteMetadataStore struct { | ||
Success bool `json:"success"` | ||
} | ||
type DeleteMetadataController struct { | ||
store *DeleteMetadataStore | ||
} | ||
|
||
var _ fctl.Controller[*DeleteMetadataStore] = (*DeleteMetadataController)(nil) | ||
|
||
func NewDefaultDeleteMetadataStore() *DeleteMetadataStore { | ||
return &DeleteMetadataStore{} | ||
} | ||
|
||
func NewDeleteMetadataController() *DeleteMetadataController { | ||
return &DeleteMetadataController{ | ||
store: NewDefaultDeleteMetadataStore(), | ||
} | ||
} | ||
|
||
func NewDeleteMetadataCommand() *cobra.Command { | ||
return fctl.NewCommand("delete-metadata <address> [<key>...]", | ||
fctl.WithShortDescription("Delete metadata on account"), | ||
fctl.WithAliases("dm", "del-meta"), | ||
fctl.WithConfirmFlag(), | ||
fctl.WithArgs(cobra.MinimumNArgs(2)), | ||
fctl.WithController[*DeleteMetadataStore](NewDeleteMetadataController()), | ||
) | ||
} | ||
|
||
func (c *DeleteMetadataController) GetStore() *DeleteMetadataStore { | ||
return c.store | ||
} | ||
|
||
func (c *DeleteMetadataController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
|
||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stack, err := fctl.ResolveStack(cmd, cfg, organizationID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ledgerClient, err := fctl.NewStackClient(cmd, cfg, stack) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !fctl.CheckStackApprobation(cmd, stack, "You are about to set a metadata on account %s", args[0]) { | ||
return nil, fctl.ErrMissingApproval | ||
} | ||
|
||
response, err := ledgerClient.Ledger.DeleteAccountMetadata(cmd.Context(), operations.DeleteAccountMetadataRequest{ | ||
Address: args[0], | ||
Key: args[1], | ||
Ledger: fctl.GetString(cmd, internal.LedgerFlag), | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.store.Success = (response.StatusCode % 200) < 100 | ||
return c, nil | ||
} | ||
|
||
func (c *DeleteMetadataController) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Metadata deleted!") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
components/fctl/cmd/ledger/transactions/delete_metadata.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package transactions | ||
|
||
import ( | ||
"github.com/formancehq/fctl/cmd/ledger/internal" | ||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/operations" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DeleteMetadataStore struct { | ||
Success bool `json:"success"` | ||
} | ||
type DeleteMetadataController struct { | ||
store *DeleteMetadataStore | ||
} | ||
|
||
var _ fctl.Controller[*DeleteMetadataStore] = (*DeleteMetadataController)(nil) | ||
|
||
func NewDefaultDeleteMetadataStore() *DeleteMetadataStore { | ||
return &DeleteMetadataStore{} | ||
} | ||
|
||
func NewDeleteMetadataController() *DeleteMetadataController { | ||
return &DeleteMetadataController{ | ||
store: NewDefaultDeleteMetadataStore(), | ||
} | ||
} | ||
|
||
func NewDeleteMetadataCommand() *cobra.Command { | ||
return fctl.NewCommand("delete-metadata <transaction-id> [<key>...]", | ||
fctl.WithShortDescription("Delete metadata on transaction"), | ||
fctl.WithAliases("dm", "del-meta"), | ||
fctl.WithConfirmFlag(), | ||
fctl.WithValidArgs("last"), | ||
fctl.WithArgs(cobra.MinimumNArgs(2)), | ||
fctl.WithController[*DeleteMetadataStore](NewDeleteMetadataController()), | ||
) | ||
} | ||
|
||
func (c *DeleteMetadataController) GetStore() *DeleteMetadataStore { | ||
return c.store | ||
} | ||
|
||
func (c *DeleteMetadataController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
|
||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stack, err := fctl.ResolveStack(cmd, cfg, organizationID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ledgerClient, err := fctl.NewStackClient(cmd, cfg, stack) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
transactionID, err := internal.TransactionIDOrLastN(cmd.Context(), ledgerClient, | ||
fctl.GetString(cmd, internal.LedgerFlag), args[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !fctl.CheckStackApprobation(cmd, stack, "You are about to set a metadata on transaction %d", transactionID) { | ||
return nil, fctl.ErrMissingApproval | ||
} | ||
|
||
response, err := ledgerClient.Ledger.DeleteTransactionMetadata(cmd.Context(), operations.DeleteTransactionMetadataRequest{ | ||
ID: transactionID, | ||
Key: args[1], | ||
Ledger: fctl.GetString(cmd, internal.LedgerFlag), | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.store.Success = (response.StatusCode % 200) < 100 | ||
return c, nil | ||
} | ||
|
||
func (c *DeleteMetadataController) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Metadata deleted!") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
29571f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./
docs-formance.vercel.app
docs.formance.com
developers.numary.com
docs-git-main-formance.vercel.app
docs.numary.com
developers.formance.com