github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/dummy.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package builtin 21 22 import ( 23 "fmt" 24 25 "github.com/snapcore/snapd/interfaces" 26 "github.com/snapcore/snapd/interfaces/apparmor" 27 "github.com/snapcore/snapd/snap" 28 ) 29 30 type dummyInterface struct{} 31 32 const dummyInterfaceSummary = `allows testing without providing any additional permissions` 33 const dummyInterfaceBaseDeclarationSlots = ` 34 dummy: 35 allow-installation: 36 slot-snap-type: 37 - app 38 deny-auto-connection: true 39 ` 40 41 func (iface *dummyInterface) String() string { 42 return iface.Name() 43 } 44 45 // Name returns the name of the dummy interface. 46 func (iface *dummyInterface) Name() string { 47 return "dummy" 48 } 49 50 func (iface *dummyInterface) StaticInfo() interfaces.StaticInfo { 51 return interfaces.StaticInfo{ 52 Summary: dummyInterfaceSummary, 53 BaseDeclarationSlots: dummyInterfaceBaseDeclarationSlots, 54 } 55 } 56 57 func (iface *dummyInterface) BeforePreparePlug(plug *snap.PlugInfo) error { 58 return nil 59 } 60 61 func (iface *dummyInterface) BeforePrepareSlot(slot *snap.SlotInfo) error { 62 return nil 63 } 64 65 func (iface *dummyInterface) BeforeConnectPlug(plug *interfaces.ConnectedPlug) error { 66 var value string 67 if err := plug.Attr("before-connect", &value); err != nil { 68 return err 69 } 70 value = fmt.Sprintf("plug-changed(%s)", value) 71 return plug.SetAttr("before-connect", value) 72 } 73 74 func (iface *dummyInterface) BeforeConnectSlot(slot *interfaces.ConnectedSlot) error { 75 var num int64 76 if err := slot.Attr("producer-num-1", &num); err != nil { 77 return err 78 } 79 var value string 80 if err := slot.Attr("before-connect", &value); err != nil { 81 return err 82 } 83 value = fmt.Sprintf("slot-changed(%s)", value) 84 return slot.SetAttr("before-connect", value) 85 } 86 87 func (iface *dummyInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 88 return nil 89 } 90 91 func (iface *dummyInterface) AppArmorConnectedSlot(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 92 return nil 93 } 94 95 func (iface *dummyInterface) AutoConnect(*snap.PlugInfo, *snap.SlotInfo) bool { 96 return true 97 } 98 99 func init() { 100 registerIface(&dummyInterface{}) 101 }