Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
interfaces/builtin: improve the bluez interface #1078
Merged
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bf2abce
interfaces: bluez: create dbus policy permantenly
6d85328
interfaces: bluez: Fix the plug dbus peer label
ssweeny 7b5655d
interfaces: bluez: Allow obexd to claim org.bluez.obexd
ssweeny 7178a01
interfaces: bluez: fix dbus snippet variable name typo
ssweeny 2211730
Merge remote-tracking branch 'upstream/master' into bluez-fix-rules
ssweeny 2f17a27
Add a FIXME comment to the plug-side AppArmor rule
ssweeny 4f18baf
Merge remote-tracking branch 'upstream/master' into bluez-fix-rules
ssweeny e29cd69
interfaces/builtin: add plug/slot for bluez tests
zyga 16228ad
interfaces/builtin: don't hard-code slot name in connected plug apparmor
zyga e9b2da3
interfaces/builtin: use precise labels for bluez
zyga c1c084f
interfaces/builtin: specialize apparmor label based on bound apps
zyga 64adb67
interfaces/buitlin: add helper slotAppLabelExpr
zyga 6e730c1
interfaces/builtin: refactor slotAppLabelExpr
zyga 50269c2
interfaces/builtin: further refactor of slotAppLabelExpr
zyga eb5ff8f
interfaces/builtin: use ####var### for template variables
zyga 4df541b
interfaces/builtin: use single bytes.Buffer for slotAppLabelExpr
zyga f44fffe
interfaces/builtin: small refactor of slotAppLabelExpr
zyga 88544c3
interfaces/builtin: drop strings.Join
zyga 420f988
interfaces/builtin: use Fprintf less often
zyga
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,61 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
| +/* | ||
| + * Copyright (C) 2016 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 ( | ||
| + "bytes" | ||
| + "fmt" | ||
| + "sort" | ||
| + | ||
| + "github.com/ubuntu-core/snappy/interfaces" | ||
| +) | ||
| + | ||
| +// slotAppLabelExpr returns the specification of the apparmor label describing | ||
| +// all the apps bound to a given slot. The result has one of three forms, | ||
| +// depending on how apps are bound to the slot: | ||
| +// | ||
| +// - "snap.$snap.$app" if there is exactly one app bound | ||
| +// - "snap.$snap.{$app1,...$appN}" if there are some, but not all, apps bound | ||
| +// - "snap.$snap.*" if all apps are bound to the slot | ||
| +func slotAppLabelExpr(slot *interfaces.Slot) []byte { | ||
|
|
||
| + var buf bytes.Buffer | ||
| + fmt.Fprintf(&buf, "snap.%s.", slot.Snap.Name()) | ||
| + if len(slot.Apps) == 1 { | ||
| + for appName := range slot.Apps { | ||
| + buf.WriteString(appName) | ||
| + } | ||
| + } else if len(slot.Apps) == len(slot.Snap.Apps) { | ||
| + buf.WriteByte('*') | ||
| + } else { | ||
| + appNames := make([]string, 0, len(slot.Apps)) | ||
| + for appName := range slot.Apps { | ||
| + appNames = append(appNames, appName) | ||
| + } | ||
| + sort.Strings(appNames) | ||
| + buf.WriteByte('{') | ||
| + for _, appName := range appNames { | ||
| + buf.WriteString(appName) | ||
| + buf.WriteByte(',') | ||
| + } | ||
| + buf.Truncate(buf.Len() - 1) | ||
| + buf.WriteByte('}') | ||
| + } | ||
| + return buf.Bytes() | ||
| +} | ||
Nice!!