settings.go

 1package backend
 2
 3import (
 4	"context"
 5
 6	"github.com/charmbracelet/soft-serve/pkg/access"
 7	"github.com/charmbracelet/soft-serve/pkg/db"
 8)
 9
10// AllowKeyless returns whether or not keyless access is allowed.
11//
12// It implements backend.Backend.
13func (b *Backend) AllowKeyless(ctx context.Context) bool {
14	var allow bool
15	if err := b.db.TransactionContext(ctx, func(tx *db.Tx) error {
16		var err error
17		allow, err = b.store.GetAllowKeylessAccess(ctx, tx)
18		return err //nolint:wrapcheck
19	}); err != nil {
20		return false
21	}
22
23	return allow
24}
25
26// SetAllowKeyless sets whether or not keyless access is allowed.
27//
28// It implements backend.Backend.
29func (b *Backend) SetAllowKeyless(ctx context.Context, allow bool) error {
30	return b.db.TransactionContext(ctx, func(tx *db.Tx) error { //nolint:wrapcheck
31		return b.store.SetAllowKeylessAccess(ctx, tx, allow)
32	})
33}
34
35// AnonAccess returns the level of anonymous access.
36//
37// It implements backend.Backend.
38func (b *Backend) AnonAccess(ctx context.Context) access.AccessLevel {
39	var level access.AccessLevel
40	if err := b.db.TransactionContext(ctx, func(tx *db.Tx) error {
41		var err error
42		level, err = b.store.GetAnonAccess(ctx, tx)
43		return err //nolint:wrapcheck
44	}); err != nil {
45		return access.NoAccess
46	}
47
48	return level
49}
50
51// SetAnonAccess sets the level of anonymous access.
52//
53// It implements backend.Backend.
54func (b *Backend) SetAnonAccess(ctx context.Context, level access.AccessLevel) error {
55	return b.db.TransactionContext(ctx, func(tx *db.Tx) error { //nolint:wrapcheck
56		return b.store.SetAnonAccess(ctx, tx, level)
57	})
58}