repo: use PlugInfo and SlotInfo for permanent plugs/slots #4120

Merged
merged 6 commits into from Nov 14, 2017
@@ -35,6 +35,7 @@ import (
"github.com/snapcore/snapd/interfaces/ifacetest"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/release"
+ "github.com/snapcore/snapd/snap"
"github.com/snapcore/snapd/snap/snaptest"
"github.com/snapcore/snapd/testutil"
)
@@ -390,7 +391,7 @@ func (s *backendSuite) TestCombineSnippets(c *C) {
"}\n")
defer restoreClassicTemplate()
for _, scenario := range combineSnippetsScenarios {
- s.Iface.AppArmorPermanentSlotCallback = func(spec *apparmor.Specification, slot *interfaces.Slot) error {
+ s.Iface.AppArmorPermanentSlotCallback = func(spec *apparmor.Specification, slot *snap.SlotInfo) error {
if scenario.snippet == "" {
return nil
}
@@ -21,6 +21,7 @@ package apparmor
import (
"github.com/snapcore/snapd/interfaces"
+ "github.com/snapcore/snapd/snap"
"sort"
"strings"
@@ -101,9 +102,9 @@ func (spec *Specification) AddConnectedSlot(iface interfaces.Interface, plug *in
}
// AddPermanentPlug records mount-specific side-effects of having a plug.
-func (spec *Specification) AddPermanentPlug(iface interfaces.Interface, plug *interfaces.Plug) error {
+func (spec *Specification) AddPermanentPlug(iface interfaces.Interface, plug *snap.PlugInfo) error {
type definer interface {
- AppArmorPermanentPlug(spec *Specification, plug *interfaces.Plug) error
+ AppArmorPermanentPlug(spec *Specification, plug *snap.PlugInfo) error
}
if iface, ok := iface.(definer); ok {
spec.securityTags = plug.SecurityTags()
@@ -114,9 +115,9 @@ func (spec *Specification) AddPermanentPlug(iface interfaces.Interface, plug *in
}
// AddPermanentSlot records mount-specific side-effects of having a slot.
-func (spec *Specification) AddPermanentSlot(iface interfaces.Interface, slot *interfaces.Slot) error {
+func (spec *Specification) AddPermanentSlot(iface interfaces.Interface, slot *snap.SlotInfo) error {
type definer interface {
- AppArmorPermanentSlot(spec *Specification, slot *interfaces.Slot) error
+ AppArmorPermanentSlot(spec *Specification, slot *snap.SlotInfo) error
}
if iface, ok := iface.(definer); ok {
spec.securityTags = slot.SecurityTags()
@@ -46,11 +46,11 @@ var _ = Suite(&specSuite{
spec.AddSnippet("connected-slot")
return nil
},
- AppArmorPermanentPlugCallback: func(spec *apparmor.Specification, plug *interfaces.Plug) error {
+ AppArmorPermanentPlugCallback: func(spec *apparmor.Specification, plug *snap.PlugInfo) error {
spec.AddSnippet("permanent-plug")
return nil
},
- AppArmorPermanentSlotCallback: func(spec *apparmor.Specification, slot *interfaces.Slot) error {
+ AppArmorPermanentSlotCallback: func(spec *apparmor.Specification, slot *snap.SlotInfo) error {
spec.AddSnippet("permanent-slot")
return nil
},
@@ -92,8 +92,8 @@ func (s *specSuite) TestSpecificationIface(c *C) {
var r interfaces.Specification = s.spec
c.Assert(r.AddConnectedPlug(s.iface, s.plug, nil, s.slot, nil), IsNil)
c.Assert(r.AddConnectedSlot(s.iface, s.plug, nil, s.slot, nil), IsNil)
- c.Assert(r.AddPermanentPlug(s.iface, s.plug), IsNil)
- c.Assert(r.AddPermanentSlot(s.iface, s.slot), IsNil)
+ c.Assert(r.AddPermanentPlug(s.iface, s.plug.PlugInfo), IsNil)
+ c.Assert(r.AddPermanentSlot(s.iface, s.slot.SlotInfo), IsNil)
c.Assert(s.spec.Snippets(), DeepEquals, map[string][]string{
"snap.snap1.app1": {"connected-plug", "permanent-plug"},
"snap.snap2.app2": {"connected-slot", "permanent-slot"},
@@ -56,10 +56,10 @@ type apparmorDefiner2 interface {
AppArmorConnestedSlot(spec *apparmor.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error
}
type apparmorDefiner3 interface {
- AppArmorPermanentPlug(spec *apparmor.Specification, plug *interfaces.Plug) error
+ AppArmorPermanentPlug(spec *apparmor.Specification, plug *snap.PlugInfo) error
}
type apparmorDefiner4 interface {
- AppArmorPermanentSlot(spec *apparmor.Specification, slot *interfaces.Slot) error
+ AppArmorPermanentSlot(spec *apparmor.Specification, slot *snap.SlotInfo) error
}
type dbusDefiner1 interface {
@@ -72,7 +72,7 @@ type dbusDefiner3 interface {
DBusPermanestPlug(spec *dbus.Specification, plug *interfaces.Plug) error
}
type dbusDefiner4 interface {
- DBusPermanentSlot(spec *dbus.Specification, slot *interfaces.Slot) error
+ DBusPermanentSlot(spec *dbus.Specification, slot *snap.SlotInfo) error
}
type kmodDefiner1 interface {
@@ -82,10 +82,10 @@ type kmodDefiner2 interface {
KModConnectedSlot(spec *kmod.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error
}
type kmodDefiner3 interface {
- KModPermanentPlug(spec *kmod.Specification, plug *interfaces.Plug) error
+ KModPermanentPlug(spec *kmod.Specification, plug *snap.PlugInfo) error
}
type kmodDefiner4 interface {
- KModPermanentSlot(spec *kmod.Specification, slot *interfaces.Slot) error
+ KModPermanentSlot(spec *kmod.Specification, slot *snap.SlotInfo) error
}
type mountDefiner1 interface {
@@ -95,10 +95,10 @@ type mountDefiner2 interface {
MountConnectedSlot(spec *mount.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error
}
type mountDefiner3 interface {
- MountPermanentPlug(spec *mount.Specification, plug *interfaces.Plug) error
+ MountPermanentPlug(spec *mount.Specification, plug *snap.PlugInfo) error
}
type mountDefiner4 interface {
- MountPermanentSlot(spec *mount.Specification, slot *interfaces.Slot) error
+ MountPermanentSlot(spec *mount.Specification, slot *snap.SlotInfo) error
}
type seccompDefiner1 interface {
@@ -108,10 +108,10 @@ type seccompDefiner2 interface {
SecCompConnectedSlot(spec *seccomp.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error
}
type seccompDefiner3 interface {
- SecCompPermanentPlug(spec *seccomp.Specification, plug *interfaces.Plug) error
+ SecCompPermanentPlug(spec *seccomp.Specification, plug *snap.PlugInfo) error
}
type seccompDefiner4 interface {
- SecCompPermanentSlot(spec *seccomp.Specification, slot *interfaces.Slot) error
+ SecCompPermanentSlot(spec *seccomp.Specification, slot *snap.SlotInfo) error
}
type systemdDefiner1 interface {
@@ -121,10 +121,10 @@ type systemdDefiner2 interface {
SystemdConnectedSlot(spec *systemd.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error
}
type systemdDefiner3 interface {
- SystemdPermanentPlug(spec *systemd.Specification, plug *interfaces.Plug) error
+ SystemdPermanentPlug(spec *systemd.Specification, plug *snap.PlugInfo) error
}
type systemdDefiner4 interface {
- SystemdPermanentSlot(spec *systemd.Specification, slot *interfaces.Slot) error
+ SystemdPermanentSlot(spec *systemd.Specification, slot *snap.SlotInfo) error
}
type udevDefiner1 interface {
@@ -134,10 +134,10 @@ type udevDefiner2 interface {
UDevConnectedSlot(spec *udev.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error
}
type udevDefiner3 interface {
- UDevPermanentPlug(spec *udev.Specification, plug *interfaces.Plug) error
+ UDevPermanentPlug(spec *udev.Specification, plug *snap.PlugInfo) error
}
type udevDefiner4 interface {
- UDevPermanentSlot(spec *udev.Specification, slot *interfaces.Slot) error
+ UDevPermanentSlot(spec *udev.Specification, slot *snap.SlotInfo) error
}
// allGoodDefiners contains all valid specification definers for all known backends.
@@ -202,10 +202,10 @@ type snippetDefiner2 interface {
ConnectedSlotSnippet(plug *interfaces.Plug, slot *interfaces.Slot, sec interfaces.SecuritySystem) error
}
type snippetDefiner3 interface {
- PermanentPlugSnippet(plug *interfaces.Plug, sec interfaces.SecuritySystem) error
+ PermanentPlugSnippet(plug *snap.PlugInfo, sec interfaces.SecuritySystem) error
}
type snippetDefiner4 interface {
- PermanentSlotSnippet(slot *interfaces.Slot, sec interfaces.SecuritySystem) error
+ PermanentSlotSnippet(slot *snap.SlotInfo, sec interfaces.SecuritySystem) error
}
@zyga

zyga Nov 2, 2017

Contributor

All the changes above are ok. Can you add a test that checks we are not merging any new interfaces with the old signature methods please?

@zyga

zyga Nov 2, 2017

Contributor

On second thought #4124 ensures this directly so please just merge it here after it lands in master.

// old auto-connect function
@@ -371,14 +371,14 @@ func (s *AllSuite) TestUnexpectedSpecSignatures(c *C) {
name: fmt.Sprintf("%sPermanentPlug", backend),
in: []string{
fmt.Sprintf("*%s.Specification", backendLower),
- "*interfaces.Plug",
+ "*snap.PlugInfo",
},
out: []string{"error"},
}, {
name: fmt.Sprintf("%sPermanentSlot", backend),
in: []string{
fmt.Sprintf("*%s.Specification", backendLower),
- "*interfaces.Slot",
+ "*snap.SlotInfo",
},
out: []string{"error"},
}, {
@@ -26,6 +26,7 @@ import (
"github.com/snapcore/snapd/interfaces/apparmor"
"github.com/snapcore/snapd/interfaces/dbus"
"github.com/snapcore/snapd/release"
+ "github.com/snapcore/snapd/snap"
)
const avahiControlBaseDeclarationSlots = `
@@ -133,7 +134,7 @@ func (iface *avahiControlInterface) AppArmorConnectedPlug(spec *apparmor.Specifi
return nil
}
-func (iface *avahiControlInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *interfaces.Slot) error {
+func (iface *avahiControlInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
// NOTE: this is using avahi-observe permanent slot as it contains
// base declarations for running as the avahi service.
@@ -155,7 +156,7 @@ func (iface *avahiControlInterface) AppArmorConnectedSlot(spec *apparmor.Specifi
return nil
}
-func (iface *avahiControlInterface) DBusPermanentSlot(spec *dbus.Specification, slot *interfaces.Slot) error {
+func (iface *avahiControlInterface) DBusPermanentSlot(spec *dbus.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
// NOTE: this is using avahi-observe permanent slot as it contains
// base declarations for running as the avahi service.
@@ -122,7 +122,7 @@ func (s *AvahiControlInterfaceSuite) TestAppArmorSpec(c *C) {
// permanent app slot
spec = &apparmor.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.producer.app"})
c.Assert(spec.SnippetForTag("snap.producer.app"), testutil.Contains, `dbus (bind)
bus=system
@@ -154,7 +154,7 @@ func (s *AvahiControlInterfaceSuite) TestAppArmorSpec(c *C) {
// permanent core slot
spec = &apparmor.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), HasLen, 0)
}
@@ -164,7 +164,7 @@ func (s *AvahiControlInterfaceSuite) TestDBusSpec(c *C) {
defer restore()
spec := &dbus.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.producer.app"})
c.Assert(spec.SnippetForTag("snap.producer.app"), testutil.Contains, `<allow own="org.freedesktop.Avahi"/>`)
@@ -173,7 +173,7 @@ func (s *AvahiControlInterfaceSuite) TestDBusSpec(c *C) {
defer restore()
spec = &dbus.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), HasLen, 0)
}
@@ -26,6 +26,7 @@ import (
"github.com/snapcore/snapd/interfaces/apparmor"
"github.com/snapcore/snapd/interfaces/dbus"
"github.com/snapcore/snapd/release"
+ "github.com/snapcore/snapd/snap"
)
const avahiObserveSummary = `allows discovery on a local network via the mDNS/DNS-SD protocol suite`
@@ -435,7 +436,7 @@ func (iface *avahiObserveInterface) AppArmorConnectedPlug(spec *apparmor.Specifi
return nil
}
-func (iface *avahiObserveInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *interfaces.Slot) error {
+func (iface *avahiObserveInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
spec.AddSnippet(avahiObservePermanentSlotAppArmor)
}
@@ -452,7 +453,7 @@ func (iface *avahiObserveInterface) AppArmorConnectedSlot(spec *apparmor.Specifi
return nil
}
-func (iface *avahiObserveInterface) DBusPermanentSlot(spec *dbus.Specification, slot *interfaces.Slot) error {
+func (iface *avahiObserveInterface) DBusPermanentSlot(spec *dbus.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
spec.AddSnippet(avahiObservePermanentSlotDBus)
}
@@ -122,7 +122,7 @@ func (s *AvahiObserveInterfaceSuite) TestAppArmorSpec(c *C) {
// permanent app slot
spec = &apparmor.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.producer.app"})
c.Assert(spec.SnippetForTag("snap.producer.app"), testutil.Contains, `dbus (bind)
bus=system
@@ -154,7 +154,7 @@ func (s *AvahiObserveInterfaceSuite) TestAppArmorSpec(c *C) {
// permanent core slot
spec = &apparmor.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), HasLen, 0)
}
@@ -164,7 +164,7 @@ func (s *AvahiObserveInterfaceSuite) TestDBusSpec(c *C) {
defer restore()
spec := &dbus.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.appSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.producer.app"})
c.Assert(spec.SnippetForTag("snap.producer.app"), testutil.Contains, `<allow own="org.freedesktop.Avahi"/>`)
@@ -173,7 +173,7 @@ func (s *AvahiObserveInterfaceSuite) TestDBusSpec(c *C) {
defer restore()
spec = &dbus.Specification{}
- c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot), IsNil)
+ c.Assert(spec.AddPermanentSlot(s.iface, s.coreSlot.SlotInfo), IsNil)
c.Assert(spec.SecurityTags(), HasLen, 0)
}
@@ -28,6 +28,7 @@ import (
"github.com/snapcore/snapd/interfaces/seccomp"
"github.com/snapcore/snapd/interfaces/udev"
"github.com/snapcore/snapd/release"
+ "github.com/snapcore/snapd/snap"
)
const bluezSummary = `allows operating as the bluez service`
@@ -211,7 +212,7 @@ func (iface *bluezInterface) StaticInfo() interfaces.StaticInfo {
}
}
-func (iface *bluezInterface) DBusPermanentSlot(spec *dbus.Specification, slot *interfaces.Slot) error {
+func (iface *bluezInterface) DBusPermanentSlot(spec *dbus.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
spec.AddSnippet(bluezPermanentSlotDBus)
}
@@ -246,14 +247,14 @@ func (iface *bluezInterface) UDevConnectedPlug(spec *udev.Specification, plug *i
return nil
}
-func (iface *bluezInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *interfaces.Slot) error {
+func (iface *bluezInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
spec.AddSnippet(bluezPermanentSlotAppArmor)
}
return nil
}
-func (iface *bluezInterface) SecCompPermanentSlot(spec *seccomp.Specification, slot *interfaces.Slot) error {
+func (iface *bluezInterface) SecCompPermanentSlot(spec *seccomp.Specification, slot *snap.SlotInfo) error {
if !release.OnClassic {
spec.AddSnippet(bluezPermanentSlotSecComp)
}
Oops, something went wrong.