Skip to content

Commit 4ab17f2

Browse files
committed
feat: Report hardened version
Show `(hardened)` next to version number in CLI.
1 parent 394f1b8 commit 4ab17f2

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

cmd/config.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ import (
88
"os/signal"
99
"strings"
1010
"time"
11+
12+
"github.com/macie/opinions/security"
1113
)
1214

1315
// AppConfig represets current app configuration.
1416
type AppConfig struct {
17+
appVersion string
1518
Query string
1619
Timeout time.Duration
17-
Version string
1820
ShowVersion bool
1921
}
2022

2123
// NewAppConfig combines command line arguments and app version into AppConfig.
2224
func NewAppConfig(cliArgs []string, appVersion string) (AppConfig, error) {
23-
if appVersion == "" {
24-
appVersion = time.Now().Format("2006.01.02-dev150405")
25-
}
2625
config := AppConfig{
27-
Version: appVersion,
26+
appVersion: appVersion,
2827
}
2928
f := flag.NewFlagSet("opinions", flag.ContinueOnError)
3029

@@ -46,6 +45,19 @@ func NewAppConfig(cliArgs []string, appVersion string) (AppConfig, error) {
4645
return config, nil
4746
}
4847

48+
// Version returns string with full version description.
49+
func (c *AppConfig) Version() string {
50+
ver := c.appVersion
51+
if ver == "" {
52+
ver = time.Now().Format("2006.01.02-dev150405")
53+
}
54+
build := ""
55+
if security.IsHardened {
56+
build = " (hardened)"
57+
}
58+
return fmt.Sprintf("opinions %s%s\n", ver, build)
59+
}
60+
4961
// NewAppContext creates cancellable app context with optional timeout.
5062
func NewAppContext(config AppConfig) (context.Context, context.CancelFunc) {
5163
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
os.Exit(1)
3030
}
3131
if config.ShowVersion {
32-
fmt.Fprintf(os.Stderr, "opinions %s\n", config.Version)
32+
fmt.Fprint(os.Stderr, config.Version())
3333
os.Exit(0)
3434
}
3535

security/sandbox.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package security
66

7-
// Sandbox restrict access to system resources. Currently only works on OpenBSD.
7+
// IsHardened reports whether security sandbox is enabled.
8+
const IsHardened = false
9+
10+
// Sandbox restrict access to system resources.
811
func Sandbox() error {
912
return nil
1013
}

security/sandbox_openbsd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package security
44

55
import "golang.org/x/sys/unix"
66

7+
// IsHardened reports whether security sandbox is enabled.
8+
const IsHardened = true
9+
710
// Sandbox restrict application access to necessary system calls needed by
811
// network connections and standard i/o.
912
//

0 commit comments

Comments
 (0)