Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
10715b81
Commit
10715b81
authored
3 years ago
by
Francé Wilke
Browse files
Options
Downloads
Patches
Plain Diff
Add provider_id to api logs
parent
715cfebf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api_logs/api-logs.go
+17
-2
17 additions, 2 deletions
api_logs/api-logs.go
with
17 additions
and
2 deletions
api_logs/api-logs.go
+
17
−
2
View file @
10715b81
...
@@ -2,8 +2,8 @@ package api_logs
...
@@ -2,8 +2,8 @@ package api_logs
import
(
import
(
"github.com/thoas/go-funk"
"github.com/thoas/go-funk"
"gitlab.com/uafrica/go-utils/string_utils"
"net/url"
"net/url"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -37,14 +37,24 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
...
@@ -37,14 +37,24 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
userID
,
_
:=
claim
[
"UserID"
]
.
(
int64
)
userID
,
_
:=
claim
[
"UserID"
]
.
(
int64
)
username
,
_
:=
claim
[
"Username"
]
.
(
string
)
username
,
_
:=
claim
[
"Username"
]
.
(
string
)
accountID
,
_
:=
claim
[
"AccountID"
]
.
(
int64
)
accountID
,
_
:=
claim
[
"AccountID"
]
.
(
int64
)
providerID
,
_
:=
claim
[
"ProviderID"
]
.
(
int64
)
if
accountID
==
0
{
if
accountID
==
0
{
if
accountIDParam
,
ok
:=
req
.
QueryStringParameters
[
"account_id"
];
ok
{
if
accountIDParam
,
ok
:=
req
.
QueryStringParameters
[
"account_id"
];
ok
{
if
i64
,
err
:=
str
conv
.
Parse
Int
(
accountIDParam
,
10
,
64
);
err
==
nil
&&
i64
>
0
{
if
i64
,
err
:=
str
ing_utils
.
StringTo
Int
64
(
accountIDParam
);
err
==
nil
&&
i64
>
0
{
accountID
=
i64
accountID
=
i64
}
}
}
}
}
}
if
providerID
==
0
{
if
providerIDParam
,
ok
:=
req
.
QueryStringParameters
[
"provider_id"
];
ok
{
if
i64
,
err
:=
string_utils
.
StringToInt64
(
providerIDParam
);
err
==
nil
&&
i64
>
0
{
providerID
=
i64
}
}
}
typeString
:=
"api-incoming"
typeString
:=
"api-incoming"
if
funk
.
Contains
(
req
.
Path
,
"webhook"
)
{
if
funk
.
Contains
(
req
.
Path
,
"webhook"
)
{
typeString
=
"webhook-incoming"
typeString
=
"webhook-incoming"
...
@@ -67,6 +77,7 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
...
@@ -67,6 +77,7 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st
UserID
:
userID
,
UserID
:
userID
,
Username
:
username
,
Username
:
username
,
AccountID
:
accountID
,
AccountID
:
accountID
,
ProviderID
:
providerID
,
Request
:
ApiLogRequest
{
Request
:
ApiLogRequest
{
Headers
:
req
.
Headers
,
Headers
:
req
.
Headers
,
QueryParameters
:
req
.
QueryStringParameters
,
QueryParameters
:
req
.
QueryStringParameters
,
...
@@ -99,6 +110,8 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st
...
@@ -99,6 +110,8 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st
userID
,
_
:=
claim
[
"UserID"
]
.
(
int64
)
userID
,
_
:=
claim
[
"UserID"
]
.
(
int64
)
username
,
_
:=
claim
[
"Username"
]
.
(
string
)
username
,
_
:=
claim
[
"Username"
]
.
(
string
)
accountID
,
_
:=
claim
[
"AccountID"
]
.
(
int64
)
accountID
,
_
:=
claim
[
"AccountID"
]
.
(
int64
)
providerID
,
_
:=
claim
[
"ProviderID"
]
.
(
int64
)
params
:=
map
[
string
]
string
{}
params
:=
map
[
string
]
string
{}
parsedURL
,
err
:=
url
.
Parse
(
urlString
)
parsedURL
,
err
:=
url
.
Parse
(
urlString
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -125,6 +138,7 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st
...
@@ -125,6 +138,7 @@ func GenerateOutgoingAPILog(startTime time.Time, requestID *string, claim map[st
UserID
:
userID
,
UserID
:
userID
,
Username
:
username
,
Username
:
username
,
AccountID
:
accountID
,
AccountID
:
accountID
,
ProviderID
:
providerID
,
Request
:
ApiLogRequest
{
Request
:
ApiLogRequest
{
Headers
:
requestHeaders
,
Headers
:
requestHeaders
,
QueryParameters
:
params
,
QueryParameters
:
params
,
...
@@ -155,6 +169,7 @@ type ApiLog struct {
...
@@ -155,6 +169,7 @@ type ApiLog struct {
InitialAuthUsername
string
`json:"initial_auth_username,omitempty"`
InitialAuthUsername
string
`json:"initial_auth_username,omitempty"`
InitialAuthType
string
`json:"initial_auth_type,omitempty"`
InitialAuthType
string
`json:"initial_auth_type,omitempty"`
AccountID
int64
`json:"account_id,omitempty"`
AccountID
int64
`json:"account_id,omitempty"`
ProviderID
int64
`json:"provider_id,omitempty"`
UserID
int64
`json:"user_id,omitempty"`
UserID
int64
`json:"user_id,omitempty"`
Username
string
`json:"username,omitempty"`
Username
string
`json:"username,omitempty"`
SourceIP
string
`json:"source_ip,omitempty"`
//only logged for incoming API
SourceIP
string
`json:"source_ip,omitempty"`
//only logged for incoming API
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment