-
Notifications
You must be signed in to change notification settings - Fork 9
/
version.go
33 lines (29 loc) · 941 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the EARLY ACCESS SOFTWARE LICENSE AGREEMENT
// available at http://github.com/namespacelabs/foundation
package nsboot
import (
"encoding/json"
"os"
"google.golang.org/protobuf/encoding/protojson"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/schema/storage"
)
func GetBootVersion() (*storage.NamespaceBinaryVersion, error) {
versionJSON, have := os.LookupEnv("NSBOOT_VERSION")
if !have {
return nil, nil
}
var errorStruct struct {
Err string `json:"error"`
}
json.Unmarshal([]byte(versionJSON), &errorStruct)
if errorStruct.Err != "" {
return nil, fnerrors.InternalError(errorStruct.Err)
}
r := &storage.NamespaceBinaryVersion{}
if err := protojson.Unmarshal([]byte(versionJSON), r); err != nil {
return nil, fnerrors.InternalError("malformed NSBOOT_VERSION in environment: %w", err)
}
return r, nil
}