-
Notifications
You must be signed in to change notification settings - Fork 2
Add top-level address-book and datastore CLI commands #683
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
Open
bytesizedroll
wants to merge
8
commits into
main
Choose a base branch
from
CLD-1098/ab-datastore-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
233a517
add top-level address-book CLI commands
bytesizedroll f818be9
add top-level datastore CLI commands
bytesizedroll 7d40135
Update engine/cld/legacy/cli/commands/addressbook.go
bytesizedroll a2b8c4d
Update engine/cld/legacy/cli/commands/addressbook.go
bytesizedroll 175d6fe
Update engine/cld/legacy/cli/commands/addressbook.go
bytesizedroll b9e5d99
panic on MarkFlagRequired errors for fail-fast behavior
bytesizedroll 569cc06
Merge branch 'CLD-1098/ab-datastore-cli' of https://github.com/smartc…
bytesizedroll d5c1678
Merge branch 'main' into CLD-1098/ab-datastore-cli
bytesizedroll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,179 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/domain" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/legacy/cli" | ||
| ) | ||
|
|
||
| // NewAddressBookCmds creates a new set of commands for address book operations. | ||
| func (c Commands) NewAddressBookCmds(domain domain.Domain) *cobra.Command { | ||
| addressBookCmd := &cobra.Command{ | ||
| Use: "address-book", | ||
| Short: "Address book operations", | ||
| } | ||
|
|
||
| addressBookCmd.AddCommand(c.newAddressBookMerge(domain)) | ||
| addressBookCmd.AddCommand(c.newAddressBookMigrate(domain)) | ||
| addressBookCmd.AddCommand(c.newAddressBookRemove(domain)) | ||
|
|
||
| addressBookCmd.PersistentFlags().StringP("environment", "e", "", "Deployment environment (required)") | ||
| if err := addressBookCmd.MarkPersistentFlagRequired("environment"); err != nil { | ||
| panic(fmt.Sprintf("failed to mark environment flag as required: %v", err)) | ||
| } | ||
|
|
||
| return addressBookCmd | ||
| } | ||
|
|
||
| var ( | ||
| addressBookMergeLong = cli.LongDesc(` | ||
| Merges the address book artifact of a specific changeset to the main address book within a | ||
| given Domain Environment. This is to ensure that the address book is up-to-date with the | ||
| latest changeset changes. | ||
| `) | ||
|
|
||
| addressBookMergeExample = cli.Examples(` | ||
| # Merge the address book for the 0001_deploy_cap changeset in the ccip staging domain environment | ||
| ccip address-book merge --environment staging --name 0001_deploy_cap | ||
|
|
||
| # Merge with a specific durable pipeline timestamp | ||
| ccip address-book merge --environment staging --name 0001_deploy_cap --timestamp 1234567890 | ||
| `) | ||
| ) | ||
|
|
||
| // newAddressBookMerge creates a command to merge the address books for a changeset to | ||
| // the main address book within a given domain environment. | ||
| func (Commands) newAddressBookMerge(domain domain.Domain) *cobra.Command { | ||
| var ( | ||
| name string | ||
| timestamp string | ||
| ) | ||
|
|
||
| cmd := cobra.Command{ | ||
| Use: "merge", | ||
| Short: "Merge the address book for a changeset to the main address book", | ||
| Long: addressBookMergeLong, | ||
| Example: addressBookMergeExample, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| envKey, _ := cmd.Flags().GetString("environment") | ||
| envDir := domain.EnvDir(envKey) | ||
|
|
||
| if err := envDir.MergeMigrationAddressBook(name, timestamp); err != nil { | ||
| return fmt.Errorf("error during address book merge for %s %s %s: %w", | ||
| domain, envKey, name, err, | ||
| ) | ||
| } | ||
|
|
||
| cmd.Printf("Merged address books for %s %s %s\n", | ||
| domain, envKey, name, | ||
| ) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVarP(&name, "name", "n", "", "name (required)") | ||
| cmd.Flags().StringVarP(×tamp, "timestamp", "t", "", "Durable Pipeline timestamp (optional)") | ||
| if err := cmd.MarkFlagRequired("name"); err != nil { | ||
| panic(fmt.Sprintf("failed to mark name flag as required: %v", err)) | ||
| } | ||
|
|
||
| return &cmd | ||
| } | ||
|
|
||
| var ( | ||
| addressBookMigrateLong = cli.LongDesc(` | ||
| Converts the address book artifact format to the new datastore schema within a | ||
| given Domain Environment. This updates your on-chain address book to the latest storage format. | ||
| `) | ||
|
|
||
| addressBookMigrateExample = cli.Examples(` | ||
| # Migrate the address book for the ccip staging domain to the new datastore format | ||
| ccip address-book migrate --environment staging | ||
| `) | ||
| ) | ||
|
|
||
| // newAddressBookMigrate creates a command to convert the address book | ||
| // artifact to the new datastore format within a given domain environment. | ||
| func (Commands) newAddressBookMigrate(domain domain.Domain) *cobra.Command { | ||
| cmd := cobra.Command{ | ||
| Use: "migrate", | ||
| Short: "Migrate address book to the new datastore format", | ||
| Long: addressBookMigrateLong, | ||
| Example: addressBookMigrateExample, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| envKey, _ := cmd.Flags().GetString("environment") | ||
| envDir := domain.EnvDir(envKey) | ||
|
|
||
| if err := envDir.MigrateAddressBook(); err != nil { | ||
| return fmt.Errorf("error during address book conversion for %s %s: %w", | ||
| domain, envKey, err, | ||
| ) | ||
| } | ||
|
|
||
| cmd.Printf("Address book for %s %s successfully migrated to the new datastore format\n", | ||
bytesizedroll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| domain, envKey, | ||
| ) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| return &cmd | ||
| } | ||
|
|
||
| var ( | ||
| addressBookRemoveLong = cli.LongDesc(` | ||
| Removes the address book entries introduced by a specific changeset from the main | ||
| address book within a given Domain Environment. This can be used to rollback | ||
| address-book merge changes. | ||
| `) | ||
|
|
||
| addressBookRemoveExample = cli.Examples(` | ||
| # Remove the address book entries for the 0001_deploy_cap changeset in the ccip staging domain | ||
| ccip address-book remove --environment staging --name 0001_deploy_cap | ||
| `) | ||
| ) | ||
|
|
||
| // newAddressBookRemove creates a command to remove a changeset's | ||
| // address book entries from the main address book within a given domain environment. | ||
| func (Commands) newAddressBookRemove(domain domain.Domain) *cobra.Command { | ||
| var ( | ||
| name string | ||
| timestamp string | ||
| ) | ||
|
|
||
| cmd := cobra.Command{ | ||
| Use: "remove", | ||
| Short: "Remove changeset address book entries", | ||
| Long: addressBookRemoveLong, | ||
| Example: addressBookRemoveExample, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| envKey, _ := cmd.Flags().GetString("environment") | ||
| envDir := domain.EnvDir(envKey) | ||
|
|
||
| if err := envDir.RemoveMigrationAddressBook(name, timestamp); err != nil { | ||
| return fmt.Errorf("error during address book remove for %s %s %s: %w", | ||
| domain, envKey, name, err, | ||
| ) | ||
| } | ||
|
|
||
| cmd.Printf("Removed address books for %s %s %s\n", | ||
| domain, envKey, name, | ||
| ) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVarP(&name, "name", "n", "", "name (required)") | ||
| cmd.Flags().StringVarP(×tamp, "timestamp", "t", "", "Durable Pipeline timestamp (optional)") | ||
| if err := cmd.MarkFlagRequired("name"); err != nil { | ||
| panic(fmt.Sprintf("failed to mark name flag as required: %v", err)) | ||
| } | ||
|
|
||
| return &cmd | ||
| } | ||
This file contains hidden or 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,117 @@ | ||||||||||||||||||
| package commands | ||||||||||||||||||
|
|
||||||||||||||||||
| import ( | ||||||||||||||||||
| "strings" | ||||||||||||||||||
| "testing" | ||||||||||||||||||
|
|
||||||||||||||||||
| "github.com/spf13/pflag" | ||||||||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||||||||
|
|
||||||||||||||||||
| "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/domain" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| func TestNewAddressBookCmds_Structure(t *testing.T) { | ||||||||||||||||||
| t.Parallel() | ||||||||||||||||||
| c := NewCommands(nil) | ||||||||||||||||||
| var dom domain.Domain | ||||||||||||||||||
| root := c.NewAddressBookCmds(dom) | ||||||||||||||||||
|
|
||||||||||||||||||
| require.Equal(t, "address-book", root.Use) | ||||||||||||||||||
|
|
||||||||||||||||||
| subs := root.Commands() | ||||||||||||||||||
| require.Len(t, subs, 3, "expected 3 subcommands under 'address-book'") | ||||||||||||||||||
|
|
||||||||||||||||||
| uses := make([]string, len(subs)) | ||||||||||||||||||
| for i, sc := range subs { | ||||||||||||||||||
| uses[i] = sc.Use | ||||||||||||||||||
| } | ||||||||||||||||||
| require.ElementsMatch(t, | ||||||||||||||||||
| []string{"merge", "migrate", "remove"}, | ||||||||||||||||||
| uses, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| // The "environment" flag is persistent on root | ||||||||||||||||||
| flag := root.PersistentFlags().Lookup("environment") | ||||||||||||||||||
| require.NotNil(t, flag, "persistent flag 'environment' should exist") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func TestAddressBookCommandMetadata(t *testing.T) { | ||||||||||||||||||
| t.Parallel() | ||||||||||||||||||
| c := NewCommands(nil) | ||||||||||||||||||
| dom := domain.Domain{} | ||||||||||||||||||
|
|
||||||||||||||||||
| tests := []struct { | ||||||||||||||||||
| name string | ||||||||||||||||||
| cmdKey string | ||||||||||||||||||
| wantUse string | ||||||||||||||||||
| wantShort string | ||||||||||||||||||
| wantLongPrefix string | ||||||||||||||||||
| wantExampleContains string | ||||||||||||||||||
| wantFlags []string | ||||||||||||||||||
| }{ | ||||||||||||||||||
| { | ||||||||||||||||||
| name: "merge", | ||||||||||||||||||
| cmdKey: "merge", | ||||||||||||||||||
| wantUse: "merge", | ||||||||||||||||||
| wantShort: "Merge the address book", | ||||||||||||||||||
| wantLongPrefix: "Merges the address book artifact", | ||||||||||||||||||
| wantExampleContains: "address-book merge --environment staging --name", | ||||||||||||||||||
| wantFlags: []string{ | ||||||||||||||||||
| "name", "timestamp", | ||||||||||||||||||
| }, | ||||||||||||||||||
| }, | ||||||||||||||||||
| { | ||||||||||||||||||
| name: "migrate", | ||||||||||||||||||
| cmdKey: "migrate", | ||||||||||||||||||
| wantUse: "migrate", | ||||||||||||||||||
| wantShort: "Migrate address book to the new datastore format", | ||||||||||||||||||
| wantLongPrefix: "Converts the address book artifact format", | ||||||||||||||||||
| wantExampleContains: "address-book migrate --environment staging", | ||||||||||||||||||
| wantFlags: []string{}, | ||||||||||||||||||
| }, | ||||||||||||||||||
| { | ||||||||||||||||||
| name: "remove", | ||||||||||||||||||
| cmdKey: "remove", | ||||||||||||||||||
| wantUse: "remove", | ||||||||||||||||||
| wantShort: "Remove changeset address book entries", | ||||||||||||||||||
| wantLongPrefix: "Removes the address book entries", | ||||||||||||||||||
| wantExampleContains: "address-book remove --environment staging --name", | ||||||||||||||||||
| wantFlags: []string{ | ||||||||||||||||||
| "name", "timestamp", | ||||||||||||||||||
| }, | ||||||||||||||||||
| }, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| for _, tc := range tests { | ||||||||||||||||||
| t.Run(tc.name, func(t *testing.T) { | ||||||||||||||||||
| // Give each subtest its own fresh command tree | ||||||||||||||||||
| root := c.NewAddressBookCmds(dom) | ||||||||||||||||||
|
|
||||||||||||||||||
| t.Parallel() | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+87
to
+91
|
||||||||||||||||||
| // Give each subtest its own fresh command tree | |
| root := c.NewAddressBookCmds(dom) | |
| t.Parallel() | |
| t.Parallel() | |
| // Give each subtest its own fresh command tree | |
| root := c.NewAddressBookCmds(dom) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.