2019-02-14 12:37:47 +03:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
2022-10-28 12:58:55 +03:00
|
|
|
"fmt"
|
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
"github.com/Masterminds/semver"
|
2022-10-28 12:58:55 +03:00
|
|
|
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
|
2019-02-14 12:37:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// ServerFeatureFlags indicates what features are supported by this
|
|
|
|
// version of server.
|
|
|
|
type ServerFeatureFlags struct {
|
|
|
|
HasAccessKey bool
|
2020-02-24 19:14:46 +03:00
|
|
|
|
2020-06-16 12:08:36 +03:00
|
|
|
HasAction bool
|
|
|
|
HasCronTriggers bool
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const adminSecretVersion = "v1.0.0-alpha38"
|
2020-02-24 19:14:46 +03:00
|
|
|
const actionVersion = "v1.2.0-beta.1"
|
2020-06-16 12:08:36 +03:00
|
|
|
const cronTriggersVersion = "v1.3.0-beta.1"
|
2019-02-14 12:37:47 +03:00
|
|
|
|
|
|
|
// GetServerFeatureFlags returns the feature flags for server.
|
2020-02-24 19:14:46 +03:00
|
|
|
func (v *Version) GetServerFeatureFlags() error {
|
2022-10-28 12:58:55 +03:00
|
|
|
var op errors.Op = "version.GetServerFeatureFlags"
|
2019-02-14 12:37:47 +03:00
|
|
|
flags := &ServerFeatureFlags{}
|
2020-02-24 19:14:46 +03:00
|
|
|
if v.ServerSemver == nil {
|
|
|
|
flags.HasAccessKey = false
|
|
|
|
flags.HasAction = true
|
|
|
|
} else {
|
|
|
|
// create a constraint to check if the current server version has admin secret
|
|
|
|
adminSecretConstraint, err := semver.NewConstraint("< " + adminSecretVersion)
|
|
|
|
if err != nil {
|
2022-10-28 12:58:55 +03:00
|
|
|
return errors.E(op, fmt.Errorf("building admin secret constraint failed: %w", err))
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
|
|
|
// check the current version with the constraint
|
|
|
|
flags.HasAccessKey = adminSecretConstraint.Check(v.ServerSemver)
|
2019-02-14 12:37:47 +03:00
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
// create a constraint to check if the current server version has actions
|
|
|
|
actionConstraint, err := semver.NewConstraint(">= " + actionVersion)
|
|
|
|
if err != nil {
|
2022-10-28 12:58:55 +03:00
|
|
|
return errors.E(op, fmt.Errorf("building action constraint failed: %w", err))
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
|
|
|
// check the current version with the constraint
|
|
|
|
flags.HasAction = actionConstraint.Check(v.ServerSemver)
|
2020-06-16 12:08:36 +03:00
|
|
|
|
|
|
|
// cronTriggers Constraint
|
|
|
|
cronTriggersConstraint, err := semver.NewConstraint(">= " + cronTriggersVersion)
|
|
|
|
if err != nil {
|
2022-10-28 12:58:55 +03:00
|
|
|
return errors.E(op, fmt.Errorf("building cron triggers constraint failed: %w", err))
|
2020-06-16 12:08:36 +03:00
|
|
|
}
|
|
|
|
// check the current version with the constraint
|
|
|
|
flags.HasCronTriggers = cronTriggersConstraint.Check(v.ServerSemver)
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
2020-02-24 19:14:46 +03:00
|
|
|
v.ServerFeatureFlags = flags
|
|
|
|
return nil
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|