Skip to content

Instantly share code, notes, and snippets.

@fredldotme
Last active August 25, 2018 15:51
Show Gist options
  • Save fredldotme/81c32310e0be83f8478cd470fa9b35f8 to your computer and use it in GitHub Desktop.
Save fredldotme/81c32310e0be83f8478cd470fa9b35f8 to your computer and use it in GitHub Desktop.
speech-dispatcher snap interface implementation example
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2018 Alfred Neumayer
* Copyright (C) 2018 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package builtin
import (
"github.com/snapcore/snapd/interfaces"
"github.com/snapcore/snapd/interfaces/apparmor"
"github.com/snapcore/snapd/snap"
)
const speechDispatcherSummary = `allows access the speech-dispatcher speech synthesis abstraction socket`
const speechDispatcherBaseDeclarationSlots = `
speech-dispatcher:
allow-installation:
slot-snap-type:
- app
- core
deny-connection:
on-classic: false
deny-auto-connection:
on-classic: false
`
const speechDispatcherConnectedPlugAppArmor = `
# Allow access to the speech-dispatcher server socket
owner /run/user/[0-9]*/speech-dispatcher/speechd.sock rw,
`
type speechDispatcherInterface struct{}
func (iface *speechDispatcherInterface) Name() string {
return "speech-dispatcher"
}
func (iface *speechDispatcherInterface) StaticInfo() interfaces.StaticInfo {
return interfaces.StaticInfo{
Summary: speechDispatcherSummary,
ImplicitOnClassic: true,
BaseDeclarationSlots: speechDispatcherBaseDeclarationSlots,
}
}
func (iface *speechDispatcherInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
spec.AddSnippet(speechDispatcherConnectedPlugAppArmor)
return nil
}
func (iface *speechDispatcherInterface) AutoConnect(*snap.PlugInfo, *snap.SlotInfo) bool {
// allow what declarations allowed
return true
}
func init() {
registerIface(&speechDispatcherInterface{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment