interfaces: API additions for interface hooks #3119

Merged
merged 23 commits into from May 10, 2017

Conversation

Projects
None yet
4 participants
Contributor

stolowski commented Mar 31, 2017

Changes to the interface of interfaces: extended AddConnectedPlug/Slot methods to take slot/plug attributes maps. Added stubs for ValidatePlug/Slot methods which will be called to validate dynamic attributes coming from interface hooks (this is implemented in PR #3120).

The API will be used in a followup PR.

stolowski added some commits Mar 28, 2017

zyga approved these changes Mar 31, 2017

LGTM

If you agree about the suggestion to have Validate{Plug,Slot} optional like other interface methods I can follow up with a quick PR that does this.

interfaces/builtin/bluez.go
@@ -225,3 +225,13 @@ func (iface *BluezInterface) AutoConnect(*interfaces.Plug, *interfaces.Slot) boo
// allow what declarations allowed
return true
}
+
+func (iface *BluezInterface) ValidatePlug(plug *interfaces.Plug, attrs map[string]interface{}) error {
@zyga

zyga Mar 31, 2017

Contributor

I kind of wish we did the same trick we have elsewhere with interfaces. We could have a function that validates a plug that checks if the interface supports validation. This would cut the amount of boilerplate code significantly as it could do simple stuff like checking if interfaces match etc etc (sanitize could be done the same way). What do you think?

@stolowski

stolowski Mar 31, 2017

Contributor

That's a very nice idea indeed. I can do it (in a followup)

@stolowski

stolowski Mar 31, 2017

Contributor

@zyga Ok, I made ValidatePlug/Slot optional in the PR #3120 (also improved a test there to make sure it's called when it should). ValidatePlug/Slot is removed from base Interface in core.go completely and I've removed it from all interfaces which have no attributes (so there is no potential use for Validate* to exists atm); I've left empty stubs for Validate* in interfaces which can potentially make use of attributes from hooks. This all makes sense in PR #3120 (I hope).

@@ -131,21 +127,13 @@ func (iface *unity8PimCommonInterface) AppArmorConnectedPlug(spec *apparmor.Spec
return nil
}
-func (iface *unity8PimCommonInterface) ConnectedPlugSnippet(plug *interfaces.Plug, slot *interfaces.Slot, securitySystem interfaces.SecuritySystem) ([]byte, error) {
@zyga

zyga Mar 31, 2017

Contributor

I'd leave those out for a separate PR. (as a habit)

stolowski added some commits Mar 31, 2017

Removed Validate* methods from interfaces which don't have attributes…
…. Don't define it in core as it's going to be optional.

mvo5 approved these changes Apr 3, 2017

Looks good!

@mvo5 mvo5 requested a review from niemeyer Apr 3, 2017

stolowski and others added some commits Apr 3, 2017

Merge branch 'master' of github.com:snapcore/snapd into iface-hooks-a…
…pi-new

I also ported the joystick interface to the newer APIs
Contributor

zyga commented May 9, 2017

Can we please...

  • land #3284
  • merge master into this branch
  • add extra checks in interfaces/builtin/all_test.go so that no legacy methods are used
  • see tests go green

... before landing this branch?

stolowski added some commits May 10, 2017

Nice, thanks! And thanks to @zyga as well for the tests and the care taken ensuring things remain working in the future.

@niemeyer niemeyer merged commit 69eee7c into snapcore:master May 10, 2017

7 checks passed

artful-amd64 autopkgtest finished (success)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-i386 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment