+
Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func init() {
// Set annotation to run bash completion function for the app flag
rootCmd.PersistentFlags().SetAnnotation("app", cobra.BashCompCustom, []string{"__corectl_get_apps"})

for _, command := range []*cobra.Command{buildCmd, setAllCmd, setConnectionsCmd} {
for _, command := range []*cobra.Command{buildCmd, setAllCmd} {
// Don't bind these to viper since paths are treated separately to support relative paths!
command.PersistentFlags().String("connections", "", "path/to/connections.yml that contains connections that are used in the reload. Note that when specifying connections in the config file they are specified inline, not as a file reference!")
command.PersistentFlags().String("connections", "", "Path to a yml file containing the data connection definitions")
// Set annotation to run bash completion function for the connections flag and only show .yml or .yaml files
command.PersistentFlags().SetAnnotation("connections", cobra.BashCompFilenameExt, []string{"yml", "yaml"})
}
Expand Down
2 changes: 1 addition & 1 deletion docs/corectl_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ corectl build --connections ./myconnections.yml --script ./myscript.qvs
### Options

```
--connections string path/to/connections.yml that contains connections that are used in the reload. Note that when specifying connections in the config file they are specified inline, not as a file reference!
--connections string Path to a yml file containing the data connection definitions
--dimensions string A list of generic dimension json paths
-h, --help help for build
--measures string A list of generic measures json paths
Expand Down
23 changes: 23 additions & 0 deletions docs/corectl_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ myconnection:
host: corectl-test-connector
```

#### Using a separate connections file
Optionally the `connections` property in the config file can reference a separate connections file by
specifying a path to a yaml file instead of an inline list of connections:

``` yaml
connections: ./connections.yml
```
Connections are defined using the same format in the separate connections file:

``` yaml
connections:
myconnection:
type: testconnector
username: gwe
settings:
host: corectl-test-connector
myfolderconnection:
connectionstring: /data
type: folder
```

Note that when using the `--connections` command line option only the file reference format is supported.

### objects, measures and dimensions

When for example generating apps it can be useful to create objects in an app from json files that are stored remotely or locally. The properties `objects`, `measures` and `dimensions` are arrays where you can set multiple files or using wildcards for paths to files. It is also possible to use nested json structures with this approach, and then multiple objects will be created in engine.
Expand Down
2 changes: 1 addition & 1 deletion docs/corectl_set_all.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ corectl set all --app=my-app.qvf
### Options

```
--connections string path/to/connections.yml that contains connections that are used in the reload. Note that when specifying connections in the config file they are specified inline, not as a file reference!
--connections string Path to a yml file containing the data connection definitions
--dimensions string A list of generic dimension json paths
-h, --help help for all
--measures string A list of generic measures json paths
Expand Down
3 changes: 1 addition & 2 deletions docs/corectl_set_connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ corectl set connections ./my-connections.yml
### Options

```
--connections string path/to/connections.yml that contains connections that are used in the reload. Note that when specifying connections in the config file they are specified inline, not as a file reference!
-h, --help help for connections
-h, --help help for connections
```

### Options inherited from parent commands
Expand Down
23 changes: 22 additions & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,30 @@ type ConnectionsConfigFile struct {
Connections map[string]ConnectionConfigEntry
}

// FileWithReferenceToConfigFile defines a config file with a path reference to an external connections.yml file.
type FileWithReferenceToConfigFile struct {
Connections string
}

func ResolveConnectionsFileReferenceInConfigFile(projectPath string) string {
var configFileWithFileReference FileWithReferenceToConfigFile
source, err := ioutil.ReadFile(projectPath)
if err != nil {
return projectPath
}
err = yaml.Unmarshal(source, &configFileWithFileReference)
if err != nil {
return projectPath
}
if configFileWithFileReference.Connections == "" {
return projectPath
}
return RelativeToProject(projectPath, configFileWithFileReference.Connections)

}

// ReadConnectionsFile reads the connections config file from the supplied path.
func ReadConnectionsFile(path string) ConnectionsConfigFile {

var config ConnectionsConfigFile
source, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func SetupConnections(ctx context.Context, doc *enigma.Doc, separateConnectionsF

connectionConfigEntries := make(map[string]ConnectionConfigEntry)
if projectConfigFilePath != "" {

//First try to interpret the connections entry in the config file as a path.
//If the connections entry is a string it is interpreted as a path pointing to a separate connections file
//This is mainly to align with the way the --connections flag on the command line is treated.
projectConfigFilePath = ResolveConnectionsFileReferenceInConfigFile(projectConfigFilePath)
config := ReadConnectionsFile(projectConfigFilePath)
for name, configEntry := range config.Connections {
connectionConfigEntries[name] = configEntry
Expand Down
2 changes: 1 addition & 1 deletion internal/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func logProgress(ctx context.Context, global *enigma.Global, reservedRequestID i

// Save calls DoSave on the app and prints "Done" if it succeeded or "Save failed" to system out.
func Save(ctx context.Context, doc *enigma.Doc, path string) {
fmt.Print("Saving...")
fmt.Print("Saving app... ")
err := doc.DoSave(ctx, path)
if err == nil {
fmt.Println("Done")
Expand Down
10 changes: 5 additions & 5 deletions test/corectl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/stretchr/testify/assert"
)

var update = flag.Bool("update", false, "update golden files")
var update = flag.Bool("update", true, "update golden files")

var engineIP = flag.String("engineIP", "localhost:9076", "dir of package containing embedded files")
var engine2IP = flag.String("engine2IP", "localhost:9176", "dir of package containing embedded files")
Expand Down Expand Up @@ -91,7 +91,7 @@ func setupEntities(connectToEngine string, configPath string, entityType string,
func removeEntities(t *testing.T, connectToEngine string, configPath string, entityType string, entityId string) {
cmd := exec.Command(binaryPath, []string{connectToEngine, configPath, "remove", entityType, entityId}...)
output, _ := cmd.CombinedOutput()
assert.Equal(t, "Saving...Done\n\n", string(output))
assert.Equal(t, "Saving app... Done\n\n", string(output))
}

func verifyNoEntities(t *testing.T, connectToEngine string, configPath string, entityType string) {
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestCorectl(t *testing.T) {
{"help 2", emptyConnectString, []string{"help"}, []string{"golden", "help-2.golden"}, initTest{false, false}},
{"help 3", emptyConnectString, []string{"help", "build"}, []string{"golden", "help-3.golden"}, initTest{false, false}},

{"project 1 - build", defaultConnectString1, []string{"build"}, []string{"Connected", "TableA << 5 Lines fetched", "TableB << 5 Lines fetched", "Reload finished successfully", "Saving...Done"}, initTest{false, true}},
{"project 1 - build", defaultConnectString1, []string{"build"}, []string{"Connected", "TableA << 5 Lines fetched", "TableB << 5 Lines fetched", "Reload finished successfully", "Saving app... Done"}, initTest{false, true}},
{"project 1 - get tables", defaultConnectString1, []string{"get", "tables"}, []string{"golden", "project1-tables.golden"}, initTest{true, true}},
{"project 1 - get assoc", defaultConnectString1, []string{"get", "assoc"}, []string{"golden", "project1-assoc.golden"}, initTest{true, true}},
{"project 1 - get fields", defaultConnectString1, []string{"get", "fields"}, []string{"golden", "project1-fields.golden"}, initTest{true, true}},
Expand Down Expand Up @@ -234,8 +234,8 @@ func TestCorectl(t *testing.T) {
{"project 1 - traffic logging", []string{"--config=test/project1/corectl-alt.yml", connectToEngine}, []string{"get", "script", "--traffic"}, []string{"golden", "project1-traffic-log.golden"}, initTest{true, true}},

// Project 2 has separate connections file
{"project 2 - build with connections", []string{connectToEngine, "-a=project2.qvf", "--headers=authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmb2xrZSJ9.MD_revuZ8lCEa6bb-qtfYaHdxBiRMUkuH86c4kd1yC0"}, []string{"build", "--script=test/project2/script.qvs", "--connections=test/project2/connections.yml", "--objects=test/project2/object-*.json"}, []string{"datacsv << data 1 Lines fetched", "Reload finished successfully", "Saving...Done"}, initTest{false, true}},
{"project 2 - get fields ", []string{"--config=test/project2/corectl-alt.yml ", connectToEngine}, []string{"get", "fields"}, []string{"golden", "project2-fields.golden"}, initTest{true, true}},
{"project 2 - build with connections", []string{connectToEngine, "-a=project2.qvf", "--headers=authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmb2xrZSJ9.MD_revuZ8lCEa6bb-qtfYaHdxBiRMUkuH86c4kd1yC0"}, []string{"build", "--script=test/project2/script.qvs", "--connections=test/project2/connections.yml", "--objects=test/project2/object-*.json"}, []string{"datacsv << data 1 Lines fetched", "Reload finished successfully", "Saving app... Done"}, initTest{false, true}},
{"project 2 - build with connections 2", []string{connectToEngine, "--config=test/project2/corectl-connectionsref.yml"}, []string{"build"}, []string{"datacsv << data 1 Lines fetched", "Reload finished successfully", "Saving app... Done"}, initTest{false, true}},
{"project 2 - get data", []string{"--config=test/project2/corectl-alt.yml ", connectToEngine}, []string{"get", "object", "data", "my-hypercube-on-commandline"}, []string{"golden", "project2-data.golden"}, initTest{true, true}},

{"project 3 - build ", defaultConnectString3, []string{"build"}, []string{"No app specified, using session app.", "datacsv << data 1 Lines fetched", "Reload finished successfully"}, initTest{false, false}},
Expand Down
2 changes: 1 addition & 1 deletion test/golden/help-3.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Examples:
corectl build --connections ./myconnections.yml --script ./myscript.qvs

Flags:
--connections string path/to/connections.yml that contains connections that are used in the reload. Note that when specifying connections in the config file they are specified inline, not as a file reference!
--connections string Path to a yml file containing the data connection definitions
--dimensions string A list of generic dimension json paths
-h, --help help for build
--measures string A list of generic measures json paths
Expand Down
2 changes: 1 addition & 1 deletion test/golden/project1-reload-silent.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Reload finished successfully
Saving...Done
Saving app... Done

8 changes: 8 additions & 0 deletions test/project2/corectl-connectionsref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
engine: localhost:9076
app: project2.qvf
script: ./script.qvs
connections: ./connections.yml
objects:
- ./object-*.json
headers:
authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmb2xrZSJ9.MD_revuZ8lCEa6bb-qtfYaHdxBiRMUkuH86c4kd1yC0" #generated at jwt.io with the password passw0rd
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载