-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feature: Implement --save option in 'ipfs swarm peering add/rm' #9192
Conversation
Thank you for submitting this PR!
Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution. |
All tests pass for me locally except for generated completions defines '_ipfs'. It fails with this error output:
I suspect, based on this thread on the Homebrew mailing list, that this is because I have Bash 3 installed on my Mac.
I'll be interested to see if the test passes in CI when someone comes around who is authorized to run them. Marking this as open for review now in hopes that this is just a me issue. |
9bd1404
to
9bc188c
Compare
core/commands/swarm.go
Outdated
if save { | ||
r, err := fsrepo.Open(env.(*commands.Context).ConfigRoot) | ||
if err != nil { | ||
return err |
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.
Could you wrap this with a descriptive error?
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.
Updated in this commit.
core/commands/swarm.go
Outdated
defer r.Close() | ||
cfg, err := r.Config() | ||
if err != nil { | ||
return err |
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.
Could you wrap this with a descriptive error?
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.
Updated in this commit.
core/commands/swarm.go
Outdated
defer r.Close() | ||
cfg, err := r.Config() | ||
if err != nil { | ||
return err |
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.
Could you wrap this with a descriptive error?
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.
Updated in this commit.
core/commands/swarm.go
Outdated
if save { | ||
r, err := fsrepo.Open(env.(*commands.Context).ConfigRoot) | ||
if err != nil { | ||
return err |
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.
Could you wrap this with a descriptive error?
core/commands/swarm.go
Outdated
save, _ := req.Options[swarmSaveOptionName].(bool) | ||
if save { | ||
r, err := fsrepo.Open(env.(*commands.Context).ConfigRoot) | ||
if err != nil { | ||
return err | ||
} | ||
defer r.Close() | ||
cfg, err := r.Config() | ||
if err != nil { | ||
return err | ||
} |
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.
I think we can avoid repeating all this code and separate it into a function.
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.
Factored out into new method updateAndPersistConfig
in this commit.
core/commands/swarm.go
Outdated
return err | ||
} | ||
|
||
addrInfos, err := mergeAddrInfo(addInfos, cfg.Peering.Peers) |
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.
Correct me if I'm wrong, but we can do the same as we are doing in line 248 to set the peers, avoiding even more duplicated lines.
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.
Good catch! Simplified in this commit.
} | ||
update(cfg) | ||
if err := r.SetConfig(cfg); err != nil { | ||
return fmt.Errorf("error removing peers from repo config: %w", err) |
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.
If this method is generic for any config param, we should update this error message.
Superseded by #9425 |
Resolves #7880 where @Stebalien proposes several new CLI commands. #8147 implements most of the actual functionality.
This PR adds the
--save
option to bothipfs swarm peering add
andipfs swarm peering rm
. With this boolean option set, the mutated peering set will be written to the configuration on disk.