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
overlord/ifacestate: setup security of snaps affected by auto-connection #2652
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
875c4a2
overlord/ifacestate: don't clobber connection when auto-connecting
zyga c216d1c
overlord/ifacestate: setup security of snaps affected by auto-connection
zyga a2ba6ad
overlord/ifacestate: rename variables for extra clarity
zyga a574b43
overlord/ifacestate: document autoConnect
zyga File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -200,19 +200,20 @@ func (c *autoConnectChecker) check(plug *interfaces.Plug, slot *interfaces.Slot) | |
return ic.CheckAutoConnect() == nil | ||
} | ||
|
||
func (m *InterfaceManager) autoConnect(task *state.Task, snapName string, blacklist map[string]bool) error { | ||
func (m *InterfaceManager) autoConnect(task *state.Task, snapName string, blacklist map[string]bool) ([]string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a comment for the function, as that first result is impossible to guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'm sorry for not documenting it earlier. |
||
var conns map[string]connState | ||
var affectedSnapNames []string | ||
err := task.State().Get("conns", &conns) | ||
if err != nil && err != state.ErrNoState { | ||
return err | ||
return nil, err | ||
} | ||
if conns == nil { | ||
conns = make(map[string]connState) | ||
} | ||
|
||
autochecker, err := newAutoConnectChecker(task.State()) | ||
if err != nil { | ||
return err | ||
return nil, err | ||
} | ||
|
||
// XXX: quick hack, auto-connect everything | ||
|
@@ -226,14 +227,20 @@ func (m *InterfaceManager) autoConnect(task *state.Task, snapName string, blackl | |
} | ||
slot := candidates[0] | ||
connRef := interfaces.ConnRef{PlugRef: plug.Ref(), SlotRef: slot.Ref()} | ||
key := connRef.ID() | ||
if _, ok := conns[key]; ok { | ||
// Suggested connection already exist so don't clobber it. | ||
continue | ||
} | ||
if err := m.repo.Connect(connRef); err != nil { | ||
task.Logf("cannot auto connect %s to %s: %s", connRef.PlugRef, connRef.SlotRef, err) | ||
} | ||
key := connRef.ID() | ||
affectedSnapNames = append(affectedSnapNames, connRef.PlugRef.Snap) | ||
affectedSnapNames = append(affectedSnapNames, connRef.SlotRef.Snap) | ||
conns[key] = connState{Interface: plug.Interface, Auto: true} | ||
} | ||
task.State().Set("conns", conns) | ||
return nil | ||
return affectedSnapNames, nil | ||
} | ||
|
||
func getPlugAndSlotRefs(task *state.Task) (interfaces.PlugRef, interfaces.SlotRef, error) { | ||
|
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
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.
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.
Before I could tell this was a list of snaps that were touched. Now it can be pretty much anything.
How about
disconnectedSnaps
andconnectedSnaps
below?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.
ah, nicer names, thank you.