-
Notifications
You must be signed in to change notification settings - Fork 42
/
arrai.go
61 lines (53 loc) · 1.62 KB
/
arrai.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package importer
import (
"fmt"
arrai2 "github.com/anz-bank/sysl/internal/arrai"
"github.com/anz-bank/sysl/pkg/arrai"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// ArraiImporter encapsulates glue code for calling arr.ai scripts to import specs.
type ArraiImporter struct {
appName string
pkg string
asset string
logger *logrus.Logger
}
// MakeArraiImporterImporter returns a new ArraiImporter.
func MakeArraiImporterImporter(asset string, logger *logrus.Logger) *ArraiImporter {
return &ArraiImporter{
asset: asset,
logger: logger,
}
}
// WithAppName allows the exported Sysl application name to be specified.
func (i *ArraiImporter) WithAppName(appName string) Importer {
i.appName = appName
return i
}
// WithPackage allows the exported Sysl package attribute to be specified.
func (i *ArraiImporter) WithPackage(packageName string) Importer {
i.pkg = packageName
return i
}
// LoadFile generates a Sysl spec be invoking the arr.ai script.
func (i *ArraiImporter) LoadFile(path string) (string, error) {
b, err := arrai2.Asset(i.asset)
if err != nil {
return "", err
}
// TODO: Make the appname optional
val, err := arrai.EvaluateBundle(b, path, i.appName, i.pkg)
if err != nil {
return "", errors.Wrap(arrai.ExecutionError{
Context: fmt.Sprintf("import(`%s`, `%s`, `%s`)", path, i.appName, i.pkg),
Err: err,
ShortMsg: err.Error(),
}, "Executing arrai transform failed")
}
return val.String(), nil
}
// Load generates a Sysl spec given the content of an input file. This is not implemented.
func (i *ArraiImporter) Load(content string) (string, error) {
panic("not implemented")
}