Skip to content

Commit

Permalink
Fixes for 32-bit build compatibility (#32)
Browse files Browse the repository at this point in the history
* Introducing build matrix to validate compatibility before merging

* Switching back to local fork of denisenkom implementation of MSSQL driver, which compiles in 32 bit

* Adding win arm back to release
  • Loading branch information
tkielar-pgs authored Jul 19, 2022
1 parent 7c4feaf commit 8ba568a
Show file tree
Hide file tree
Showing 56 changed files with 177 additions and 1,417 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,32 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
goos:
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
steps:
- uses: actions/setup-go@v3
if: ${{ !(matrix.goos == 'darwin' && (matrix.goarch == '386' || matrix.goarch == 'arm')) }}
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
if: ${{ !(matrix.goos == 'darwin' && (matrix.goarch == '386' || matrix.goarch == 'arm')) }}
- run: go mod download
if: ${{ !(matrix.goos == 'darwin' && (matrix.goarch == '386' || matrix.goarch == 'arm')) }}
- run: go build -v .
if: ${{ !(matrix.goos == 'darwin' && (matrix.goarch == '386' || matrix.goarch == 'arm')) }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}

generate:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -68,6 +87,6 @@ jobs:
TF_MSSQL_IMG_TAG: ${{ matrix.mssql }}
TF_AZURE_SUBSCRIPTION_ID: fbf513eb-321c-40b8-8dbb-bb939ea1fe5a
TF_AZURE_RESOURCE_GROUP: terraform-mssql-tests
AZURE_CLIENT_ID: 874f61a5-e5c1-4811-b6bf-e6a1135bea5a
AZURE_TENANT_ID: b3e5a293-6975-4239-9637-c963e8d90b7a
AZURE_CLIENT_ID: 139df37c-3e72-4283-80c1-7be62f3d8e64
AZURE_TENANT_ID: 7029fc72-c85c-4ecd-86f6-1ab9852b576f
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ builds:
ignore:
- goos: darwin
goarch: '386'
- goos: windows
goarch: arm
binary: '{{ .ProjectName }}_v{{ .Version }}'

archives:
Expand Down
33 changes: 0 additions & 33 deletions deps/go-mssqldb/.github/workflows/pr-validation.yml

This file was deleted.

14 changes: 0 additions & 14 deletions deps/go-mssqldb/CONTRIBUTING.md

This file was deleted.

1 change: 0 additions & 1 deletion deps/go-mssqldb/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Copyright (c) 2012 The Go Authors. All rights reserved.
Copyright (c) Microsoft Corporation.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand Down
47 changes: 8 additions & 39 deletions deps/go-mssqldb/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# A pure Go MSSQL driver for Go's database/sql package

[![Go Reference](https://pkg.go.dev/badge/github.com/microsoft/go-mssqldb.svg)](https://pkg.go.dev/github.com/microsoft/go-mssqldb)
[![Build status](https://ci.appveyor.com/api/projects/status/jrln8cs62wj9i0a2?svg=true)](https://ci.appveyor.com/project/microsoft/go-mssqldb)
[![codecov](https://codecov.io/gh/microsoft/go-mssqldb/branch/master/graph/badge.svg)](https://codecov.io/gh/microsoft/go-mssqldb)
[![Go Reference](https://pkg.go.dev/badge/github.com/denisenkom/go-mssqldb.svg)](https://pkg.go.dev/github.com/denisenkom/go-mssqldb)
[![Build status](https://ci.appveyor.com/api/projects/status/jrln8cs62wj9i0a2?svg=true)](https://ci.appveyor.com/project/denisenkom/go-mssqldb)
[![codecov](https://codecov.io/gh/denisenkom/go-mssqldb/branch/master/graph/badge.svg)](https://codecov.io/gh/denisenkom/go-mssqldb)

## Install

Requires Go 1.8 or above.

Install with `go get github.com/microsoft/go-mssqldb` .
Install with `go get github.com/denisenkom/go-mssqldb` .

## Connection Parameters and DSN

Expand All @@ -32,7 +32,7 @@ Other supported formats are listed below.
### Connection parameters for ODBC and ADO style connection strings

* `server` - host or host\instance (default localhost)
* `port` - specifies the host\instance port (default 1433). If instance name is provided but no port, the driver will use SQL Server Browser to discover the port.
* `port` - used only when there is no instance in server (default 1433)

### Less common parameters

Expand Down Expand Up @@ -130,7 +130,6 @@ The credential type is determined by the new `fedauth` connection string paramet
* `fedauth=ActiveDirectoryDefault` - authenticates using a chained set of credentials. The chain is built from EnvironmentCredential -> ManagedIdentityCredential->AzureCLICredential. See [DefaultAzureCredential docs](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#configure-defaultazurecredential) for instructions on setting up your host environment to use it. Using this option allows you to have the same connection string in a service deployment as on your interactive development machine.
* `fedauth=ActiveDirectoryManagedIdentity` or `fedauth=ActiveDirectoryMSI` - authenticates using a system-assigned or user-assigned Azure Managed Identity.
* `user id=<identity id>` - optional id of user-assigned managed identity. If empty, system-assigned managed identity is used.
* `resource id=<resource id>` - optional resource id of user-assigned managed identity. If empty, system-assigned managed identity or user id are used (if both user id and resource id are provided, resource id will be used)
* `fedauth=ActiveDirectoryInteractive` - authenticates using credentials acquired from an external web browser. Only suitable for use with human interaction.
* `applicationclientid=<application id>` - This guid identifies an Azure Active Directory enterprise application that the AAD admin has approved for accessing Azure SQL database resources in the tenant. This driver does not have an associated application id of its own.

Expand All @@ -141,7 +140,7 @@ import (
"net/url"
// Import the Azure AD driver module (also imports the regular driver package)
"github.com/microsoft/go-mssqldb/azuread"
"github.com/denisenkom/go-mssqldb/azuread"
)
func ConnectWithMSI() (*sql.DB, error) {
Expand Down Expand Up @@ -281,19 +280,6 @@ are supported:
* "github.com/golang-sql/civil".Time -> time
* mssql.TVP -> Table Value Parameter (TDS version dependent)

Using an `int` parameter will send a 4 byte value (int) from a 32bit app and an 8 byte value (bigint) from a 64bit app.
To make sure your integer parameter matches the size of the SQL parameter, use the appropriate sized type like `int32` or `int8`.

```go
// If this is passed directly as a parameter,
// the SQL parameter generated would be nvarchar
name := "Bob"
// If the user_name is defined as varchar,
// it needs to be converted like this:
db.QueryContext(ctx, `select * from t2 where user_name = @p1;`, mssql.VarChar(name))
// Note: Mismatched data types on table and parameter may cause long running queries
```

## Important Notes

* [LastInsertId](https://golang.org/pkg/database/sql/#Result.LastInsertId) should
Expand All @@ -302,9 +288,9 @@ db.QueryContext(ctx, `select * from t2 where user_name = @p1;`, mssql.VarChar(na
or add a `select ID = convert(bigint, SCOPE_IDENTITY());` to the end of your
query (ref [SCOPE_IDENTITY](https://docs.microsoft.com/en-us/sql/t-sql/functions/scope-identity-transact-sql)).
This will ensure you are getting the correct ID and will prevent a network round trip.
* [NewConnector](https://godoc.org/github.com/microsoft/go-mssqldb#NewConnector)
* [NewConnector](https://godoc.org/github.com/denisenkom/go-mssqldb#NewConnector)
may be used with [OpenDB](https://golang.org/pkg/database/sql/#OpenDB).
* [Connector.SessionInitSQL](https://godoc.org/github.com/microsoft/go-mssqldb#Connector.SessionInitSQL)
* [Connector.SessionInitSQL](https://godoc.org/github.com/denisenkom/go-mssqldb#Connector.SessionInitSQL)
may be set to set any driver specific session settings after the session
has been reset. If empty the session will still be reset but use the database
defaults in Go1.10+.
Expand Down Expand Up @@ -360,20 +346,3 @@ Use the native "@Name" parameters instead with the "sqlserver" driver name.
To fix SQL Server 2008 R2 issue, install SQL Server 2008 R2 Service Pack 2.
To fix SQL Server 2008 issue, install Microsoft SQL Server 2008 Service Pack 3 and Cumulative update package 3 for SQL Server 2008 SP3.
More information: <http://support.microsoft.com/kb/2653857>
# Contributing
This project is a fork of [https://github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) and welcomes new and previous contributors. For more informaton on contributing to this project, please see [Contributing](./CONTRIBUTING.md).
For more information on the roadmap for go-mssqldb, [project plans](https://github.com/microsoft/go-mssqldb/projects) are available for viewing and discussion.
# Microsoft Open Source Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
Resources:
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [[email protected]](mailto:[email protected]) with questions or concerns
41 changes: 0 additions & 41 deletions deps/go-mssqldb/SECURITY.md

This file was deleted.

6 changes: 4 additions & 2 deletions deps/go-mssqldb/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 1.0.{build}
image:
- Visual Studio 2015

clone_folder: c:\gopath\src\github.com\microsoft\go-mssqldb
clone_folder: c:\gopath\src\github.com\denisenkom\go-mssqldb

environment:
GOPATH: c:\gopath
Expand All @@ -13,6 +13,8 @@ environment:
DATABASE: test
GOVERSION: 113
matrix:
- GOVERSION: 18
SQLINSTANCE: SQL2017
- GOVERSION: 19
SQLINSTANCE: SQL2017
- GOVERSION: 110
Expand Down Expand Up @@ -48,7 +50,7 @@ install:
- go env
- go get -u github.com/golang-sql/civil
- go get -u github.com/golang-sql/sqlexp

build_script:
- go build

Expand Down
2 changes: 1 addition & 1 deletion deps/go-mssqldb/azuread/azuread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"testing"

mssql "github.com/microsoft/go-mssqldb"
mssql "github.com/denisenkom/go-mssqldb"
)

func TestAzureSqlAuth(t *testing.T) {
Expand Down
30 changes: 13 additions & 17 deletions deps/go-mssqldb/azuread/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
mssql "github.com/microsoft/go-mssqldb"
"github.com/microsoft/go-mssqldb/msdsn"
mssql "github.com/denisenkom/go-mssqldb"
"github.com/denisenkom/go-mssqldb/msdsn"
)

const (
Expand Down Expand Up @@ -39,7 +39,6 @@ type azureFedAuthConfig struct {
tenantID string
clientSecret string
certificatePath string
resourceID string

// AD password/managed identity/interactive
user string
Expand Down Expand Up @@ -94,7 +93,6 @@ func (p *azureFedAuthConfig) validateParameters(params map[string]string) error
// When using MSI, to request a specific client ID or user-assigned identity,
// provide the ID in the "user id" parameter
p.adalWorkflow = mssql.FedAuthADALWorkflowMSI
p.resourceID, _ = params["resource id"]
p.clientID, _ = splitTenantAndClientID(params["user id"])
case strings.EqualFold(fedAuthWorkflow, ActiveDirectoryApplication) || strings.EqualFold(fedAuthWorkflow, ActiveDirectoryServicePrincipal):
p.adalWorkflow = mssql.FedAuthADALWorkflowPassword
Expand Down Expand Up @@ -167,26 +165,24 @@ func (p *azureFedAuthConfig) provideActiveDirectoryToken(ctx context.Context, se
case ActiveDirectoryServicePrincipal, ActiveDirectoryApplication:
switch {
case p.certificatePath != "":
certData, err := os.ReadFile(p.certificatePath)
if err != nil {
certs, key, err := azidentity.ParseCertificates(certData, []byte(p.clientSecret))
if err != nil {
cred, err = azidentity.NewClientCertificateCredential(tenant, p.clientID, certs, key, nil)
}
certFile, inErr := os.ReadFile(p.certificatePath)
if inErr != nil {
err = inErr
break
}
certs, key, inErr := azidentity.ParseCertificates(certFile, ([]byte)(p.clientSecret))
if inErr != nil {
err = inErr
break
}
cred, err = azidentity.NewClientCertificateCredential(tenant, p.clientID, certs, key, nil)
default:
cred, err = azidentity.NewClientSecretCredential(tenant, p.clientID, p.clientSecret, nil)
}
case ActiveDirectoryPassword:
cred, err = azidentity.NewUsernamePasswordCredential(tenant, p.applicationClientID, p.user, p.password, nil)
case ActiveDirectoryMSI, ActiveDirectoryManagedIdentity:
if p.resourceID != "" {
cred, err = azidentity.NewManagedIdentityCredential(&azidentity.ManagedIdentityCredentialOptions{ID: azidentity.ResourceID(p.resourceID)})
} else if p.clientID != "" {
cred, err = azidentity.NewManagedIdentityCredential(&azidentity.ManagedIdentityCredentialOptions{ID: azidentity.ClientID(p.clientID)})
} else {
cred, err = azidentity.NewManagedIdentityCredential(nil)
}
cred, err = azidentity.NewManagedIdentityCredential(&azidentity.ManagedIdentityCredentialOptions{ID: azidentity.ClientID(p.clientID)})
case ActiveDirectoryInteractive:
cred, err = azidentity.NewInteractiveBrowserCredential(&azidentity.InteractiveBrowserCredentialOptions{TenantID: tenant, ClientID: p.applicationClientID})

Expand Down
17 changes: 4 additions & 13 deletions deps/go-mssqldb/azuread/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package azuread
import (
"testing"

mssql "github.com/microsoft/go-mssqldb"
"github.com/microsoft/go-mssqldb/msdsn"
mssql "github.com/denisenkom/go-mssqldb"
"github.com/denisenkom/go-mssqldb/msdsn"
)

func TestValidateParameters(t *testing.T) {
Expand Down Expand Up @@ -84,17 +84,8 @@ func TestValidateParameters(t *testing.T) {
dsn: "server=someserver.database.windows.net;fedauth=ActiveDirectoryManagedIdentity;user id=identity-client-id",
expected: &azureFedAuthConfig{
adalWorkflow: mssql.FedAuthADALWorkflowMSI,
clientID: "identity-client-id",
fedAuthWorkflow: ActiveDirectoryManagedIdentity,
},
},
{
name: "managed identity with resource id",
dsn: "server=someserver.database.windows.net;fedauth=ActiveDirectoryManagedIdentity;resource id=/subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name}",
expected: &azureFedAuthConfig{
adalWorkflow: mssql.FedAuthADALWorkflowMSI,
resourceID: "/subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name}",
fedAuthWorkflow: ActiveDirectoryManagedIdentity,
clientID: "identity-client-id",
fedAuthWorkflow: ActiveDirectoryManagedIdentity,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion deps/go-mssqldb/azuread/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"database/sql"
"database/sql/driver"

mssql "github.com/microsoft/go-mssqldb"
mssql "github.com/denisenkom/go-mssqldb"
)

// DriverName is the name used to register the driver
Expand Down
Loading

0 comments on commit 8ba568a

Please sign in to comment.