Skip to content

Commit c7e2ac8

Browse files
authored
Adding logs for debugging (#10)
* Adding logs for debugging * Fix typo on readme file * Update zap values * Update readme file * Update zap values * Refactoring code * Update readme
1 parent 059c2c5 commit c7e2ac8

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,21 @@ Usage:
8484
baton-sql-server [command]
8585
8686
Available Commands:
87+
capabilities Get connector capabilities
8788
completion Generate the autocompletion script for the specified shell
8889
help Help about any command
8990
9091
Flags:
91-
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
92-
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
93-
--dsn string The connection string for connecting to SQL Server ($BATON_DSN)
94-
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
95-
-h, --help help for baton-sql-server
96-
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
97-
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
98-
-v, --version version for baton-sql-server
92+
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
93+
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
94+
--dsn string The connection string for connecting to SQL Server ($BATON_DSN)
95+
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
96+
-h, --help help for baton-sql-server
97+
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
98+
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
99+
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
100+
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
101+
-v, --version version for baton-sql-server
99102
100103
Use "baton-sql-server [command] --help" for more information about a command.
101104

cmd/baton-sql-server/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
)
1010

1111
var (
12-
dns = field.StringField("dns",
12+
dsn = field.StringField("dsn",
1313
field.WithDescription("The connection string for connecting to SQL Server"),
1414
field.WithRequired(true))
1515
)
1616

1717
// validateConfig is run after the configuration is loaded, and should return an error if it isn't valid.
1818
func validateConfig(_ context.Context, v *viper.Viper) error {
19-
if v.GetString(dns.FieldName) == "" {
19+
if v.GetString(dsn.FieldName) == "" {
2020
return fmt.Errorf("--dsn is required")
2121
}
2222

cmd/baton-sql-server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var version = "dev"
2020
func main() {
2121
ctx := context.Background()
2222

23-
_, cmd, err := config.DefineConfiguration(ctx, "baton-sql-server", getConnector, []field.SchemaField{dns}, nil)
23+
_, cmd, err := config.DefineConfiguration(ctx, "baton-sql-server", getConnector, []field.SchemaField{dsn}, nil)
2424
if err != nil {
2525
fmt.Fprintln(os.Stderr, err.Error())
2626
os.Exit(1)
@@ -41,7 +41,7 @@ func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, e
4141
return nil, err
4242
}
4343

44-
cb, err := connector.New(ctx, v.GetString(dns.FieldName))
44+
cb, err := connector.New(ctx, v.GetString(dsn.FieldName))
4545
if err != nil {
4646
l.Error("error creating connector", zap.Error(err))
4747
return nil, err

pkg/mssqldb/permissions.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
9+
"go.uber.org/zap"
910
)
1011

1112
type PermissionModel struct {
@@ -39,7 +40,10 @@ WHERE perms.state = 'G' OR perms.state = 'W'
3940
GROUP BY perms.grantee_principal_id, perms.state, principals.name, principals.type
4041
ORDER BY perms.grantee_principal_id ASC
4142
OFFSET @p1 ROWS FETCH NEXT @p2 ROWS ONLY`)
42-
43+
l.Debug("ListServerPermissions",
44+
zap.String("sql query", sb.String()),
45+
zap.Any("args", args),
46+
)
4347
rows, err := c.db.QueryxContext(ctx, sb.String(), args...)
4448
if err != nil {
4549
return nil, "", err
@@ -97,7 +101,10 @@ WHERE (perms.state = 'G' OR perms.state = 'W') AND (perms.class = 0 AND perms.ma
97101
GROUP BY perms.grantee_principal_id, perms.state, principals.name, principals.type
98102
ORDER BY perms.grantee_principal_id ASC
99103
OFFSET @p1 ROWS FETCH NEXT @p2 ROWS ONLY`)
100-
104+
l.Debug("ListDatabasePermissions",
105+
zap.String("sql query", sb.String()),
106+
zap.Any("args", args),
107+
)
101108
rows, err := c.db.QueryxContext(ctx, sb.String(), args...)
102109
if err != nil {
103110
return nil, "", err

pkg/mssqldb/roles.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ WHERE sys.server_role_members.role_principal_id = @p1
5151
ORDER BY
5252
sys.server_principals.principal_id ASC OFFSET @p2 ROWS FETCH NEXT @p3 ROWS ONLY
5353
`)
54-
54+
l.Debug("ListServerRolePrincipals",
55+
zap.String("sql query", sb.String()),
56+
zap.Any("args", args),
57+
)
5558
rows, err := c.db.QueryxContext(ctx, sb.String(), args...)
5659
if err != nil {
5760
return nil, "", err
@@ -106,7 +109,10 @@ WHERE type = 'R'
106109
ORDER BY
107110
principal_id ASC OFFSET @p1 ROWS FETCH NEXT @p2 ROWS ONLY
108111
`)
109-
112+
l.Debug("ListServerRoles",
113+
zap.String("sql query", sb.String()),
114+
zap.Any("args", args),
115+
)
110116
rows, err := c.db.QueryxContext(ctx, sb.String(), args...)
111117
if err != nil {
112118
return nil, "", err
@@ -161,7 +167,10 @@ WHERE type = 'R'
161167
ORDER BY
162168
principal_id ASC OFFSET @p1 ROWS FETCH NEXT @p2 ROWS ONLY
163169
`)
164-
170+
l.Debug("ListDatabaseRoles",
171+
zap.String("sql query", sb.String()),
172+
zap.Any("args", args),
173+
)
165174
rows, err := c.db.QueryxContext(ctx, sb.String(), args...)
166175
if err != nil {
167176
return nil, "", err
@@ -221,7 +230,10 @@ func (c *Client) ListDatabaseRolePrincipals(ctx context.Context, dbName string,
221230
dbName,
222231
dbName,
223232
)
224-
233+
l.Debug("ListDatabaseRolePrincipals",
234+
zap.String("sql query", query),
235+
zap.Any("args", args),
236+
)
225237
rows, err := c.db.QueryxContext(ctx, query, args...)
226238
if err != nil {
227239
return nil, "", err

0 commit comments

Comments
 (0)