Skip to content

Commit 8c73c08

Browse files
Add MS SQL Server DB Client (#88)
Signed-off-by: Neaj Morshad <neaj@appscode.com>
1 parent 4b4e47e commit 8c73c08

File tree

176 files changed

+90040
-5148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+90040
-5148
lines changed

go.mod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/go-resty/resty/v2 v2.11.0
1515
github.com/go-sql-driver/mysql v1.7.1
1616
github.com/lib/pq v1.10.7
17+
github.com/microsoft/go-mssqldb v1.6.0
1718
github.com/opensearch-project/opensearch-go v1.1.0
1819
github.com/opensearch-project/opensearch-go/v2 v2.3.0
1920
github.com/pkg/errors v0.9.1
@@ -25,7 +26,7 @@ require (
2526
k8s.io/klog/v2 v2.120.1
2627
kmodules.xyz/client-go v0.29.13
2728
kmodules.xyz/custom-resources v0.29.1
28-
kubedb.dev/apimachinery v0.44.1-0.20240418111017-ee6ba81797f6
29+
kubedb.dev/apimachinery v0.44.1-0.20240425042236-6efef42b8792
2930
sigs.k8s.io/controller-runtime v0.17.2
3031
xorm.io/xorm v1.3.6
3132
)
@@ -52,6 +53,8 @@ require (
5253
github.com/go-openapi/swag v0.22.4 // indirect
5354
github.com/goccy/go-json v0.9.11 // indirect
5455
github.com/gogo/protobuf v1.3.2 // indirect
56+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
57+
github.com/golang-sql/sqlexp v0.1.0 // indirect
5558
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5659
github.com/golang/protobuf v1.5.4 // indirect
5760
github.com/golang/snappy v0.0.4 // indirect
@@ -101,7 +104,7 @@ require (
101104
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
102105
golang.org/x/net v0.23.0 // indirect
103106
golang.org/x/oauth2 v0.15.0 // indirect
104-
golang.org/x/sync v0.5.0 // indirect
107+
golang.org/x/sync v0.6.0 // indirect
105108
golang.org/x/sys v0.18.0 // indirect
106109
golang.org/x/term v0.18.0 // indirect
107110
golang.org/x/text v0.14.0 // indirect
@@ -123,7 +126,7 @@ require (
123126
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
124127
kmodules.xyz/apiversion v0.2.0 // indirect
125128
kmodules.xyz/monitoring-agent-api v0.29.0 // indirect
126-
kmodules.xyz/offshoot-api v0.29.0 // indirect
129+
kmodules.xyz/offshoot-api v0.29.1 // indirect
127130
kubeops.dev/petset v0.0.5 // indirect
128131
modernc.org/memory v1.5.0 // indirect
129132
modernc.org/token v1.1.0 // indirect

go.sum

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
22
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
33
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
4+
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
45
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw=
6+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 h1:/iHxaJhsFr0+xVFfbMr5vxz848jyiWuIEDhYq3y5odY=
7+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
58
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0=
9+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
10+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U=
611
github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8=
12+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
13+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
14+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0 h1:yfJe15aSwEQ6Oo6J+gdfdulPNoZ3TEhmbhLIoxZcA+U=
15+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0/go.mod h1:Q28U+75mpCaSCDowNEmhIo/rmgdkqmkmzI7N6TGR4UY=
16+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 h1:T028gtTPiYt/RMUfs8nVsAL7FDQrfLlrm/NnRG/zcC4=
17+
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0/go.mod h1:cw4zVQgBby0Z5f2v0itn6se2dDP17nTjbZFXW5uPyHA=
18+
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 h1:HCc0+LpPfpCKs6LGGLAhwBARt9632unrVcI6i8s/8os=
19+
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
720
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
821
github.com/IBM/sarama v1.42.1 h1:wugyWa15TDEHh2kvq2gAy1IHLjEjuYOYgXz/ruC/OSQ=
922
github.com/IBM/sarama v1.42.1/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ=
@@ -112,7 +125,12 @@ github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
112125
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
113126
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
114127
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
128+
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
129+
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
115130
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
131+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
132+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
133+
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
116134
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
117135
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
118136
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -236,6 +254,8 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
236254
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
237255
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
238256
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
257+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
258+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
239259
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
240260
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
241261
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@@ -259,6 +279,8 @@ github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwp
259279
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
260280
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
261281
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
282+
github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc=
283+
github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU=
262284
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
263285
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
264286
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -289,6 +311,8 @@ github.com/opensearch-project/opensearch-go/v2 v2.3.0/go.mod h1:8LDr9FCgUTVoT+5E
289311
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
290312
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
291313
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
314+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
315+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
292316
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
293317
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
294318
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -447,8 +471,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
447471
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
448472
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
449473
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
450-
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
451-
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
474+
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
475+
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
452476
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
453477
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
454478
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -583,10 +607,10 @@ kmodules.xyz/custom-resources v0.29.1 h1:xiNylhs3ILRbcUhxxy306AOy9GMA4Mq7xFIptZK
583607
kmodules.xyz/custom-resources v0.29.1/go.mod h1:829zDY1EjaxPP52h1T73LZx/vgv8Pld9/uTT/ViZTc0=
584608
kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9H1UFRwB4=
585609
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
586-
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
587-
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
588-
kubedb.dev/apimachinery v0.44.1-0.20240418111017-ee6ba81797f6 h1:VrQhjNOGtqmMiT7lMxIydlfhuL8Ya+uitzyvBbvToQ4=
589-
kubedb.dev/apimachinery v0.44.1-0.20240418111017-ee6ba81797f6/go.mod h1:7daaaWragCFLV38plrrJtsOuzinBSX3enMpliqlm3Uo=
610+
kmodules.xyz/offshoot-api v0.29.1 h1:Pm83nzYHbqfCYKPCHrK0io387yXTaBmSydoAP6nF0WU=
611+
kmodules.xyz/offshoot-api v0.29.1/go.mod h1:SeGhKGXxNAy56cLnskEcLgCH+LRFN+MhJzvrZzPqUlM=
612+
kubedb.dev/apimachinery v0.44.1-0.20240425042236-6efef42b8792 h1:WNzbq7rB18pla0OkJszSg1eWZ2/VNZmdf6YNq97WRSU=
613+
kubedb.dev/apimachinery v0.44.1-0.20240425042236-6efef42b8792/go.mod h1:0uGwbmD4XN00LeU236LLOgoocK+UBoB9ojdstnZeJd8=
590614
kubeops.dev/petset v0.0.5 h1:VVXi39JhjondlbHyZ98z0MLp6VCmiCMinL59K48Y2zA=
591615
kubeops.dev/petset v0.0.5/go.mod h1:ijtKT1HlAht2vBEZj5LW7C00XEs3B0d1VdCQgd5V4cA=
592616
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=

mssql/client.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mssql
18+
19+
import (
20+
"xorm.io/xorm"
21+
)
22+
23+
type XormClient struct {
24+
*xorm.Engine
25+
}
26+
27+
func (xc *XormClient) Close() error {
28+
if xc.Engine != nil {
29+
return xc.Engine.Close()
30+
}
31+
return nil
32+
}

mssql/kubedb_client_builder.go

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mssql
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
24+
25+
_ "github.com/microsoft/go-mssqldb"
26+
core "k8s.io/api/core/v1"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
28+
"xorm.io/xorm"
29+
)
30+
31+
type KubeDBClientBuilder struct {
32+
kc client.Client
33+
db *api.MSSQL
34+
url string
35+
podName string
36+
ctx context.Context
37+
}
38+
39+
func NewKubeDBClientBuilder(kc client.Client, db *api.MSSQL) *KubeDBClientBuilder {
40+
return &KubeDBClientBuilder{
41+
kc: kc,
42+
db: db,
43+
}
44+
}
45+
46+
func (o *KubeDBClientBuilder) WithURL(url string) *KubeDBClientBuilder {
47+
o.url = url
48+
return o
49+
}
50+
51+
func (o *KubeDBClientBuilder) WithPod(podName string) *KubeDBClientBuilder {
52+
o.podName = podName
53+
return o
54+
}
55+
56+
func (o *KubeDBClientBuilder) WithContext(ctx context.Context) *KubeDBClientBuilder {
57+
o.ctx = ctx
58+
return o
59+
}
60+
61+
func (o *KubeDBClientBuilder) GetMSSQLXormClient() (*XormClient, error) {
62+
if o.ctx == nil {
63+
o.ctx = context.Background()
64+
}
65+
connector, err := o.getConnectionString()
66+
if err != nil {
67+
return nil, err
68+
}
69+
70+
engine, err := xorm.NewEngine(api.ResourceSingularMSSQL, connector)
71+
if err != nil {
72+
return nil, err
73+
}
74+
75+
_, err = engine.Query("SELECT 1")
76+
if err != nil {
77+
return nil, err
78+
}
79+
80+
engine.SetDefaultContext(o.ctx)
81+
return &XormClient{
82+
engine,
83+
}, nil
84+
}
85+
86+
func (o *KubeDBClientBuilder) getURL() string {
87+
return fmt.Sprintf("%s.%s.%s.svc", o.podName, o.db.GoverningServiceName(), o.db.Namespace)
88+
}
89+
90+
func (o *KubeDBClientBuilder) getMSSQLSACredentials() (string, string, error) {
91+
db := o.db
92+
var secretName string
93+
if db.Spec.AuthSecret != nil {
94+
secretName = db.GetAuthSecretName()
95+
}
96+
var secret core.Secret
97+
err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: db.Namespace, Name: secretName}, &secret)
98+
if err != nil {
99+
return "", "", err
100+
}
101+
user, ok := secret.Data[core.BasicAuthUsernameKey]
102+
if !ok {
103+
return "", "", fmt.Errorf("DB SA user is not found in secret")
104+
}
105+
pass, ok := secret.Data[core.BasicAuthPasswordKey]
106+
if !ok {
107+
return "", "", fmt.Errorf("DB password is not set in secret")
108+
}
109+
return string(user), string(pass), nil
110+
}
111+
112+
func (o *KubeDBClientBuilder) getConnectionString() (string, error) {
113+
user, pass, err := o.getMSSQLSACredentials()
114+
if err != nil {
115+
return "", err
116+
}
117+
118+
if o.podName != "" {
119+
o.url = o.getURL()
120+
}
121+
122+
// TODO: Add tlsConfig
123+
tlsConfig := ""
124+
//if o.db.Spec.RequireSSL && o.db.Spec.TLS != nil {
125+
// // get client-secret
126+
// var clientSecret core.Secret
127+
// err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: o.db.GetNamespace(), Name: o.db.GetCertSecretName(api.MSSQLClientCert)}, &clientSecret)
128+
// if err != nil {
129+
// return "", err
130+
// }
131+
// cacrt := clientSecret.Data["ca.crt"]
132+
// certPool := x509.NewCertPool()
133+
// certPool.AppendCertsFromPEM(cacrt)
134+
//
135+
// crt := clientSecret.Data["tls.crt"]
136+
// key := clientSecret.Data["tls.key"]
137+
// cert, err := tls.X509KeyPair(crt, key)
138+
// if err != nil {
139+
// return "", err
140+
// }
141+
// var clientCert []tls.Certificate
142+
// clientCert = append(clientCert, cert)
143+
//
144+
// // tls custom setup
145+
// if o.db.Spec.RequireSSL {
146+
// mssql_driver.RegisterTLSConfig(api.MSSQLTLSConfigCustom, &tls.Config{
147+
// RootCAs: certPool,
148+
// Certificates: clientCert,
149+
// })
150+
// tlsConfig = fmt.Sprintf("tls=%s", api.MSSQLTLSConfigCustom)
151+
// } else {
152+
// tlsConfig = fmt.Sprintf("tls=%s", api.MSSQLTLSConfigSkipVerify)
153+
// }
154+
//}
155+
156+
connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;database=master;%s", o.url, user, pass, tlsConfig)
157+
return connectionString, nil
158+
}

vendor/github.com/golang-sql/civil/CONTRIBUTING.md

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)