interfaces/builtin: make all interfaces private #3295

Merged
merged 3 commits into from May 12, 2017
@@ -19,10 +19,6 @@
package builtin
-import (
- "github.com/snapcore/snapd/interfaces"
-)
-
const accountControlConnectedPlugAppArmor = `
# Allow creating, modifying and deleting non-system users and account password.
/{,usr/}sbin/chpasswd ixr,
@@ -63,16 +59,11 @@ bind
socket AF_NETLINK - NETLINK_AUDIT
`
-// Interface which allows to handle the user accounts.
-func NewAccountControlInterface() interfaces.Interface {
- return &commonInterface{
+func init() {
+ registerIface(&commonInterface{
name: "account-control",
connectedPlugAppArmor: accountControlConnectedPlugAppArmor,
connectedPlugSecComp: accountControlConnectedPlugSecComp,
reservedForOS: true,
- }
-}
-
-func init() {
- registerIface(NewAccountControlInterface())
+ })
}
@@ -37,7 +37,9 @@ type AccountControlSuite struct {
plug *interfaces.Plug
}
-var _ = Suite(&AccountControlSuite{})
+var _ = Suite(&AccountControlSuite{
+ iface: builtin.MustInterface("account-control"),
+})
const accountCtlMockPlugSnapInfo = `name: other
version: 1.0
@@ -48,7 +50,6 @@ apps:
`
func (s *AccountControlSuite) SetUpTest(c *C) {
- s.iface = builtin.NewAccountControlInterface()
s.slot = &interfaces.Slot{
SlotInfo: &snap.SlotInfo{
Snap: &snap.Info{SuggestedName: "core", Type: snap.TypeOS},
@@ -19,8 +19,6 @@
package builtin
-import "github.com/snapcore/snapd/interfaces"
-
const alsaConnectedPlugAppArmor = `
# Description: Allow access to raw ALSA devices.
@@ -33,14 +31,10 @@ const alsaConnectedPlugAppArmor = `
/var/lib/alsa/{,*} r,
`
-func NewAlsaInterface() interfaces.Interface {
- return &commonInterface{
+func init() {
+ registerIface(&commonInterface{
name: "alsa",
connectedPlugAppArmor: alsaConnectedPlugAppArmor,
reservedForOS: true,
- }
-}
-
-func init() {
- registerIface(NewAlsaInterface())
+ })
}
@@ -36,7 +36,9 @@ type AlsaInterfaceSuite struct {
plug *interfaces.Plug
}
-var _ = Suite(&AlsaInterfaceSuite{})
+var _ = Suite(&AlsaInterfaceSuite{
+ iface: builtin.MustInterface("alsa"),
+})
func (s *AlsaInterfaceSuite) SetUpTest(c *C) {
var mockPlugSnapInfoYaml = `name: other
@@ -46,7 +48,6 @@ apps:
command: foo
plugs: [alsa]
`
- s.iface = builtin.NewAlsaInterface()
s.slot = &interfaces.Slot{
SlotInfo: &snap.SlotInfo{
Snap: &snap.Info{SuggestedName: "core", Type: snap.TypeOS},
@@ -56,6 +57,7 @@ apps:
}
snapInfo := snaptest.MockInfo(c, mockPlugSnapInfoYaml, nil)
s.plug = &interfaces.Plug{PlugInfo: snapInfo.Plugs["alsa"]}
+ c.Assert(s.iface, NotNil)
}
func (s *AlsaInterfaceSuite) TestName(c *C) {
@@ -19,10 +19,6 @@
package builtin
-import (
- "github.com/snapcore/snapd/interfaces"
-)
-
const autopilotIntrospectionPlugAppArmor = `
# Description: Allows an application to be introspected and export its ui
# status over DBus
@@ -56,17 +52,11 @@ sendmsg
sendto
`
-// NewAutopilotIntrospectionInterface returns a new "autopilot-introspection"
-// interface.
-func NewAutopilotIntrospectionInterface() interfaces.Interface {
- return &commonInterface{
+func init() {
+ registerIface(&commonInterface{
name: "autopilot-introspection",
connectedPlugAppArmor: autopilotIntrospectionPlugAppArmor,
connectedPlugSecComp: autopilotIntrospectionPlugSecComp,
reservedForOS: true,
- }
-}
-
-func init() {
- registerIface(NewAutopilotIntrospectionInterface())
+ })
}
@@ -45,10 +45,11 @@ apps:
plugs: [autopilot-introspection]
`
-var _ = Suite(&AutopilotInterfaceSuite{})
+var _ = Suite(&AutopilotInterfaceSuite{
+ iface: builtin.MustInterface("autopilot-introspection"),
+})
func (s *AutopilotInterfaceSuite) SetUpTest(c *C) {
- s.iface = builtin.NewAutopilotIntrospectionInterface()
s.slot = &interfaces.Slot{
SlotInfo: &snap.SlotInfo{
Snap: &snap.Info{SuggestedName: "core", Type: snap.TypeOS},
@@ -19,8 +19,6 @@
package builtin
-import "github.com/snapcore/snapd/interfaces"
-
const avahiObserveConnectedPlugAppArmor = `
# Description: allows domain browsing, service browsing and service resolving
@@ -113,14 +111,10 @@ dbus (receive)
peer=(label=unconfined),
`
-func NewAvahiObserveInterface() interfaces.Interface {
- return &commonInterface{
+func init() {
+ registerIface(&commonInterface{
name: "avahi-observe",
connectedPlugAppArmor: avahiObserveConnectedPlugAppArmor,
reservedForOS: true,
- }
-}
-
-func init() {
- registerIface(NewAvahiObserveInterface())
+ })
}
@@ -36,7 +36,9 @@ type AvahiObserveInterfaceSuite struct {
plug *interfaces.Plug
}
-var _ = Suite(&AvahiObserveInterfaceSuite{})
+var _ = Suite(&AvahiObserveInterfaceSuite{
+ iface: builtin.MustInterface("avahi-observe"),
+})
func (s *AvahiObserveInterfaceSuite) SetUpTest(c *C) {
var mockPlugSnapInfoYaml = `name: other
@@ -46,7 +48,6 @@ apps:
command: foo
plugs: [avahi-observe]
`
- s.iface = builtin.NewAvahiObserveInterface()
s.slot = &interfaces.Slot{
SlotInfo: &snap.SlotInfo{
Snap: &snap.Info{SuggestedName: "core", Type: snap.TypeOS},
@@ -19,10 +19,6 @@
package builtin
-import (
- "github.com/snapcore/snapd/interfaces"
-)
-
const bluetoothControlConnectedPlugAppArmor = `
# Description: Allow managing the kernel side Bluetooth stack. Reserved
# because this gives privileged access to the system.
@@ -50,15 +46,11 @@ const bluetoothControlConnectedPlugSecComp = `
bind
`
-func NewBluetoothControlInterface() interfaces.Interface {
- return &commonInterface{
+func init() {
+ registerIface(&commonInterface{
name: "bluetooth-control",
connectedPlugAppArmor: bluetoothControlConnectedPlugAppArmor,
connectedPlugSecComp: bluetoothControlConnectedPlugSecComp,
reservedForOS: true,
- }
-}
-
-func init() {
- registerIface(NewBluetoothControlInterface())
+ })
}
@@ -45,10 +45,11 @@ apps:
plugs: [bluetooth-control]
`
-var _ = Suite(&BluetoothControlInterfaceSuite{})
+var _ = Suite(&BluetoothControlInterfaceSuite{
+ iface: builtin.MustInterface("bluetooth-control"),
+})
func (s *BluetoothControlInterfaceSuite) SetUpTest(c *C) {
- s.iface = builtin.NewBluetoothControlInterface()
s.slot = &interfaces.Slot{
SlotInfo: &snap.SlotInfo{
Snap: &snap.Info{SuggestedName: "core", Type: snap.TypeOS},
@@ -181,56 +181,56 @@ const bluezPermanentSlotDBus = `
</policy>
`
-type BluezInterface struct{}
+type bluezInterface struct{}
-func (iface *BluezInterface) Name() string {
+func (iface *bluezInterface) Name() string {
return "bluez"
}
-func (iface *BluezInterface) DBusPermanentSlot(spec *dbus.Specification, slot *interfaces.Slot) error {
+func (iface *bluezInterface) DBusPermanentSlot(spec *dbus.Specification, slot *interfaces.Slot) error {
spec.AddSnippet(bluezPermanentSlotDBus)
return nil
}
-func (iface *BluezInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error {
+func (iface *bluezInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error {
old := "###SLOT_SECURITY_TAGS###"
new := slotAppLabelExpr(slot)
snippet := strings.Replace(bluezConnectedPlugAppArmor, old, new, -1)
spec.AddSnippet(snippet)
return nil
}
-func (iface *BluezInterface) AppArmorConnectedSlot(spec *apparmor.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error {
+func (iface *bluezInterface) AppArmorConnectedSlot(spec *apparmor.Specification, plug *interfaces.Plug, plugAttrs map[string]interface{}, slot *interfaces.Slot, slotAttrs map[string]interface{}) error {
old := "###PLUG_SECURITY_TAGS###"
new := plugAppLabelExpr(plug)
snippet := strings.Replace(bluezConnectedSlotAppArmor, old, new, -1)
spec.AddSnippet(snippet)
return nil
}
-func (iface *BluezInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *interfaces.Slot) error {
+func (iface *bluezInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *interfaces.Slot) error {
spec.AddSnippet(bluezPermanentSlotAppArmor)
return nil
}
-func (iface *BluezInterface) SecCompPermanentSlot(spec *seccomp.Specification, slot *interfaces.Slot) error {
+func (iface *bluezInterface) SecCompPermanentSlot(spec *seccomp.Specification, slot *interfaces.Slot) error {
spec.AddSnippet(bluezPermanentSlotSecComp)
return nil
}
-func (iface *BluezInterface) SanitizePlug(plug *interfaces.Plug) error {
+func (iface *bluezInterface) SanitizePlug(plug *interfaces.Plug) error {
return nil
}
-func (iface *BluezInterface) SanitizeSlot(slot *interfaces.Slot) error {
+func (iface *bluezInterface) SanitizeSlot(slot *interfaces.Slot) error {
return nil
}
-func (iface *BluezInterface) AutoConnect(*interfaces.Plug, *interfaces.Slot) bool {
+func (iface *bluezInterface) AutoConnect(*interfaces.Plug, *interfaces.Slot) bool {
// allow what declarations allowed
return true
}
func init() {
- registerIface(&BluezInterface{})
+ registerIface(&bluezInterface{})
}
@@ -38,7 +38,9 @@ type BluezInterfaceSuite struct {
plug *interfaces.Plug
}
-var _ = Suite(&BluezInterfaceSuite{})
+var _ = Suite(&BluezInterfaceSuite{
+ iface: builtin.MustInterface("bluez"),
+})
const bluezMockPlugSnapInfoYaml = `name: other
version: 1.0
@@ -56,7 +58,6 @@ apps:
`
func (s *BluezInterfaceSuite) SetUpTest(c *C) {
- s.iface = &builtin.BluezInterface{}
slotSnap := snaptest.MockInfo(c, bluezMockSlotSnapInfoYaml, nil)
s.slot = &interfaces.Slot{SlotInfo: slotSnap.Slots["bluez"]}
plugSnap := snaptest.MockInfo(c, bluezMockPlugSnapInfoYaml, nil)
Oops, something went wrong.