From 78e74f2e4669b983d4d80ca9ade98238e995226b Mon Sep 17 00:00:00 2001 From: Tommi2Day Date: Tue, 16 May 2023 18:39:55 +0200 Subject: [PATCH] dblib: fix SID parsing --- CHANGELOG.md | 4 ++++ dblib/tns.go | 4 ++-- dblib/tns_test.go | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0133d7a..1a64d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Go Library +## [v1.7.2 - 2023-05-16] +### Fixed +- dblib: fix SID parsing + ## [v1.7.1 - 2023-05-10] ### New - pwlib: add vault method to get_password diff --git a/dblib/tns.go b/dblib/tns.go index 377ab4d..aed8942 100644 --- a/dblib/tns.go +++ b/dblib/tns.go @@ -57,7 +57,7 @@ func CheckTNSadmin(tnsadmin string) (dn string, err error) { // BuildTnsEntry build map for entry func BuildTnsEntry(filename string, desc string, tnsAlias string) TNSEntry { var service = "" - reService := regexp.MustCompile(`(?mi)SERVICE_NAME\s*=\s*([\w.]+)`) + reService := regexp.MustCompile(`(?mi)(?:SERVICE_NAME|SID)\s*=\s*([\w.]+)`) s := reService.FindStringSubmatch(desc) if len(s) > 1 { service = s[1] @@ -194,7 +194,7 @@ func tnsSanity(entries TNSEntries) (tnsEntries TNSEntries, deletes int) { se++ } if len(e.Service) == 0 { - log.Errorf("Entry %s has no Service set", k) + log.Errorf("Entry %s has no SERVICE_NAME or SID set", k) se++ } if len(e.Servers) == 0 { diff --git a/dblib/tns_test.go b/dblib/tns_test.go index c5cde8c..61d9fd3 100644 --- a/dblib/tns_test.go +++ b/dblib/tns_test.go @@ -67,6 +67,10 @@ XE1 =(DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))) (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = XE1)) ) +XE.SID =(DESCRIPTION = + (ADDRESS_LIST = (ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))) + (CONNECT_DATA=(SID = XESID)) +) XE.error = Error ` @@ -74,7 +78,7 @@ const sqlnetora = ` NAMES.DEFAULT_DOMAIN=local NAMES.DIRECTORY_PATH=(TNSNAMES,EZCONNECT,LDAP) ` -const entryCount = 5 +const entryCount = 6 var tnsAdmin = "testdata" @@ -142,6 +146,12 @@ func TestParseTns(t *testing.T) { success: true, service: "XE", }, + { + name: "XE-SID", + alias: "XE.SID", + success: true, + service: "XESID", + }, { name: "XE1-short-invalid", alias: "XE1",