aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/app.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-04-12 13:56:41 +0900
committerOphestra <cat@gensokyo.uk>2025-04-12 13:56:41 +0900
commit6309469e933a31a300fbf16d8e77f48dcee402d3 (patch)
tree8f8a72ee02b3ca15b104a6e55c9379e20f8d7e8a /internal/app/app.go
parent0d7c1a9a4356614f035225aeb24e66421879a99b (diff)
app/instance: wrap internal implementation
This reduces the scope of the fst package, which was growing questionably large. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/app.go')
-rw-r--r--internal/app/app.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/app/app.go b/internal/app/app.go
new file mode 100644
index 00000000..325d9f87
--- /dev/null
+++ b/internal/app/app.go
@@ -0,0 +1,59 @@
+// Package app defines the generic [App] interface.
+package app
+
+import (
+ "syscall"
+ "time"
+
+ "git.gensokyo.uk/security/fortify/fst"
+)
+
+type App interface {
+ // ID returns a copy of [ID] held by App.
+ ID() ID
+
+ // Seal determines the outcome of config as a [SealedApp].
+ // The value of config might be overwritten and must not be used again.
+ Seal(config *fst.Config) (SealedApp, error)
+
+ String() string
+}
+
+type SealedApp interface {
+ // Run commits sealed system setup and starts the app process.
+ Run(rs *RunState) error
+}
+
+// RunState stores the outcome of a call to [SealedApp.Run].
+type RunState struct {
+ // Time is the exact point in time where the process was created.
+ // Location must be set to UTC.
+ //
+ // Time is nil if no process was ever created.
+ Time *time.Time
+ // RevertErr is stored by the deferred revert call.
+ RevertErr error
+ // WaitErr is the generic error value created by the standard library.
+ WaitErr error
+
+ syscall.WaitStatus
+}
+
+// SetStart stores the current time in [RunState] once.
+func (rs *RunState) SetStart() {
+ if rs.Time != nil {
+ panic("attempted to store time twice")
+ }
+ now := time.Now().UTC()
+ rs.Time = &now
+}
+
+// Paths contains environment-dependent paths used by fortify.
+type Paths struct {
+ // path to shared directory (usually `/tmp/fortify.%d`)
+ SharePath string `json:"share_path"`
+ // XDG_RUNTIME_DIR value (usually `/run/user/%d`)
+ RuntimePath string `json:"runtime_path"`
+ // application runtime directory (usually `/run/user/%d/fortify`)
+ RunDirPath string `json:"run_dir_path"`
+}