Skip to content

Commit

Permalink
#122 Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Jun 7, 2024
1 parent 9eba11c commit 044d02c
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 330 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The following helpers have been created:

### Helper functions

- `engineconfigurationjson`: A package for creating the `SENZING_ENGINE_CONFIGURATION_JSON` Document.
- `settings`: A package for creating the `SENZING_ENGINE_CONFIGURATION_JSON` Document.

### Test data

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
// --- Build JSON from environment variables.
// ------------------------------------------------------------------------

iniParams, err := settings.BuildSimpleSystemConfigurationJSONUsingEnvVars()
iniParams, err := settings.BuildSimpleSettingsUsingEnvVars()
if err != nil {
panic(err)
}
Expand All @@ -46,7 +46,7 @@ func main() {
// --- Verify parameters
// ------------------------------------------------------------------------

err = settings.VerifySenzingEngineConfigurationJSON(ctx, iniParams)
err = settings.VerifySettings(ctx, iniParams)
if err != nil {
panic(err)
}
Expand All @@ -63,7 +63,7 @@ func main() {
"supportPath": "/final/path/to/support",
}

iniParams2, err := settings.BuildSimpleSystemConfigurationJSONUsingMap(attributeMap)
iniParams2, err := settings.BuildSimpleSettingsUsingMap(attributeMap)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion settings/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
The engineconfigurationjson package is used to create the JSON needed for initializing the Senzing runtime objects.
The settings package is used to create the JSON needed for initializing the Senzing runtime objects.
*/
package settings
2 changes: 1 addition & 1 deletion settings/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// The engineconfigurationjson package helps configure SENZING_ENGINE_CONFIGURATION_JSON.
// The settings package helps configure SENZING_ENGINE_CONFIGURATION_JSON.
package settings

// ----------------------------------------------------------------------------
Expand Down
32 changes: 16 additions & 16 deletions settings/settings.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package engineconfigurationjson is used to generate the JSON document used to configure a Senzing client.
Package settings is used to generate the JSON document used to configure a Senzing client.
*/
package settings

Expand All @@ -18,23 +18,23 @@ import (
// ----------------------------------------------------------------------------

/*
The BuildSimpleSystemConfigurationJSONUsingEnvVars method is a convenience method
for invoking BuildSimpleSystemConfigurationJsonUsingMap without any mapped values.
The BuildSimpleSettingsUsingEnvVars method is a convenience method
for invoking BuildSimpleSettingsUsingMap without any mapped values.
In other words, only environment variables will be used.
See BuildSimpleSystemConfigurationJsonUsingMap() for information on the environment variables used.
See BuildSimpleSettingsUsingMap() for information on the environment variables used.
Output
- A string containing a JSON document use when calling Senzing's Init(...) methods.
See the example output.
*/
func BuildSimpleSystemConfigurationJSONUsingEnvVars() (string, error) {
func BuildSimpleSettingsUsingEnvVars() (string, error) {
attributeMap := map[string]string{}
return BuildSimpleSystemConfigurationJSONUsingMap(attributeMap)
return BuildSimpleSettingsUsingMap(attributeMap)
}

/*
The BuildSimpleSystemConfigurationJSONUsingMap method returns a JSON document for use with Senzing's Init(...) methods.
The BuildSimpleSettingsUsingMap method returns a JSON document for use with Senzing's Init(...) methods.
If the environment variable SENZING_TOOLS_ENGINE_CONFIGURATION_JSON is set,
the value of SENZING_TOOLS_ENGINE_CONFIGURATION_JSON will be returned unchanged.
Expand Down Expand Up @@ -66,7 +66,7 @@ Output
- A string containing a JSON document use when calling Senzing's Init(...) methods.
See the example output.
*/
func BuildSimpleSystemConfigurationJSONUsingMap(attributeMap map[string]string) (string, error) {
func BuildSimpleSettingsUsingMap(attributeMap map[string]string) (string, error) {
var err error

// If SENZING_TOOLS_ENGINE_CONFIGURATION_JSON is set, use it.
Expand Down Expand Up @@ -132,23 +132,23 @@ func BuildSimpleSystemConfigurationJSONUsingMap(attributeMap map[string]string)
}

/*
The VerifySenzingEngineConfigurationJSON method inspects the Senzing engine configuration JSON to see if it is misconfigured.
The VerifySettings method inspects the Senzing engine configuration JSON to see if it is misconfigured.
Errors are documented at https://hub.senzing.com/go-helpers/errors.
Input
- ctx: A context to control lifecycle.
- senzingEngineConfigurationJson: A JSON string. See https://github.com/senzing-garage/knowledge-base/blob/main/lists/environment-variables.md#senzing_tools_engine_configuration_json
- settings: A JSON string. See https://github.com/senzing-garage/knowledge-base/blob/main/lists/environment-variables.md#senzing_tools_engine_configuration_json
*/
func VerifySenzingEngineConfigurationJSON(ctx context.Context, senzingEngineConfigurationJSON string) error {
func VerifySettings(ctx context.Context, settings string) error {
var err error
parser := settingsparser.BasicEngineConfigurationJSONParser{
EngineConfigurationJSON: senzingEngineConfigurationJSON,
parser := settingsparser.BasicSettingsParser{
Settings: settings,
}

// Check database URLs.

databaseURLs, err := parser.GetDatabaseUrls(ctx)
databaseURLs, err := parser.GetDatabaseURLs(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -210,13 +210,13 @@ func VerifySenzingEngineConfigurationJSON(ctx context.Context, senzingEngineConf

// Os / Arch specific calls

err = verifySenzingEngineConfigurationJSON(ctx, senzingEngineConfigurationJSON)
err = verifySettings(ctx, settings)

return err
}

// ----------------------------------------------------------------------------
// Internal methods
// Private functions
// ----------------------------------------------------------------------------

func getOsEnv(variableName string) (string, error) {
Expand Down
8 changes: 4 additions & 4 deletions settings/settings_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build darwin

package engineconfigurationjson
package settings

import (
"context"
Expand Down Expand Up @@ -47,7 +47,7 @@ func buildStruct(attributeMap map[string]string) SzConfiguration {
ResourcePath: mapWithDefault(attributeMap, "resourcePath", resourcePath),
SupportPath: mapWithDefault(attributeMap, "supportPath", supportPath),
},
Sql: SzConfigurationSql{
SQL: SzConfigurationSQL{
Connection: databaseUrl,
},
}
Expand All @@ -60,9 +60,9 @@ func buildStruct(attributeMap map[string]string) SzConfiguration {
return result
}

func verifySenzingEngineConfigurationJson(ctx context.Context, engineConfigurationJson string) error {
func verifySettings(ctx context.Context, settings string) error {
_ = ctx
_ = engineConfigurationJson
_ = settings
var err error = nil
return err
}
10 changes: 5 additions & 5 deletions settings/settings_darwin_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//go:build darwin

package engineconfigurationjson
package settings

var testCasesForOsArch = []testCaseMetadata{
{
name: "sqlite3-001",
databaseUrl: "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db",
databaseUrlPath: "/var/opt/senzing/sqlite/G2C.db",
databaseURL: "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db",
databaseURLPath: "/var/opt/senzing/sqlite/G2C.db",
},
{
name: "sqlite3-002",
databaseUrl: `sqlite3://na:na@hostname/var/opt/senzing/sqlite/G2C.db`,
databaseUrlPath: "/var/opt/senzing/sqlite/G2C.db",
databaseURL: `sqlite3://na:na@hostname/var/opt/senzing/sqlite/G2C.db`,
databaseURLPath: "/var/opt/senzing/sqlite/G2C.db",
},
}
36 changes: 18 additions & 18 deletions settings/settings_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,106 @@ import (
// Examples for godoc documentation
// ----------------------------------------------------------------------------

func ExampleBuildSimpleSystemConfigurationJSONUsingMap() {
func ExampleBuildSimpleSettingsUsingMap() {
aMap := map[string]string{
"databaseUrl": "postgresql://username:password@hostname:5432/G2",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"postgresql://username:password@hostname:5432:G2/"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_db2() {
func ExampleBuildSimpleSettingsUsingMap_db2() {
aMap := map[string]string{
"databaseUrl": "db2://username:password@hostname:50000/G2",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"db2://username:password@G2"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_db2WithSchema() {
func ExampleBuildSimpleSettingsUsingMap_db2WithSchema() {
aMap := map[string]string{
"databaseUrl": "db2://username:password@hostname:50000/G2/?schema=schemaname",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"db2://username:password@G2/?schema=schemaname"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_oci() {
func ExampleBuildSimpleSettingsUsingMap_oci() {
aMap := map[string]string{
"databaseUrl": "oci://username:password@hostname:1521/G2",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"oci://username:password@G2"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_mssql() {
func ExampleBuildSimpleSettingsUsingMap_mssql() {
aMap := map[string]string{
"databaseUrl": "mssql://username:password@hostname:1433/G2",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"mssql://username:password@G2"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_mysql() {
func ExampleBuildSimpleSettingsUsingMap_mysql() {
aMap := map[string]string{
"databaseUrl": "mysql://username:password@hostname:3306/G2",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"mysql://username:password@hostname:3306/?schema=G2"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_postgresql() {
func ExampleBuildSimpleSettingsUsingMap_postgresql() {
aMap := map[string]string{
"databaseUrl": "postgresql://username:password@hostname:5432/G2",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"postgresql://username:password@hostname:5432:G2/"}}
}

func ExampleBuildSimpleSystemConfigurationJSONUsingMap_postgresqlWithSchema() {
func ExampleBuildSimpleSettingsUsingMap_postgresqlWithSchema() {
aMap := map[string]string{
"databaseUrl": "postgresql://username:password@hostname:5432/G2/?schema=schemaname",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
// Output: {"PIPELINE":{"CONFIGPATH":"/etc/opt/senzing","RESOURCEPATH":"/opt/senzing/g2/resources","SUPPORTPATH":"/opt/senzing/data"},"SQL":{"CONNECTION":"postgresql://username:password@hostname:5432:G2/?schema=schemaname"}}
}
func ExampleBuildSimpleSystemConfigurationJSONUsingMap_sqlite() {
func ExampleBuildSimpleSettingsUsingMap_sqlite() {
aMap := map[string]string{
"databaseUrl": "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db",
}
result, err := BuildSimpleSystemConfigurationJSONUsingMap(aMap)
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
fmt.Println(err)
}
Expand Down
4 changes: 2 additions & 2 deletions settings/settings_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func buildStruct(attributeMap map[string]string) SzConfiguration {
return result
}

func verifySenzingEngineConfigurationJSON(ctx context.Context, engineConfigurationJSON string) error {
_ = engineConfigurationJSON
func verifySettings(ctx context.Context, settings string) error {
_ = settings
_ = ctx
var err error
return err
Expand Down
Loading

0 comments on commit 044d02c

Please sign in to comment.