More flexible "compose", move to Corteza
- more control over starting procedure, cli commands... - fix package paths - renaming symbols, comments, strings from Crust to Corteza
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
|
||||
migrate "github.com/cortezaproject/corteza-server/compose/db"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest"
|
||||
"github.com/cortezaproject/corteza-server/internal/db"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/api"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli/flags"
|
||||
)
|
||||
|
||||
const (
|
||||
compose = "compose"
|
||||
)
|
||||
|
||||
type (
|
||||
Compose struct {
|
||||
log *zap.Logger
|
||||
|
||||
// General
|
||||
logOpt *flags.LogOpt
|
||||
smtpOpt *flags.SMTPOpt
|
||||
jwtOpt *flags.JWTOpt
|
||||
httpClientOpt *flags.HttpClientOpt
|
||||
|
||||
// Compose specific
|
||||
dbOpt *flags.DBOpt
|
||||
provisionOpt *flags.ProvisionOpt
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger.Init(zap.DebugLevel)
|
||||
}
|
||||
|
||||
func InitCompose() *Compose {
|
||||
return &Compose{
|
||||
log: logger.Default().Named(compose),
|
||||
}
|
||||
}
|
||||
|
||||
// Command produces cobra.Command
|
||||
func (m *Compose) Command(ctx context.Context) (cmd *cobra.Command) {
|
||||
cmd = &cobra.Command{
|
||||
Use: "corteza-server-compose",
|
||||
TraverseChildren: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
cli.InitGeneralServices(m.logOpt, m.smtpOpt, m.jwtOpt, m.httpClientOpt)
|
||||
|
||||
return m.StartServices(ctx)
|
||||
},
|
||||
}
|
||||
|
||||
m.BindGlobalFlags(cmd)
|
||||
|
||||
srv := api.NewServer(m.log)
|
||||
serveApiCmd := srv.Command(ctx, compose, m.ApiServerPreRun)
|
||||
|
||||
// Bind all flags we need for serving compose
|
||||
m.BindApiServerFlags(serveApiCmd)
|
||||
|
||||
srv.MountRoutes(m.ApiServerRoutes)
|
||||
|
||||
cmd.AddCommand(
|
||||
serveApiCmd,
|
||||
cli.SetupProvisionSubcommands(ctx, m),
|
||||
)
|
||||
|
||||
m.AddCommands(cmd, ctx)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AddCommands - other commands that this subservice needs
|
||||
func (m *Compose) AddCommands(cmd *cobra.Command, ctx context.Context) {}
|
||||
|
||||
// Binds all global flags
|
||||
func (m *Compose) BindGlobalFlags(cmd *cobra.Command) {
|
||||
m.logOpt = flags.Log(cmd)
|
||||
m.smtpOpt = flags.SMTP(cmd)
|
||||
m.jwtOpt = flags.JWT(cmd)
|
||||
m.httpClientOpt = flags.HttpClient(cmd)
|
||||
}
|
||||
|
||||
// BindApiServerFlags sets & binds all API server flags
|
||||
func (m *Compose) BindApiServerFlags(cmd *cobra.Command) {
|
||||
m.dbOpt = flags.DB(cmd, compose)
|
||||
m.provisionOpt = flags.Provision(cmd, compose)
|
||||
}
|
||||
|
||||
// StartServices
|
||||
func (m *Compose) StartServices(ctx context.Context) (err error) {
|
||||
_, err = db.TryToConnect(ctx, m.log, compose, m.dbOpt.DSN, m.dbOpt.Profiler)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not connect to database")
|
||||
}
|
||||
|
||||
if m.provisionOpt.Database {
|
||||
err = m.ProvisionMigrateDatabase(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = service.Init(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// ApiServerPreRun is executed before serve-api command runs REST API server
|
||||
//
|
||||
// Should initialize all that needs to run in the background
|
||||
func (m Compose) ApiServerPreRun(ctx context.Context) error {
|
||||
service.DefaultPermissions.Watch(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApiServerRoutes mounts api server routes
|
||||
func (m *Compose) ApiServerRoutes(r chi.Router) {
|
||||
rest.MountRoutes(r)
|
||||
}
|
||||
|
||||
// ProvisionMigrateDatabase migrates database to new version
|
||||
//
|
||||
// This is ran by default on serve-api (when not explicitly disabled with --compose-provision-database=false)
|
||||
// or on demand with "provision migrate-database"
|
||||
func (m Compose) ProvisionMigrateDatabase(ctx context.Context) error {
|
||||
var db, err = factory.Database.Get(compose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db = db.With(ctx)
|
||||
// Disable profiler for migrations
|
||||
db.Profiler = nil
|
||||
|
||||
return migrate.Migrate(db)
|
||||
}
|
||||
|
||||
// ProvisionAccessControl resets access-control rules for roles admin (2) and everyone (1)
|
||||
//
|
||||
// Run with emand with "provision access-control-rules"
|
||||
func (m Compose) ProvisionAccessControl(ctx context.Context) error {
|
||||
var ac = service.DefaultAccessControl
|
||||
return ac.Grant(ctx, ac.DefaultRules()...)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/db/mysql"
|
||||
"github.com/cortezaproject/corteza-server/compose/db/mysql"
|
||||
)
|
||||
|
||||
func statements(contents []byte, err error) ([]string, error) {
|
||||
@@ -31,13 +31,16 @@ func Migrate(db *factory.DB) error {
|
||||
|
||||
var files []string
|
||||
|
||||
if err := fs.Walk(statikFS, "/", func(filename string, info os.FileInfo, err error) error {
|
||||
fn := func(filename string, info os.FileInfo, err error) error {
|
||||
_ = err
|
||||
matched, err := filepath.Match("/*.up.sql", filename)
|
||||
if matched {
|
||||
files = append(files, filename)
|
||||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
}
|
||||
|
||||
if err = fs.Walk(statikFS, "/", fn); err != nil {
|
||||
return errors.Wrap(err, "Error when listing files for migrations")
|
||||
}
|
||||
|
||||
|
||||
@@ -3,27 +3,15 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/namsral/flag"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
func TestMigrations(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode.")
|
||||
return
|
||||
}
|
||||
|
||||
var dsn string
|
||||
|
||||
flag.StringVar(&dsn, "db-dsn", "crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
flag.Parse()
|
||||
|
||||
factory.Database.Add("default", dsn)
|
||||
factory.Database.Add("system", dsn)
|
||||
|
||||
db := factory.Database.MustGet()
|
||||
factory.Database.Add("compose", os.Getenv("COMPOSE_DB_DSN"))
|
||||
db := factory.Database.MustGet("compose")
|
||||
if err := Migrate(db); err != nil {
|
||||
t.Fatalf("Unexpected error: %+v", err)
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/internal/config"
|
||||
)
|
||||
|
||||
type (
|
||||
appFlags struct {
|
||||
smtp *config.SMTP
|
||||
http *config.HTTP
|
||||
monitor *config.Monitor
|
||||
db *config.Database
|
||||
repository *repository.Flags
|
||||
jwt *config.JWT
|
||||
}
|
||||
)
|
||||
|
||||
var flags *appFlags
|
||||
|
||||
func (c *appFlags) Validate() error {
|
||||
if c == nil {
|
||||
return errors.New("Flags are not initialized, need to call Flags()")
|
||||
}
|
||||
if err := c.http.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.smtp.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.monitor.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.db.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.repository.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Flags(prefix ...string) {
|
||||
if flags != nil {
|
||||
return
|
||||
}
|
||||
if len(prefix) == 0 {
|
||||
panic("Flags() needs prefix on first call")
|
||||
}
|
||||
|
||||
flags = &appFlags{
|
||||
new(config.SMTP).Init(prefix...),
|
||||
new(config.HTTP).Init(prefix...),
|
||||
new(config.Monitor).Init(prefix...),
|
||||
new(config.Database).Init(prefix...),
|
||||
new(repository.Flags).Init(prefix...),
|
||||
new(config.JWT).Init(),
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -115,6 +115,7 @@ func (r attachment) Find(filter types.AttachmentFilter) (set types.AttachmentSet
|
||||
}
|
||||
default:
|
||||
err = errors.New("unsupported kind value")
|
||||
return
|
||||
}
|
||||
|
||||
if f.Filter != "" {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
repositoryError string
|
||||
)
|
||||
@@ -17,9 +13,5 @@ func (e repositoryError) Error() string {
|
||||
}
|
||||
|
||||
func (e repositoryError) String() string {
|
||||
return "crust.compose.repository." + string(e)
|
||||
}
|
||||
|
||||
func (e repositoryError) new() error {
|
||||
return errors.WithStack(e)
|
||||
return "compose.repository." + string(e)
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
_ "github.com/crusttech/crust/internal/config"
|
||||
)
|
||||
|
||||
type (
|
||||
Flags struct {
|
||||
// No config yet
|
||||
}
|
||||
)
|
||||
|
||||
var flags *Flags
|
||||
|
||||
func (f *Flags) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *Flags) Init(prefix ...string) *Flags {
|
||||
if flags != nil {
|
||||
return flags
|
||||
}
|
||||
flags = &Flags{}
|
||||
return flags
|
||||
}
|
||||
@@ -7,20 +7,18 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/namsral/flag"
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
|
||||
dsn := ""
|
||||
flag.StringVar(&dsn, "compose-db-dsn", "", "")
|
||||
flag.Parse()
|
||||
factory.Database.Add("compose", dsn)
|
||||
factory.Database.Add("compose", os.Getenv("COMPOSE_DB_DSN"))
|
||||
db := factory.Database.MustGet("compose")
|
||||
db.Profiler = &factory.DatabaseProfilerStdout{}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository/ql"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository/ql"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository/ql"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository/ql"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,8 +3,8 @@ package repository
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestRecordReportBuilder2(t *testing.T) {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestRepository(t *testing.T) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,8 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -17,11 +17,11 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/store"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/internal/store"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -298,10 +298,10 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
|
||||
if imaging.JPEG == format {
|
||||
// Rotate image if needed
|
||||
if preview, _, err = exiffix.Decode(original); err != nil {
|
||||
//return errors.Wrapf(err, "Could not decode EXIF from JPEG")
|
||||
}
|
||||
|
||||
// if preview, _, err = exiffix.Decode(original); err != nil {
|
||||
// return errors.Wrapf(err, "Could not decode EXIF from JPEG")
|
||||
// }
|
||||
preview, _, _ = exiffix.Decode(original)
|
||||
}
|
||||
|
||||
if imaging.GIF == format {
|
||||
@@ -346,7 +346,7 @@ func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment
|
||||
width, height = preview.Bounds().Max.X, preview.Bounds().Max.Y
|
||||
|
||||
var buf = &bytes.Buffer{}
|
||||
if err = imaging.Encode(buf, preview, previewFormat); err != nil {
|
||||
if err = imaging.Encode(buf, preview, previewFormat, opts...); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -66,9 +64,9 @@ func (svc chart) With(ctx context.Context) ChartService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc chart) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc chart) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc chart) FindByID(namespaceID, chartID uint64) (c *types.Chart, err error) {
|
||||
if namespaceID == 0 {
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestChart(t *testing.T) {
|
||||
|
||||
@@ -26,7 +26,7 @@ func (e serviceError) Error() string {
|
||||
}
|
||||
|
||||
func (e serviceError) String() string {
|
||||
return "crust.compose.service." + string(e)
|
||||
return "compose.service." + string(e)
|
||||
}
|
||||
|
||||
func (e serviceError) withStack() error {
|
||||
|
||||
@@ -9,14 +9,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/namsral/flag"
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
composeMigrate "github.com/crusttech/crust/compose/db"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
composeMigrate "github.com/cortezaproject/corteza-server/compose/db"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -28,12 +27,7 @@ func (mockDB) Transaction(callback func() error) error { return callback() }
|
||||
func TestMain(m *testing.M) {
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
|
||||
dsn := ""
|
||||
flag.StringVar(&dsn, "compose-db-dsn", "", "")
|
||||
flag.Parse()
|
||||
|
||||
factory.Database.Add("compose", dsn)
|
||||
|
||||
factory.Database.Add("compose", os.Getenv("COMPOSE_DB_DSN"))
|
||||
db := factory.Database.MustGet("compose")
|
||||
db.Profiler = &factory.DatabaseProfilerStdout{}
|
||||
|
||||
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -68,9 +66,9 @@ func (svc module) With(ctx context.Context) ModuleService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc module) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc module) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc module) FindByID(namespaceID, moduleID uint64) (m *types.Module, err error) {
|
||||
if namespaceID == 0 {
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestModule(t *testing.T) {
|
||||
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -63,9 +61,9 @@ func (svc namespace) With(ctx context.Context) NamespaceService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc namespace) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc namespace) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc namespace) FindByID(ID uint64) (ns *types.Namespace, err error) {
|
||||
if ID == 0 {
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestNamespace(t *testing.T) {
|
||||
|
||||
@@ -6,11 +6,9 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
gomail "gopkg.in/mail.v2"
|
||||
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/mail"
|
||||
"github.com/cortezaproject/corteza-server/internal/mail"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -41,9 +39,9 @@ func (svc notification) With(ctx context.Context) NotificationService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc notification) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc notification) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc notification) SendEmail(message *gomail.Message) error {
|
||||
return mail.Send(message)
|
||||
|
||||
@@ -6,11 +6,9 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -74,9 +72,9 @@ func (svc page) With(ctx context.Context) PageService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc page) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc page) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc page) FindByID(namespaceID, pageID uint64) (p *types.Page, err error) {
|
||||
return svc.checkPermissions(svc.pageRepo.FindByID(namespaceID, pageID))
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestPage(t *testing.T) {
|
||||
|
||||
@@ -8,12 +8,10 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,9 +75,9 @@ func (svc record) With(ctx context.Context) RecordService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc record) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc record) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc record) FindByID(namespaceID, recordID uint64) (r *types.Record, err error) {
|
||||
if namespaceID == 0 {
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestRecord(t *testing.T) {
|
||||
|
||||
@@ -6,17 +6,13 @@ import (
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/crusttech/crust/internal/store"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/store"
|
||||
)
|
||||
|
||||
type (
|
||||
db interface {
|
||||
Transaction(callback func() error) error
|
||||
}
|
||||
|
||||
permissionServicer interface {
|
||||
accessControlPermissionServicer
|
||||
Watch(ctx context.Context)
|
||||
@@ -24,7 +20,7 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
permSvc permissionServicer
|
||||
DefaultPermissions permissionServicer
|
||||
|
||||
DefaultLogger *zap.Logger
|
||||
|
||||
@@ -48,12 +44,12 @@ func Init(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
permSvc = permissions.Service(
|
||||
DefaultPermissions = permissions.Service(
|
||||
ctx,
|
||||
DefaultLogger,
|
||||
permissions.Repository(repository.DB(ctx), "compose_permission_rules"))
|
||||
|
||||
DefaultAccessControl = AccessControl(permSvc)
|
||||
DefaultAccessControl = AccessControl(DefaultPermissions)
|
||||
|
||||
DefaultRecord = Record()
|
||||
DefaultModule = Module()
|
||||
@@ -67,10 +63,6 @@ func Init(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Watchers(ctx context.Context) {
|
||||
permSvc.Watch(ctx)
|
||||
}
|
||||
|
||||
// Data is stale when new date does not match updatedAt or createdAt (before first update)
|
||||
func isStale(new *time.Time, updatedAt *time.Time, createdAt time.Time) bool {
|
||||
if new == nil {
|
||||
|
||||
@@ -5,11 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/repository"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/repository"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -66,9 +64,9 @@ func (svc trigger) With(ctx context.Context) TriggerService {
|
||||
}
|
||||
|
||||
// log() returns zap's logger with requestID from current context and fields.
|
||||
func (svc trigger) log(fields ...zapcore.Field) *zap.Logger {
|
||||
return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
}
|
||||
// func (svc trigger) log(fields ...zapcore.Field) *zap.Logger {
|
||||
// return logger.AddRequestID(svc.ctx, svc.logger).With(fields...)
|
||||
// }
|
||||
|
||||
func (svc trigger) FindByID(namespaceID, triggerID uint64) (t *types.Trigger, err error) {
|
||||
if namespaceID == 0 {
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
func TestTrigger(t *testing.T) {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
)
|
||||
|
||||
// Provision orchestrates various tasks after deployment
|
||||
//
|
||||
func Provision(ctx context.Context) (err error) {
|
||||
if err = resetDefaultPermissionRules(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// @todo move migration here
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Resets default permission rules for compose resources
|
||||
func resetDefaultPermissionRules(ctx context.Context) error {
|
||||
var ac = service.DefaultAccessControl
|
||||
|
||||
return ac.Grant(ctx, ac.DefaultRules()...)
|
||||
}
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/logger"
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
|
||||
@@ -3,7 +3,7 @@ package rest
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
)
|
||||
|
||||
func middlewareAllowedAccess(next http.Handler) http.Handler {
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,9 +3,9 @@ package rest
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/mail"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/mail"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/payload"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/internal/payload"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
@@ -26,9 +26,10 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
sqlxTypes "github.com/jmoiron/sqlx/types"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
sqlxTypes "github.com/jmoiron/sqlx/types"
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package request
|
||||
|
||||
//lint:file-ignore U1000 Ignore unused code, part of request pkg toolset
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -10,7 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var truthy = regexp.MustCompile("^\\s*(t(rue)?|y(es)?|1)\\s*$")
|
||||
var truthy = regexp.MustCompile(`^\s*(t(rue)?|y(es)?|1)\s*$`)
|
||||
|
||||
func parseJSONTextWithErr(s string) (types.JSONText, error) {
|
||||
result := &types.JSONText{}
|
||||
@@ -69,7 +71,7 @@ func parseUInt64(s string) uint64 {
|
||||
|
||||
func parseUInt64A(values []string) []uint64 {
|
||||
var result []uint64
|
||||
if values != nil && len(values) > 0 {
|
||||
if len(values) > 0 {
|
||||
for _, val := range values {
|
||||
result = append(result, parseUInt64(val))
|
||||
}
|
||||
|
||||
+20
-23
@@ -3,11 +3,11 @@ package rest
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest/handlers"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/handlers"
|
||||
"github.com/cortezaproject/corteza-server/internal/auth"
|
||||
)
|
||||
|
||||
func MountRoutes() func(chi.Router) {
|
||||
func MountRoutes(r chi.Router) {
|
||||
var (
|
||||
namespace = Namespace{}.New()
|
||||
module = Module{}.New()
|
||||
@@ -20,27 +20,24 @@ func MountRoutes() func(chi.Router) {
|
||||
)
|
||||
|
||||
// Initialize handlers & controllers.
|
||||
return func(r chi.Router) {
|
||||
r.Group(func(r chi.Router) {
|
||||
handlers.NewPermissions(Permissions{}.New()).MountRoutes(r)
|
||||
})
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
handlers.NewPermissions(Permissions{}.New()).MountRoutes(r)
|
||||
})
|
||||
// Protect all _private_ routes
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(auth.MiddlewareValidOnly)
|
||||
r.Use(middlewareAllowedAccess)
|
||||
|
||||
// Protect all _private_ routes
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(auth.MiddlewareValidOnly)
|
||||
r.Use(middlewareAllowedAccess)
|
||||
handlers.NewNamespace(namespace).MountRoutes(r)
|
||||
handlers.NewPage(page).MountRoutes(r)
|
||||
handlers.NewModule(module).MountRoutes(r)
|
||||
handlers.NewRecord(record).MountRoutes(r)
|
||||
handlers.NewChart(chart).MountRoutes(r)
|
||||
handlers.NewTrigger(trigger).MountRoutes(r)
|
||||
handlers.NewNotification(notification).MountRoutes(r)
|
||||
})
|
||||
|
||||
handlers.NewNamespace(namespace).MountRoutes(r)
|
||||
handlers.NewPage(page).MountRoutes(r)
|
||||
handlers.NewModule(module).MountRoutes(r)
|
||||
handlers.NewRecord(record).MountRoutes(r)
|
||||
handlers.NewChart(chart).MountRoutes(r)
|
||||
handlers.NewTrigger(trigger).MountRoutes(r)
|
||||
handlers.NewNotification(notification).MountRoutes(r)
|
||||
})
|
||||
|
||||
// Use alternative handlers that support file serving
|
||||
handlers.NewAttachment(attachment).MountRoutes(r)
|
||||
}
|
||||
// Use alternative handlers that support file serving
|
||||
handlers.NewAttachment(attachment).MountRoutes(r)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/compose/rest/request"
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/cortezaproject/corteza-server/compose/internal/service"
|
||||
"github.com/cortezaproject/corteza-server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza-server/compose/types"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"github.com/crusttech/crust/compose/rest"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/config"
|
||||
"github.com/crusttech/crust/internal/middleware"
|
||||
)
|
||||
|
||||
func Routes(ctx context.Context) *chi.Mux {
|
||||
r := chi.NewRouter()
|
||||
middleware.Mount(ctx, r, flags.http)
|
||||
MountRoutes(ctx, r)
|
||||
middleware.MountSystemRoutes(ctx, r, flags.http)
|
||||
return r
|
||||
}
|
||||
|
||||
func MountRoutes(ctx context.Context, r chi.Router) {
|
||||
// Only protect application routes with JWT
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(
|
||||
auth.DefaultJwtHandler.Verifier(),
|
||||
auth.DefaultJwtHandler.Authenticator(),
|
||||
)
|
||||
mountRoutes(r, flags.http, rest.MountRoutes())
|
||||
})
|
||||
}
|
||||
|
||||
func mountRoutes(r chi.Router, opts *config.HTTP, mounts ...func(r chi.Router)) {
|
||||
for _, mount := range mounts {
|
||||
mount(r)
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory/resputil"
|
||||
"go.uber.org/zap"
|
||||
|
||||
migrate "github.com/crusttech/crust/compose/db"
|
||||
"github.com/crusttech/crust/compose/internal/service"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/db"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/mail"
|
||||
"github.com/crusttech/crust/internal/metrics"
|
||||
)
|
||||
|
||||
func Init(ctx context.Context) (err error) {
|
||||
// validate configuration
|
||||
if err = flags.Validate(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
mail.SetupDialer(flags.smtp)
|
||||
|
||||
if err = InitDatabase(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// configure resputil options
|
||||
resputil.SetConfig(resputil.Options{
|
||||
Pretty: flags.http.Pretty,
|
||||
Trace: flags.http.Tracing,
|
||||
Logger: func(err error) {},
|
||||
})
|
||||
|
||||
// Use JWT secret for hmac signer for now
|
||||
auth.DefaultSigner = auth.HmacSigner(flags.jwt.Secret)
|
||||
auth.DefaultJwtHandler, err = auth.JWT(flags.jwt.Secret, flags.jwt.Expiry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Don't change this to init(), it needs Database
|
||||
return service.Init(ctx)
|
||||
}
|
||||
|
||||
func InitDatabase(ctx context.Context) error {
|
||||
// start/configure database connection
|
||||
db, err := db.TryToConnect(ctx, "compose", flags.db.DSN, flags.db.Profiler)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not connect to database")
|
||||
}
|
||||
|
||||
// migrate database schema
|
||||
if err := migrate.Migrate(db); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func StartWatchers(ctx context.Context) {
|
||||
service.Watchers(ctx)
|
||||
}
|
||||
|
||||
func StartRestAPI(ctx context.Context) error {
|
||||
logger.Default().Info("Starting HTTP server", zap.String("address", flags.http.Addr))
|
||||
listener, err := net.Listen("tcp", flags.http.Addr)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("Can't listen on addr %s", flags.http.Addr))
|
||||
}
|
||||
|
||||
if flags.monitor.Interval > 0 {
|
||||
go metrics.NewMonitor(flags.monitor.Interval)
|
||||
}
|
||||
|
||||
go http.Serve(listener, Routes(ctx))
|
||||
<-ctx.Done()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -91,6 +91,7 @@ func (a *Attachment) imageMeta(in *attachmentFileMeta, width, height int, animat
|
||||
}
|
||||
|
||||
func (meta *attachmentMeta) Scan(value interface{}) error {
|
||||
//lint:ignore S1034 This typecast is intentional, we need to get []byte out of a []uint8
|
||||
switch value.(type) {
|
||||
case nil:
|
||||
*meta = attachmentMeta{}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
const ComposePermissionResource = permissions.Resource("compose")
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -3,7 +3,7 @@ package types
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -19,7 +19,7 @@ type (
|
||||
OwnedBy uint64 `db:"owned_by" json:"ownedBy,string"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt,omitempty"`
|
||||
CreatedBy uint64 `db:"created_by" json:"createdBy,string" `
|
||||
UpdatedAt *time.Time `db:"updated_at" json:"updatedAt,omitempty,omitempty"`
|
||||
UpdatedAt *time.Time `db:"updated_at" json:"updatedAt,omitempty"`
|
||||
UpdatedBy uint64 `db:"updated_by" json:"updatedBy,string,omitempty" `
|
||||
DeletedAt *time.Time `db:"deleted_at" json:"deletedAt,omitempty"`
|
||||
DeletedBy uint64 `db:"deleted_by" json:"deletedBy,string,omitempty" `
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
"github.com/cortezaproject/corteza-server/internal/test"
|
||||
)
|
||||
|
||||
// Hello! This file is auto-generated.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/crusttech/crust/internal/permissions"
|
||||
"github.com/cortezaproject/corteza-server/internal/permissions"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
Reference in New Issue
Block a user