本文整理汇总了Golang中github.com/snapcore/snapd/snap.Info.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Info.Name方法的具体用法?Golang Info.Name怎么用?Golang Info.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/snapcore/snapd/snap.Info
的用法示例。
在下文中一共展示了Info.Name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mapLocal
func mapLocal(localSnap *snap.Info, snapst *snapstate.SnapState) map[string]interface{} {
status := "installed"
if snapst.Active && localSnap.Revision == snapst.Current {
status = "active"
}
apps := make([]appJSON, 0, len(localSnap.Apps))
for _, app := range localSnap.Apps {
apps = append(apps, appJSON{
Name: app.Name,
})
}
return map[string]interface{}{
"description": localSnap.Description(),
"developer": localSnap.Developer,
"icon": snapIcon(localSnap),
"id": localSnap.SnapID,
"install-date": snapDate(localSnap),
"installed-size": localSnap.Size,
"name": localSnap.Name(),
"revision": localSnap.Revision,
"status": status,
"summary": localSnap.Summary(),
"type": string(localSnap.Type),
"version": localSnap.Version,
"channel": localSnap.Channel,
"confinement": localSnap.Confinement,
"devmode": snapst.DevMode(),
"trymode": snapst.TryMode(),
"private": localSnap.Private,
"apps": apps,
"broken": localSnap.Broken,
}
}
示例2: Setup
// Setup creates a conf file with list of kernel modules required by given snap,
// writes it in /etc/modules-load.d/ directory and immediately loads the modules
// using /sbin/modprobe. The devMode is ignored.
//
// If the method fails it should be re-tried (with a sensible strategy) by the caller.
func (b *Backend) Setup(snapInfo *snap.Info, confinement interfaces.ConfinementOptions, repo *interfaces.Repository) error {
snapName := snapInfo.Name()
// Get the snippets that apply to this snap
snippets, err := repo.SecuritySnippetsForSnap(snapInfo.Name(), interfaces.SecurityKMod)
if err != nil {
return fmt.Errorf("cannot obtain kmod security snippets for snap %q: %s", snapName, err)
}
// Get the files that this snap should have
glob := interfaces.SecurityTagGlob(snapName)
content, modules, err := b.combineSnippets(snapInfo, snippets)
if err != nil {
return fmt.Errorf("cannot obtain expected security files for snap %q: %s", snapName, err)
}
dir := dirs.SnapKModModulesDir
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("cannot create directory for kmod files %q: %s", dir, err)
}
changed, _, err := osutil.EnsureDirState(dirs.SnapKModModulesDir, glob, content)
if err != nil {
return err
}
if len(changed) > 0 {
return loadModules(modules)
}
return nil
}
示例3: templateVariables
// templateVariables returns text defining apparmor variables that can be used in the
// apparmor template and by apparmor snippets.
func templateVariables(info *snap.Info) []byte {
var buf bytes.Buffer
fmt.Fprintf(&buf, "@{SNAP_NAME}=\"%s\"\n", info.Name())
fmt.Fprintf(&buf, "@{SNAP_REVISION}=\"%s\"\n", info.Revision)
fmt.Fprintf(&buf, "@{INSTALL_DIR}=\"/snap\"")
return buf.Bytes()
}
示例4: CheckInterfaces
// CheckInterfaces checks whether plugs and slots of snap are allowed for installation.
func CheckInterfaces(st *state.State, snapInfo *snap.Info) error {
// XXX: AddImplicitSlots is really a brittle interface
snap.AddImplicitSlots(snapInfo)
baseDecl, err := assertstate.BaseDeclaration(st)
if err != nil {
return fmt.Errorf("internal error: cannot find base declaration: %v", err)
}
var snapDecl *asserts.SnapDeclaration
if snapInfo.SnapID != "" {
var err error
snapDecl, err = assertstate.SnapDeclaration(st, snapInfo.SnapID)
if err != nil {
return fmt.Errorf("cannot find snap declaration for %q: %v", snapInfo.Name(), err)
}
}
ic := policy.InstallCandidate{
Snap: snapInfo,
SnapDeclaration: snapDecl,
BaseDeclaration: baseDecl,
}
return ic.Check()
}
示例5: combineSnippets
// combineSnippets combines security snippets collected from all the interfaces
// affecting a given snap into a de-duplicated list of kernel modules.
func (b *Backend) combineSnippets(snapInfo *snap.Info, snippets map[string][][]byte) (content map[string]*osutil.FileState, modules []string, err error) {
content = make(map[string]*osutil.FileState)
for _, appInfo := range snapInfo.Apps {
for _, snippet := range snippets[appInfo.SecurityTag()] {
// split snippet by newline to get the list of modules
for _, line := range bytes.Split(snippet, []byte{'\n'}) {
l := bytes.TrimSpace(line)
// ignore empty lines and comments
if len(l) > 0 && l[0] != '#' {
modules = append(modules, string(l))
}
}
}
}
sort.Strings(modules)
modules = uniqueLines(modules)
if len(modules) > 0 {
var buffer bytes.Buffer
buffer.WriteString("# This file is automatically generated.\n")
for _, module := range modules {
buffer.WriteString(module)
buffer.WriteByte('\n')
}
content[fmt.Sprintf("%s.conf", snap.SecurityTag(snapInfo.Name()))] = &osutil.FileState{
Content: buffer.Bytes(),
Mode: 0644,
}
}
return content, modules, nil
}
示例6: ClearTrashedData
func (f *fakeSnappyBackend) ClearTrashedData(si *snap.Info) {
f.ops = append(f.ops, fakeOp{
op: "cleanup-trash",
name: si.Name(),
revno: si.Revision,
})
}
示例7: removePlugsSlots
func (s *BackendSuite) removePlugsSlots(c *C, snapInfo *snap.Info) {
for _, plug := range s.Repo.Plugs(snapInfo.Name()) {
err := s.Repo.RemovePlug(plug.Snap.Name(), plug.Name)
c.Assert(err, IsNil)
}
for _, slot := range s.Repo.Slots(snapInfo.Name()) {
err := s.Repo.RemoveSlot(slot.Snap.Name(), slot.Name)
c.Assert(err, IsNil)
}
}
示例8: AddSnap
// AddSnap adds plugs and slots declared by the given snap to the repository.
//
// This function can be used to implement snap install or, when used along with
// RemoveSnap, snap upgrade.
//
// AddSnap doesn't change existing plugs/slots. The caller is responsible for
// ensuring that the snap is not present in the repository in any way prior to
// calling this function. If this constraint is violated then no changes are
// made and an error is returned.
//
// Each added plug/slot is validated according to the corresponding interface.
// Unknown interfaces and plugs/slots that don't validate are not added.
// Information about those failures are returned to the caller.
func (r *Repository) AddSnap(snapInfo *snap.Info) error {
r.m.Lock()
defer r.m.Unlock()
snapName := snapInfo.Name()
if r.plugs[snapName] != nil || r.slots[snapName] != nil {
return fmt.Errorf("cannot register interfaces for snap %q more than once", snapName)
}
bad := BadInterfacesError{
snap: snapName,
issues: make(map[string]string),
}
for plugName, plugInfo := range snapInfo.Plugs {
iface, ok := r.ifaces[plugInfo.Interface]
if !ok {
bad.issues[plugName] = "unknown interface"
continue
}
plug := &Plug{PlugInfo: plugInfo}
if err := iface.SanitizePlug(plug); err != nil {
bad.issues[plugName] = err.Error()
continue
}
if r.plugs[snapName] == nil {
r.plugs[snapName] = make(map[string]*Plug)
}
r.plugs[snapName][plugName] = plug
}
for slotName, slotInfo := range snapInfo.Slots {
iface, ok := r.ifaces[slotInfo.Interface]
if !ok {
bad.issues[slotName] = "unknown interface"
continue
}
slot := &Slot{SlotInfo: slotInfo}
if err := iface.SanitizeSlot(slot); err != nil {
bad.issues[slotName] = err.Error()
continue
}
if r.slots[snapName] == nil {
r.slots[snapName] = make(map[string]*Slot)
}
r.slots[snapName][slotName] = slot
}
if len(bad.issues) > 0 {
return &bad
}
return nil
}
示例9: Download
func (f *fakeStoreClient) Download(remoteSnap *snap.Info, pb progress.Meter, sa store.Authenticator) (path string, err error) {
f.downloadCalls[getDownloadCall(remoteSnap.Name(), remoteSnap.Channel)]++
f.totalDownloadCalls++
if f.downloadErr {
if f.totalDownloadCalls > f.correctDownloadCalls {
return "", errors.New("")
}
}
return getSnapFilename(remoteSnap.Name(), remoteSnap.Channel), nil
}
示例10: UpdateSnap
// UpdateSnap "updates" an existing snap from YAML.
func (s *BackendSuite) UpdateSnap(c *C, oldSnapInfo *snap.Info, devMode bool, snapYaml string, revision int) *snap.Info {
newSnapInfo := snaptest.MockInfo(c, snapYaml, &snap.SideInfo{
Revision: snap.R(revision),
Developer: "acme",
})
c.Assert(newSnapInfo.Name(), Equals, oldSnapInfo.Name())
s.removePlugsSlots(c, oldSnapInfo)
s.addPlugsSlots(c, newSnapInfo)
err := s.Backend.Setup(newSnapInfo, devMode, s.Repo)
c.Assert(err, IsNil)
return newSnapInfo
}
示例11: ClearTrashedData
// ClearTrashedData removes the trash. It returns no errors on the assumption that it is called very late in the game.
func (b Backend) ClearTrashedData(oldSnap *snap.Info) {
dirs, err := snapDataDirs(oldSnap)
if err != nil {
logger.Noticef("Cannot remove previous data for %q: %v", oldSnap.Name(), err)
return
}
for _, d := range dirs {
if err := clearTrash(d); err != nil {
logger.Noticef("Cannot remove %s: %v", d, err)
}
}
}
示例12: basicEnv
// basicEnv returns the app-level environment variables for a snap.
// Despite this being a bit snap-specific, this is in helpers.go because it's
// used by so many other modules, we run into circular dependencies if it's
// somewhere more reasonable like the snappy module.
func basicEnv(info *snap.Info) map[string]string {
return map[string]string{
"SNAP": info.MountDir(),
"SNAP_COMMON": info.CommonDataDir(),
"SNAP_DATA": info.DataDir(),
"SNAP_NAME": info.Name(),
"SNAP_VERSION": info.Version,
"SNAP_REVISION": info.Revision.String(),
"SNAP_ARCH": arch.UbuntuArchitecture(),
"SNAP_LIBRARY_PATH": "/var/lib/snapd/lib/gl:",
"SNAP_REEXEC": os.Getenv("SNAP_REEXEC"),
}
}
示例13: FetchAndCheckSnapAssertions
// FetchAndCheckSnapAssertions fetches and cross checks the snap assertions matching the given snap file using the provided asserts.Fetcher and assertion database.
func FetchAndCheckSnapAssertions(snapPath string, info *snap.Info, f asserts.Fetcher, db asserts.RODatabase) error {
sha3_384, size, err := asserts.SnapFileSHA3_384(snapPath)
if err != nil {
return err
}
if err := snapasserts.FetchSnapAssertions(f, sha3_384); err != nil {
return fmt.Errorf("cannot fetch snap signatures/assertions: %v", err)
}
// cross checks
return snapasserts.CrossCheck(info.Name(), sha3_384, size, &info.SideInfo, db)
}
示例14: mapRemote
func mapRemote(remoteSnap *snap.Info) map[string]interface{} {
status := "available"
if remoteSnap.MustBuy {
status = "priced"
}
confinement := remoteSnap.Confinement
if confinement == "" {
confinement = snap.StrictConfinement
}
screenshots := make([]screenshotJSON, len(remoteSnap.Screenshots))
for i, screenshot := range remoteSnap.Screenshots {
screenshots[i] = screenshotJSON{
URL: screenshot.URL,
Width: screenshot.Width,
Height: screenshot.Height,
}
}
result := map[string]interface{}{
"description": remoteSnap.Description(),
"developer": remoteSnap.Developer,
"download-size": remoteSnap.Size,
"icon": snapIcon(remoteSnap),
"id": remoteSnap.SnapID,
"name": remoteSnap.Name(),
"revision": remoteSnap.Revision,
"status": status,
"summary": remoteSnap.Summary(),
"type": string(remoteSnap.Type),
"version": remoteSnap.Version,
"channel": remoteSnap.Channel,
"private": remoteSnap.Private,
"confinement": confinement,
}
if len(screenshots) > 0 {
result["screenshots"] = screenshots
}
if len(remoteSnap.Prices) > 0 {
result["prices"] = remoteSnap.Prices
}
if len(remoteSnap.Channels) > 0 {
result["channels"] = remoteSnap.Channels
}
return result
}
示例15: combineSnippets
// combineSnippets combines security snippets collected from all the interfaces
// affecting a given snap into a content map applicable to EnsureDirState.
func (b *Backend) combineSnippets(snapInfo *snap.Info, snippets map[string][][]byte) (result [][]byte, err error) {
var snapSnippets = make(map[string][]byte)
// We put all snippets from apps and hooks in the following part in a
// map to reach a deduplicated set of snippets we can then write out
// in a per snap udev rules file.
for _, appInfo := range snapInfo.Apps {
securityTag := appInfo.SecurityTag()
appSnippets := snippets[securityTag]
if len(appSnippets) == 0 {
continue
}
for _, snippet := range appSnippets {
snapSnippets[string(snippet)] = snippet
}
}
for _, hookInfo := range snapInfo.Hooks {
securityTag := hookInfo.SecurityTag()
hookSnippets := snippets[securityTag]
if len(hookSnippets) == 0 {
continue
}
for _, snippet := range hookSnippets {
snapSnippets[string(snippet)] = snippet
}
}
nonePrefix := snap.NoneSecurityTag(snapInfo.Name(), "")
for securityTag, slotSnippets := range snippets {
if !strings.HasPrefix(securityTag, nonePrefix) {
continue
}
for _, snippet := range slotSnippets {
snapSnippets[string(snippet)] = snippet
}
}
var combinedSnippets [][]byte
for _, snippet := range snapSnippets {
combinedSnippets = append(combinedSnippets, snippet)
}
return combinedSnippets, nil
}