github.com/Lephar/snapd@v0.0.0-20210825215435-c7fba9cef4d2/overlord/snapstate/flags.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 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 snapstate 21 22 // Flags are used to pass additional flags to operations and to keep track of 23 // snap modes. 24 type Flags struct { 25 // DevMode switches confinement to non-enforcing mode. 26 DevMode bool `json:"devmode,omitempty"` 27 // JailMode is set when the user has requested confinement 28 // always be enforcing, even if the snap requests otherwise. 29 JailMode bool `json:"jailmode,omitempty"` 30 // Classic is set when the user has consented to install a snap with 31 // classic confinement and the snap declares that confinement. 32 Classic bool `json:"classic,omitempty"` 33 // TryMode is set for snaps installed to try directly from a local directory. 34 TryMode bool `json:"trymode,omitempty"` 35 36 // Revert flags the SnapSetup as coming from a revert 37 Revert bool `json:"revert,omitempty"` 38 39 // RemoveSnapPath is used via InstallPath to flag that the file passed in is 40 // temporary and should be removed 41 RemoveSnapPath bool `json:"remove-snap-path,omitempty"` 42 43 // IgnoreValidation is set when the user requested as one-off 44 // to ignore refresh control validation. 45 IgnoreValidation bool `json:"ignore-validation,omitempty"` 46 47 // IgnoreRunning is set to indicate that running apps or hooks should be 48 // ignored. 49 IgnoreRunning bool `json:"ignore-running,omitempty"` 50 51 // Required is set to mark that a snap is required 52 // and cannot be removed 53 Required bool `json:"required,omitempty"` 54 55 // SkipConfigure is used with InstallPath to flag that creating a task 56 // running the configure hook should be skipped. 57 SkipConfigure bool `json:"skip-configure,omitempty"` 58 59 // SkipKernelExtraction is used with InstallPath to flag that the 60 // kernel extraction should be skipped. This is useful during seeding. 61 SkipKernelExtraction bool `json:"skip-kernel-extraction,omitempty"` 62 63 // Unaliased is set to request that no automatic aliases are created 64 // installing the snap. 65 Unaliased bool `json:"unaliased,omitempty"` 66 67 // Amend allows refreshing out of a snap unknown to the store 68 // and into one that is known. 69 Amend bool `json:"amend,omitempty"` 70 71 // IsAutoRefresh is true if the snap is currently auto-refreshed 72 IsAutoRefresh bool `json:"is-auto-refresh,omitempty"` 73 74 // NoReRefresh prevents refresh from adding epoch-hopping 75 // re-refresh tasks. This allows refresh to work offline, as 76 // long as refresh assets are cached. 77 NoReRefresh bool `json:"no-rerefresh,omitempty"` 78 79 // RequireTypeBase is set to mark that a snap needs to be of type: base, 80 // otherwise installation fails. 81 RequireTypeBase bool `json:"require-base-type,omitempty"` 82 83 // ApplySnapDevMode overrides allowing a snap to be installed if it is in 84 // devmode confinement. This is set to true for currently only UC20 model 85 // grades dangerous for all snaps during first boot, where we always allow 86 // devmode snaps to be installed, and installed with devmode confinement 87 // turned on. 88 // This may eventually be set for specific snaps mentioned in the model 89 // assertion for non-dangerous grade models too. 90 ApplySnapDevMode bool `json:"apply-snap-devmode,omitempty"` 91 } 92 93 // DevModeAllowed returns whether a snap can be installed with devmode 94 // confinement (either set or overridden). 95 func (f Flags) DevModeAllowed() bool { 96 return f.DevMode || f.JailMode || f.ApplySnapDevMode 97 } 98 99 // ForSnapSetup returns a copy of the Flags with the flags that we don't need in 100 // SnapSetup set to false (so they're not serialized). 101 func (f Flags) ForSnapSetup() Flags { 102 // TODO: consider using instead/also json:"-" in the struct? 103 f.SkipConfigure = false 104 f.NoReRefresh = false 105 f.RequireTypeBase = false 106 f.ApplySnapDevMode = false 107 return f 108 }