Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hosekpeter committed Dec 2, 2024
1 parent 05efd37 commit baa767a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
21 changes: 21 additions & 0 deletions internal/pkg/service/templates/api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package service
import (
"context"
"fmt"
"github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet"
"github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet/fsimporter"
"github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs/mountfs"
"github.com/keboola/keboola-as-code/internal/pkg/template/jsonnet/function"
"net/http"
"path"
"strconv"
Expand Down Expand Up @@ -257,6 +261,23 @@ func (s *service) UseTemplateVersion(ctx context.Context, d dependencies.Project
}
defer unlockFn(ctx)

s.mapper

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

s.mapper (variable of type *Mapper) is not used

Check failure on line 264 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

s.mapper (variable of type *Mapper) is not used
mountPoint := mountfs.NewMountPoint(repository.CommonDirectoryMountPoint, commonDir)

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

undefined: commonDir

Check failure on line 265 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

undefined: commonDir
templateDir, err := aferofs.NewMountFs(templateDir, []mountfs.MountPoint{mountPoint})

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

undefined: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

undefined: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

undefined: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

undefined: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

declared and not used: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

undefined: templateDir

Check failure on line 266 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

declared and not used: templateDir
if err != nil {
return nil, err
}
srcDir, err := d.SubDirFs(SrcDirectory)

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

d.SubDirFs undefined (type "github.com/keboola/keboola-as-code/internal/pkg/service/templates/dependencies".ProjectRequestScope has no field or method SubDirFs)

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

undefined: SrcDirectory

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

d.SubDirFs undefined (type "github.com/keboola/keboola-as-code/internal/pkg/service/templates/dependencies".ProjectRequestScope has no field or method SubDirFs)

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

undefined: SrcDirectory

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

d.SubDirFs undefined (type "github.com/keboola/keboola-as-code/internal/pkg/service/templates/dependencies".ProjectRequestScope has no field or method SubDirFs)

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

undefined: SrcDirectory

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

d.SubDirFs undefined (type "github.com/keboola/keboola-as-code/internal/pkg/service/templates/dependencies".ProjectRequestScope has no field or method SubDirFs)

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

undefined: SrcDirectory

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

d.SubDirFs undefined (type "github.com/keboola/keboola-as-code/internal/pkg/service/templates/dependencies".ProjectRequestScope has no field or method SubDirFs)

Check failure on line 270 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

undefined: SrcDirectory
if err != nil {
return nil, err
}
srcDir, err = aferofs.NewMountFs(srcDir, []mountfs.MountPoint{mountPoint})
if err != nil {
return nil, err
}
jsonnetCtx := jsonnet.NewContext().WithCtx(ctx).WithImporter(fsimporter.New(objectsRoot))

Check failure on line 278 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / E2E: Templates / test

undefined: objectsRoot

Check failure on line 278 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Lint / lint

undefined: objectsRoot) (typecheck)

Check failure on line 278 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / linux

undefined: objectsRoot

Check failure on line 278 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / mac-os

undefined: objectsRoot

Check failure on line 278 in internal/pkg/service/templates/api/service/service.go

View workflow job for this annotation

GitHub Actions / Unit Tests / windows

undefined: objectsRoot

jsonnetCtx.NativeFunctionWithAlias(function.SnowflakeWriterComponentID(d.Components()))
// Note:
// A very strange code follows.
// Since I did not manage to complete the refactoring - separation of remote and local state.
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/service/templates/dependencies/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
// apiScope implements APIScope interface.
type apiScope struct {
dependencies.BaseScope
dependencies.ProjectScope
dependencies.PublicScope
dependencies.EtcdClientScope
dependencies.DistributionScope
Expand All @@ -41,6 +42,7 @@ type apiScope struct {

type parentScopes struct {
dependencies.BaseScope
dependencies.ProjectScope
dependencies.PublicScope
dependencies.EtcdClientScope
dependencies.DistributionScope
Expand Down Expand Up @@ -130,6 +132,8 @@ func newAPIScope(ctx context.Context, p *parentScopes, cfg config.Config) (v *ap

d.BaseScope = p.BaseScope

d.ProjectScope = p.ProjectScope

d.PublicScope = p.PublicScope

d.EtcdClientScope = p.EtcdClientScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ctxKey string
const (
PublicRequestScopeCtxKey = ctxKey("PublicRequestScope")
ProjectRequestScopeCtxKey = ctxKey("ProjectRequestScope")
APIRequestScopeCtxKey = ctxKey("APIRequestScope")
)

// APIScope interface provides dependencies for Templates API server.
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/template/context/load/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package load

import (
"context"
"fmt"

"github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet"
"github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet/fsimporter"
Expand All @@ -29,6 +30,7 @@ func NewContext(ctx context.Context, objectsRoot filesystem.Fs, components *mode
projectBackends: projectBackends,
}

fmt.Println("AAA: ", projectBackends)
// Register Jsonnet functions
c.registerJsonnetFunctions()

Expand All @@ -41,6 +43,6 @@ func (c *Context) JsonnetContext() *jsonnet.Context {

func (c *Context) registerJsonnetFunctions() {
c.jsonnetCtx.NativeFunctionWithAlias(function.ComponentIsAvailable(c.components))
c.jsonnetCtx.NativeFunctionWithAlias(function.SnowflakeWriterComponentID(c.components))
//c.jsonnetCtx.NativeFunctionWithAlias(function.SnowflakeWriterComponentID(c.components))
c.jsonnetCtx.NativeFunctionWithAlias(function.HasProjectBackend(c.projectBackends))
}
4 changes: 3 additions & 1 deletion internal/pkg/template/repository/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package manager

import (
"context"
"fmt"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -59,6 +60,7 @@ type dependencies interface {
Telemetry() telemetry.Telemetry
Process() *servicectx.Process
Components() *model.ComponentsMap
ProjectBackends() []string
}

func New(ctx context.Context, d dependencies, defaultRepositories []model.TemplateRepository) (*Manager, error) {
Expand All @@ -72,7 +74,7 @@ func New(ctx context.Context, d dependencies, defaultRepositories []model.Templa
repositoriesInit: &singleflight.Group{},
repositoriesLock: &sync.RWMutex{},
}

fmt.Println("BB: ", d.ProjectBackends())
// Free all repositories on server shutdown
d.Process().OnShutdown(func(ctx context.Context) {
m.Free(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/template/repository/manager/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *CachedRepository) Template(ctx context.Context, reference model.Templat

// Load template
r.d.Logger().Infof(ctx, r.repo.Fs().BasePath())
tmpl, err := loadTemplateOp.Run(ctx, r.d, r.repo, reference, template.Option{})
tmpl, err := loadTemplateOp.Run(ctx, r.d, r.repo, reference, template.Option{ProjectBackend: r.d.ProjectBackends()})
if err != nil {
return nil, errors.Errorf(`cannot load template "%s": %w`, reference.FullName(), err)
}
Expand Down

0 comments on commit baa767a

Please sign in to comment.