make status values configurable

This commit is contained in:
Michael Barz
2022-05-06 16:41:52 +02:00
parent 4ce35acf01
commit 5f0c635f92
7 changed files with 74 additions and 18 deletions

View File

@@ -4,17 +4,12 @@ import (
"path"
"strconv"
"github.com/Masterminds/semver"
"github.com/owncloud/ocis/v2/extensions/frontend/pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
)
// FrontendConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func FrontendConfigFromStruct(cfg *config.Config) map[string]interface{} {
parsedVersion, err := semver.NewVersion(version.String)
if err != nil {
parsedVersion, _ = semver.NewVersion("0.0.0")
}
archivers := []map[string]interface{}{
{
"enabled": true,
@@ -144,10 +139,11 @@ func FrontendConfigFromStruct(cfg *config.Config) map[string]interface{} {
"installed": true,
"maintenance": false,
"needsDbUpgrade": false,
"version": version.String + ".0",
"versionstring": version.String,
"version": version.Long(),
"versionstring": version.GetString(),
"edition": "Community",
"productname": "oCIS",
"productname": "Infinite Scale",
"product": "oCIS",
"hostname": "",
},
"support_url_signing": true,
@@ -218,9 +214,9 @@ func FrontendConfigFromStruct(cfg *config.Config) map[string]interface{} {
"version": map[string]interface{}{
"product": "oCIS",
"edition": "Community",
"major": parsedVersion.Major(),
"minor": parsedVersion.Minor(),
"micro": parsedVersion.Patch(),
"major": version.Parsed().Major(),
"minor": version.Parsed().Minor(),
"micro": version.Parsed().Patch(),
"string": version.String,
},
},

View File

@@ -55,6 +55,11 @@ func Server(cfg *config.Config) *cli.Command {
ocdav.Prefix(cfg.HTTP.Prefix),
ocdav.GatewaySvc(cfg.Reva.Address),
ocdav.JWTSecret(cfg.TokenManager.JWTSecret),
ocdav.ProductName(cfg.Status.ProductName),
ocdav.Product(cfg.Status.Product),
ocdav.Version(cfg.Status.Version),
ocdav.VersionString(cfg.Status.VersionString),
ocdav.Edition(cfg.Status.Edition),
// ocdav.FavoriteManager() // FIXME needs a proper persistence implementation
// ocdav.LockSystem(), // will default to the CS3 lock system
// ocdav.TLSConfig() // tls config for the http server

View File

@@ -33,6 +33,7 @@ type Config struct {
Middleware Middleware `yaml:"middleware"`
Context context.Context `yaml:"-"`
Status Status `yaml:"-"`
}
type Tracing struct {
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;OCDAV_TRACING_ENABLED" desc:"Activates tracing."`
@@ -75,3 +76,12 @@ type Middleware struct {
type Auth struct {
CredentialsByUserAgent map[string]string `yaml:"credentials_by_user_agent"`
}
// Status holds the configurable values for the status.php
type Status struct {
Version string
VersionString string
Product string
ProductName string
Edition string
}

View File

@@ -2,6 +2,7 @@ package defaults
import (
"github.com/owncloud/ocis/v2/extensions/ocdav/pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/version"
)
func FullDefaultConfig() *config.Config {
@@ -42,6 +43,13 @@ func DefaultConfig() *config.Config {
CredentialsByUserAgent: map[string]string{},
},
},
Status: config.Status{
Version: version.Long(),
VersionString: version.GetString(),
Product: "oCIS",
ProductName: "Infinite Scale",
Edition: "Community",
},
}
}

2
go.mod
View File

@@ -11,7 +11,7 @@ require (
github.com/blevesearch/bleve_index_api v1.0.1
github.com/coreos/go-oidc/v3 v3.1.0
github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde
github.com/cs3org/reva/v2 v2.3.1-0.20220506133959-1ad146903c6f
github.com/cs3org/reva/v2 v2.3.1-0.20220506154310-71844dde23d4
github.com/disintegration/imaging v1.6.2
github.com/glauth/glauth/v2 v2.0.0-20211021011345-ef3151c28733
github.com/go-chi/chi/v5 v5.0.7

6
go.sum
View File

@@ -318,10 +318,8 @@ github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde h1:WrD9O8ZaWvsm0
github.com/cs3org/go-cs3apis v0.0.0-20220412090512-93c5918b4bde/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva v1.18.0 h1:MbPS5ZAa8RzKcTxAVeSDdISB3XXqLIxqB03BTN5ReBY=
github.com/cs3org/reva v1.18.0/go.mod h1:e5VDUDu4vVWIeVkZcW//n6UZzhGGMa+Tz/whCiX3N6o=
github.com/cs3org/reva/v2 v2.3.0 h1:AwDwqqzAKTrkBz1ifOy3U92C12zk92uBw6LyhLAjCBc=
github.com/cs3org/reva/v2 v2.3.0/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng=
github.com/cs3org/reva/v2 v2.3.1-0.20220506133959-1ad146903c6f h1:1vv8pODAoBgFGCP7UGoQCxvY6hK3vb6KirlqUNRcRys=
github.com/cs3org/reva/v2 v2.3.1-0.20220506133959-1ad146903c6f/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng=
github.com/cs3org/reva/v2 v2.3.1-0.20220506154310-71844dde23d4 h1:nr35Kdfp8lnYTxissRlgqIOirIe2NpE3+OEq4GRbGDg=
github.com/cs3org/reva/v2 v2.3.1-0.20220506154310-71844dde23d4/go.mod h1:2e/4HcIy54Mic3V7Ow0bz4n5dkZU0dHIZSWomFe5vng=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=

View File

@@ -1,15 +1,18 @@
package version
import (
"strconv"
"time"
"github.com/Masterminds/semver"
)
var (
// String gets defined by the build system.
String = "0.0.0"
String = "dev"
// Date indicates the build date.
Date = "00000000"
Date = time.Now().Format("20060102")
)
// Compiled returns the compile time of this service.
@@ -17,3 +20,39 @@ func Compiled() time.Time {
t, _ := time.Parse("20060102", Date)
return t
}
func GetString() string {
if String == "dev" {
return "0.0.0+dev"
}
parsedVersion, err := semver.NewVersion(String)
// We have no semver version but a commitid
if err != nil {
return String
}
return parsedVersion.String()
}
func Parsed() *semver.Version {
var versionToParse string
if String == "dev" {
versionToParse = "0.0.0+dev"
}
parsedVersion, err := semver.NewVersion(versionToParse)
// We have no semver version but a commitid
if err != nil {
parsedVersion, _ = semver.NewVersion("0.0.0+" + String)
}
return parsedVersion
}
func Long() string {
var s string
if Parsed().Metadata() == "" {
s = "-" + Parsed().Prerelease()
}
s = "+" + Parsed().Metadata()
return strconv.FormatInt(Parsed().Major(), 10) + "." +
strconv.FormatInt(Parsed().Minor(), 10) + "." +
strconv.FormatInt(Parsed().Patch(), 10) + "." + "0" + s
}