mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-11 10:46:25 +03:00
This commit is contained in:
parent
d7ca702542
commit
5a648a9bb2
@ -7,6 +7,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
crontriggers "github.com/hasura/graphql-engine/cli/metadata/cron_triggers"
|
||||||
|
|
||||||
"github.com/hasura/graphql-engine/cli/metadata/actions"
|
"github.com/hasura/graphql-engine/cli/metadata/actions"
|
||||||
"github.com/hasura/graphql-engine/cli/metadata/actions/types"
|
"github.com/hasura/graphql-engine/cli/metadata/actions/types"
|
||||||
"github.com/hasura/graphql-engine/cli/metadata/allowlist"
|
"github.com/hasura/graphql-engine/cli/metadata/allowlist"
|
||||||
@ -251,6 +253,7 @@ func (o *InitOptions) createFiles() error {
|
|||||||
plugins = append(plugins, allowlist.New(o.EC, o.EC.MetadataDir))
|
plugins = append(plugins, allowlist.New(o.EC, o.EC.MetadataDir))
|
||||||
plugins = append(plugins, remoteschemas.New(o.EC, o.EC.MetadataDir))
|
plugins = append(plugins, remoteschemas.New(o.EC, o.EC.MetadataDir))
|
||||||
plugins = append(plugins, actions.New(o.EC, o.EC.MetadataDir))
|
plugins = append(plugins, actions.New(o.EC, o.EC.MetadataDir))
|
||||||
|
plugins = append(plugins, crontriggers.New(o.EC, o.EC.MetadataDir))
|
||||||
for _, plg := range plugins {
|
for _, plg := range plugins {
|
||||||
err := plg.CreateFiles()
|
err := plg.CreateFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
[]
|
@ -0,0 +1 @@
|
|||||||
|
[]
|
100
cli/metadata/cron_triggers/cron_triggers.go
Normal file
100
cli/metadata/cron_triggers/cron_triggers.go
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
package crontriggers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/hasura/graphql-engine/cli/version"
|
||||||
|
|
||||||
|
"github.com/hasura/graphql-engine/cli"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
fileName string = "cron_triggers.yaml"
|
||||||
|
metadataKey = "cron_triggers"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CronTriggers struct {
|
||||||
|
MetadataDir string
|
||||||
|
|
||||||
|
logger *logrus.Logger
|
||||||
|
serverFeatureFlags *version.ServerFeatureFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(ec *cli.ExecutionContext, baseDir string) *CronTriggers {
|
||||||
|
return &CronTriggers{
|
||||||
|
MetadataDir: baseDir,
|
||||||
|
logger: ec.Logger,
|
||||||
|
serverFeatureFlags: ec.Version.ServerFeatureFlags,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CronTriggers) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CronTriggers) CreateFiles() error {
|
||||||
|
v := make([]interface{}, 0)
|
||||||
|
data, err := yaml.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(filepath.Join(c.MetadataDir, fileName), data, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CronTriggers) Build(metadata *yaml.MapSlice) error {
|
||||||
|
if !c.serverFeatureFlags.HasCronTriggers {
|
||||||
|
c.logger.WithField("metadata_plugin", "cron_triggers").Warnf("Skipping building %s", fileName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(c.MetadataDir, fileName))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
item := yaml.MapItem{
|
||||||
|
Key: metadataKey,
|
||||||
|
Value: []yaml.MapSlice{},
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(data, &item.Value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*metadata = append(*metadata, item)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CronTriggers) Export(metadata yaml.MapSlice) (map[string][]byte, error) {
|
||||||
|
if !c.serverFeatureFlags.HasCronTriggers {
|
||||||
|
c.logger.Debugf("Skipping creating %s", fileName)
|
||||||
|
return make(map[string][]byte), nil
|
||||||
|
}
|
||||||
|
var cronTriggers interface{}
|
||||||
|
for _, item := range metadata {
|
||||||
|
k, ok := item.Key.(string)
|
||||||
|
if !ok || k != metadataKey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cronTriggers = item.Value
|
||||||
|
}
|
||||||
|
if cronTriggers == nil {
|
||||||
|
cronTriggers = make([]interface{}, 0)
|
||||||
|
}
|
||||||
|
data, err := yaml.Marshal(cronTriggers)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string][]byte{
|
||||||
|
filepath.Join(c.MetadataDir, fileName): data,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CronTriggers) Name() string {
|
||||||
|
return metadataKey
|
||||||
|
}
|
@ -9,6 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
crontriggers "github.com/hasura/graphql-engine/cli/metadata/cron_triggers"
|
||||||
|
|
||||||
"github.com/hasura/graphql-engine/cli/metadata"
|
"github.com/hasura/graphql-engine/cli/metadata"
|
||||||
"github.com/hasura/graphql-engine/cli/metadata/actions"
|
"github.com/hasura/graphql-engine/cli/metadata/actions"
|
||||||
"github.com/hasura/graphql-engine/cli/metadata/allowlist"
|
"github.com/hasura/graphql-engine/cli/metadata/allowlist"
|
||||||
@ -172,6 +174,7 @@ func SetMetadataPluginsWithDir(ec *cli.ExecutionContext, drv *Migrate, dir ...st
|
|||||||
plugins = append(plugins, allowlist.New(ec, metadataDir))
|
plugins = append(plugins, allowlist.New(ec, metadataDir))
|
||||||
plugins = append(plugins, remoteschemas.New(ec, metadataDir))
|
plugins = append(plugins, remoteschemas.New(ec, metadataDir))
|
||||||
plugins = append(plugins, actions.New(ec, metadataDir))
|
plugins = append(plugins, actions.New(ec, metadataDir))
|
||||||
|
plugins = append(plugins, crontriggers.New(ec, metadataDir))
|
||||||
} else {
|
} else {
|
||||||
plugins = append(plugins, metadata.New(ec, ec.MigrationDir))
|
plugins = append(plugins, metadata.New(ec, ec.MigrationDir))
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,13 @@ import (
|
|||||||
type ServerFeatureFlags struct {
|
type ServerFeatureFlags struct {
|
||||||
HasAccessKey bool
|
HasAccessKey bool
|
||||||
|
|
||||||
HasAction bool
|
HasAction bool
|
||||||
|
HasCronTriggers bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminSecretVersion = "v1.0.0-alpha38"
|
const adminSecretVersion = "v1.0.0-alpha38"
|
||||||
const actionVersion = "v1.2.0-beta.1"
|
const actionVersion = "v1.2.0-beta.1"
|
||||||
|
const cronTriggersVersion = "v1.3.0-beta.1"
|
||||||
|
|
||||||
// GetServerFeatureFlags returns the feature flags for server.
|
// GetServerFeatureFlags returns the feature flags for server.
|
||||||
func (v *Version) GetServerFeatureFlags() error {
|
func (v *Version) GetServerFeatureFlags() error {
|
||||||
@ -38,6 +40,14 @@ func (v *Version) GetServerFeatureFlags() error {
|
|||||||
}
|
}
|
||||||
// check the current version with the constraint
|
// check the current version with the constraint
|
||||||
flags.HasAction = actionConstraint.Check(v.ServerSemver)
|
flags.HasAction = actionConstraint.Check(v.ServerSemver)
|
||||||
|
|
||||||
|
// cronTriggers Constraint
|
||||||
|
cronTriggersConstraint, err := semver.NewConstraint(">= " + cronTriggersVersion)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "building cron triggers constraint failed")
|
||||||
|
}
|
||||||
|
// check the current version with the constraint
|
||||||
|
flags.HasCronTriggers = cronTriggersConstraint.Check(v.ServerSemver)
|
||||||
}
|
}
|
||||||
v.ServerFeatureFlags = flags
|
v.ServerFeatureFlags = flags
|
||||||
return nil
|
return nil
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
[]
|
Loading…
Reference in New Issue
Block a user