Skip to content

Commit

Permalink
finished adding 3 level logging
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Feb 9, 2020
1 parent fec979d commit 80bd2da
Show file tree
Hide file tree
Showing 41 changed files with 675 additions and 460 deletions.
2 changes: 2 additions & 0 deletions handlers/utilites.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func UseWebHandler(dbi db.Database, compressJtw bool, authURL string, logger *lg
var oauthManagerw m.OauthManager
oauthManagerw.Log = logger
var oauthMySqldbw msdb.MySQLOauthDB
oauthMySqldbw.Log = logger
oauthMySqldbw.DB = dbi
var oauthDbw odb.Oauth2DB
oauthDbw = &oauthMySqldbw
Expand All @@ -69,6 +70,7 @@ func UseRestHandler(dbi db.Database, assets string, compressJtw bool, authURL st
var oauthManager m.OauthManager
oauthManager.Log = logger
var oauthMySqldb msdb.MySQLOauthDB
oauthMySqldb.Log = logger
oauthMySqldb.DB = dbi
var oauthDb odb.Oauth2DB
oauthDb = &oauthMySqldb
Expand Down
Binary file modified main
Binary file not shown.
3 changes: 3 additions & 0 deletions mysqldb/accessToken_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
Expand All @@ -29,6 +30,8 @@ func TestMySQLOauthDBAcTokeni_Connect(t *testing.T) {
dbAti = &mydb

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAti

odbAti = &moadb
Expand Down
13 changes: 13 additions & 0 deletions mysqldb/accessToken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
Expand Down Expand Up @@ -58,6 +59,8 @@ func TestMySQLOauthDBAcToken_Connect(t *testing.T) {
mydb.MockRow2 = &getRow2

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAt

odbAt = &moadb
Expand Down Expand Up @@ -88,6 +91,8 @@ func TestMySQLOauthDBAcToken_AddAccessTokenTx(t *testing.T) {
mdbx.MockInsertID1 = 1
mtx.MyDBMock = &mdbx
var moadbtx MySQLOauthDB
var l lg.Logger
moadbtx.Log = &l
//moadbtx.Tx = &mtx
var odbbUri2TX = &moadbtx

Expand Down Expand Up @@ -122,6 +127,8 @@ func TestMySQLOauthDBAcToken_UpdateAccessTokenTx(t *testing.T) {

mtx.MyDBMock = &mdbx
var moadbtx MySQLOauthDB
var l lg.Logger
moadbtx.Log = &l
//moadbtx.Tx = &mtx
var odbbUri2TX = &moadbtx

Expand Down Expand Up @@ -156,6 +163,8 @@ func TestMySQLOauthDBAcToken_DeleteAccessTokenTx(t *testing.T) {

mtx.MyDBMock = &mdbx
var moadbtx MySQLOauthDB
var l lg.Logger
moadbtx.Log = &l
//moadbtx.Tx = &mtx
var odbbUri2TX = &moadbtx

Expand Down Expand Up @@ -202,6 +211,8 @@ func TestMySQLOauthDBAcToken_AddAccessToken2Tx(t *testing.T) {
mdbx.MockInsertID1 = 1
mtx.MyDBMock = &mdbx
var moadbtx MySQLOauthDB
var l lg.Logger
moadbtx.Log = &l
//moadbtx.Tx = &mtx
var odbbUri2TX = &moadbtx

Expand Down Expand Up @@ -237,6 +248,8 @@ func TestMySQLOauthDBAcToken_UpdateAccessToken2Tx(t *testing.T) {
mdbx.MockUpdateSuccess1 = true
mtx.MyDBMock = &mdbx
var moadbtx MySQLOauthDB
var l lg.Logger
moadbtx.Log = &l
//moadbtx.Tx = &mtx
var odbbUri2TX = &moadbtx

Expand Down
6 changes: 5 additions & 1 deletion mysqldb/allowedUri_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ package mysqldb

import (
"fmt"
"testing"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
"testing"
)

var dbAui db.Database
Expand All @@ -24,6 +26,8 @@ func TestMySQLOauthDBi_ConnectAllowURI(t *testing.T) {
dbAui = &mydb

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAui

odbAui = &moadb
Expand Down
6 changes: 5 additions & 1 deletion mysqldb/allowedUri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package mysqldb

import (
"fmt"
"testing"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
"testing"
)

var dbAu db.Database
Expand Down Expand Up @@ -45,6 +47,8 @@ func TestMySQLOauthDB_ConnectAllowURI(t *testing.T) {
mydb.MockDeleteSuccess1 = true

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAu

odbAu = &moadb
Expand Down
3 changes: 1 addition & 2 deletions mysqldb/authCodeRevolk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package mysqldb
*/

import (
"fmt"
"strconv"

odb "github.com/Ulbora/GoAuth2/oauth2database"
Expand Down Expand Up @@ -53,7 +52,7 @@ func (d *MySQLOauthDB) GetAuthCodeRevolk(ac int64) *odb.AuthCodeRevolk {
var a []interface{}
a = append(a, ac)
row := d.DB.Get(getAuthCodeRevolk, a...)
fmt.Println("row: ", row)
d.Log.Debug("row: ", row)
rtn := parseAuthCodeRevolkRow(&row.Row)
return rtn
}
Expand Down
3 changes: 3 additions & 0 deletions mysqldb/authCodeRevolk_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
Expand All @@ -28,6 +29,8 @@ func TestMySQLOauthDBAcRvi_Connect(t *testing.T) {
dbAcRvi = &mydb

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAcRvi

odbAcRvi = &moadb
Expand Down
5 changes: 5 additions & 0 deletions mysqldb/authCodeRevolk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
//"time"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
Expand Down Expand Up @@ -41,6 +42,8 @@ func TestMySQLOauthDBAcRv_Connect(t *testing.T) {
mydb.MockDeleteSuccess1 = true

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAcRv

odbAcRv = &moadb
Expand Down Expand Up @@ -115,6 +118,8 @@ func TestMySQLOauthDBAcRv_AddAuthCodeRevolkTx(t *testing.T) {

mtx.MyDBMock = &mdbx
var moadbtx MySQLOauthDB
var l lg.Logger
moadbtx.Log = &l
//moadbtx.DB = &mtx
var odbbUri2TX = &moadbtx

Expand Down
48 changes: 24 additions & 24 deletions mysqldb/authorizationCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (d *MySQLOauthDB) AddAuthorizationCode(code *odb.AuthorizationCode, at *odb
var cont bool
if rt != nil && rt.Token != "" {
rtsuc, rtID := d.AddRefreshToken(tx, rt)
fmt.Println("refTk res: ", rtsuc)
fmt.Println("refTk id: ", rtID)
d.Log.Debug("refTk res: ", rtsuc)
d.Log.Debug("refTk id: ", rtID)
if rtsuc {
at.RefreshTokenID = rtID
cont = true
Expand All @@ -51,15 +51,15 @@ func (d *MySQLOauthDB) AddAuthorizationCode(code *odb.AuthorizationCode, at *odb
if cont {
//at.RefreshTokenID = rtID
atsuc, acID := d.AddAccessToken(tx, at)
fmt.Println("atTk res: ", atsuc)
fmt.Println("atTk id: ", acID)
d.Log.Debug("atTk res: ", atsuc)
d.Log.Debug("atTk id: ", acID)
if atsuc {
code.AccessTokenID = acID
var a []interface{}
a = append(a, code.ClientID, code.UserID, code.Expires, code.AccessTokenID, code.RandonAuthCode, code.AlreadyUsed)
suc, id = tx.Insert(insertAuthCode, a...)
fmt.Println("ac res: ", suc)
fmt.Println("ac id: ", id)
d.Log.Debug("ac res: ", suc)
d.Log.Debug("ac id: ", id)
if suc {
//add code for adding scopes
var scSuc = true
Expand All @@ -69,10 +69,10 @@ func (d *MySQLOauthDB) AddAuthorizationCode(code *odb.AuthorizationCode, at *odb
acs.AuthorizationCode = id
acs.Scope = s
ssuc, sid := d.AddAuthCodeScope(tx, &acs)
fmt.Println("scope res: ", ssuc)
fmt.Println("scope id: ", sid)
d.Log.Debug("scope res: ", ssuc)
d.Log.Debug("scope id: ", sid)
if !ssuc {
fmt.Println("scope failed authcode: ", ssuc)
d.Log.Debug("scope failed authcode: ", ssuc)
scSuc = false
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func (d *MySQLOauthDB) GetAuthorizationCode(clientID int64, userID string) *[]od
}
}
// rtn := parseAuthCodeRow(&row.Row)
fmt.Println("authCode: ", rtn)
d.Log.Debug("authCode: ", rtn)
return &rtn
}

Expand All @@ -166,13 +166,13 @@ func (d *MySQLOauthDB) GetAuthorizationCodeByScope(clientID int64, userID string
var a []interface{}
a = append(a, clientID, userID, scope)
rows := d.DB.GetList(getAuthorizationCodeByClientUserScope, a...)
fmt.Println("rows in getbyscope: ", rows)
d.Log.Debug("rows in getbyscope: ", rows)
if rows != nil && len(rows.Rows) != 0 {
foundRows := rows.Rows
fmt.Println("foundRows in getbyscope: ", foundRows)
d.Log.Debug("foundRows in getbyscope: ", foundRows)
for r := range foundRows {
foundRow := foundRows[r]
fmt.Println("foundRow in getbyscope: ", foundRow)
d.Log.Debug("foundRow in getbyscope: ", foundRow)
ac, err := strconv.ParseInt((foundRow)[0], 10, 64)
if err == nil {
cid, err := strconv.ParseInt((foundRow)[1], 10, 64)
Expand All @@ -186,7 +186,7 @@ func (d *MySQLOauthDB) GetAuthorizationCodeByScope(clientID int64, userID string
//rtnc.AccessTokenID = atid
rtnc.RandonAuthCode = (foundRow)[3]
rtnc.AlreadyUsed, _ = strconv.ParseBool((foundRow)[4])
fmt.Println("rtnc in getbyscope: ", rtnc)
d.Log.Debug("rtnc in getbyscope: ", rtnc)
rtn = append(rtn, rtnc)
}
}
Expand All @@ -208,7 +208,7 @@ func (d *MySQLOauthDB) GetAuthorizationCodeByCode(code string) *odb.Authorizatio
a = append(a, code)
row := d.DB.Get(getAuthorizationCodeByCode, a...)
rtn := parseAuthCodeRow(&row.Row)
fmt.Println("authCode: ", rtn)
d.Log.Debug("authCode: ", rtn)
return rtn
}

Expand All @@ -220,8 +220,8 @@ func (d *MySQLOauthDB) DeleteAuthorizationCode(clientID int64, userID string) bo
}
//make this a list call
acodeList := d.GetAuthorizationCode(clientID, userID)
fmt.Println("auth code list: ", acodeList)
fmt.Println("auth code list: ", len(*acodeList))
d.Log.Debug("auth code list: ", acodeList)
d.Log.Debug("auth code list: ", len(*acodeList))
if len(*acodeList) == 0 {
suc = true
} else {
Expand All @@ -236,26 +236,26 @@ func (d *MySQLOauthDB) DeleteAuthorizationCode(clientID int64, userID string) bo
tx := d.DB.BeginTransaction()
// authCodeRevokeProcessor.deleteAuthCodeRevoke do this
rvkDel := d.DeleteAuthCodeRevolk(tx, acode.AuthorizationCode)
fmt.Println("delete refresh token: ", rvkDel)
d.Log.Debug("delete refresh token: ", rvkDel)
if rvkDel {
sdel := d.DeleteAuthCodeScopeList(tx, acode.AuthorizationCode)
fmt.Println("delete scope: ", sdel)
d.Log.Debug("delete scope: ", sdel)
// d.DeleteAuthCodeScopeList(tx, acode.AuthorizationCode)
if sdel {
var a []interface{}
//a = append(a, clientID, userID)
//acdel := tx.Delete(deleteAuthCode, a...)
a = append(a, acode.AuthorizationCode)
acdel := tx.Delete(deleteAuthCodeByCode, a...)
fmt.Println("delete authCode: ", acdel)
d.Log.Debug("delete authCode: ", acdel)
if acdel {
atdel := d.DeleteAccessToken(tx, acode.AccessTokenID)
fmt.Println("delete AccessToken: ", atdel)
d.Log.Debug("delete AccessToken: ", atdel)
if atdel {
var cont = true
if rtid > 0 {
cont = d.DeleteRefreshToken(tx, rtid)
fmt.Println("delete RefreshToken: ", cont)
d.Log.Debug("delete RefreshToken: ", cont)
}
if cont {
suc = true
Expand All @@ -282,7 +282,7 @@ func (d *MySQLOauthDB) DeleteAuthorizationCode(clientID int64, userID string) bo
}

func parseAuthCodeRow(foundRow *[]string) *odb.AuthorizationCode {
fmt.Println("foundRow in parseAuthCodeRow: ", foundRow)
//fmt.Println("foundRow in parseAuthCodeRow: ", foundRow)
var rtn odb.AuthorizationCode
if len(*foundRow) > 0 {
id, err := strconv.ParseInt((*foundRow)[0], 10, 64)
Expand All @@ -295,7 +295,7 @@ func parseAuthCodeRow(foundRow *[]string) *odb.AuthorizationCode {
//if err == nil {
// rtn.UserID = uid
cTime, err := time.Parse(odb.TimeFormat, (*foundRow)[3])
fmt.Println("time error:", err)
//fmt.Println("time error:", err)
if err == nil {
atid, err := strconv.ParseInt((*foundRow)[4], 10, 64)
if err == nil {
Expand Down
3 changes: 3 additions & 0 deletions mysqldb/authorizationCode_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
Expand All @@ -28,6 +29,8 @@ func TestMySQLOauthDBACi_Connect(t *testing.T) {
dbAci = &mydb

var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAci

odbAci = &moadb
Expand Down
Loading

0 comments on commit 80bd2da

Please sign in to comment.