Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Portal API Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Kontr 2.0
Portal API Backend
Commits
2cbdd0bf
There was an error fetching the commit references. Please try again later.
Verified
Commit
2cbdd0bf
authored
6 years ago
by
Peter Stanko
Browse files
Options
Downloads
Patches
Plain Diff
Auth logging
parent
63291a78
No related branches found
No related tags found
1 merge request
!41
Removed unnecessary permissions
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
portal/logger.py
+8
-0
8 additions, 0 deletions
portal/logger.py
portal/service/auth.py
+8
-2
8 additions, 2 deletions
portal/service/auth.py
with
16 additions
and
2 deletions
portal/logger.py
+
8
−
0
View file @
2cbdd0bf
...
...
@@ -41,12 +41,16 @@ HANDLERS = {
},
'
portal_file
'
:
get_logger_file
(
'
portal
'
),
'
access_file
'
:
get_logger_file
(
'
access
'
),
'
auth_file
'
:
get_logger_file
(
'
auth
'
),
'
storage_file
'
:
get_logger_file
(
'
storage
'
),
'
flask_file
'
:
get_logger_file
(
'
flask
'
)
}
LOGGERS
=
{
'
portal
'
:
{
'
handlers
'
:
[
'
console
'
,
'
portal_file
'
],
'
level
'
:
'
DEBUG
'
,
'
propagate
'
:
True
},
'
portal.auth_log
'
:
{
'
handlers
'
:
[
'
console
'
,
'
auth_file
'
],
'
level
'
:
'
DEBUG
'
,
'
propagate
'
:
True
},
'
portal.access_log
'
:
{
'
handlers
'
:
[
'
console
'
,
'
access_file
'
],
'
level
'
:
'
DEBUG
'
,
'
propagate
'
:
True
},
...
...
@@ -101,4 +105,8 @@ def get_access_logger(*args, **kwargs):
return
logging
.
getLogger
(
'
portal.access_log
'
,
*
args
,
**
kwargs
)
def
get_auth_logger
(
*
args
,
**
kwargs
):
return
logging
.
getLogger
(
'
portal.auth_log
'
,
*
args
,
**
kwargs
)
ACCESS
=
get_access_logger
()
AUTH
=
get_auth_logger
()
This diff is collapsed.
Click to expand it.
portal/service/auth.py
+
8
−
2
View file @
2cbdd0bf
...
...
@@ -6,6 +6,7 @@ import logging
from
flask_jwt_extended
import
get_jwt_identity
from
portal.database.models
import
Client
from
portal.logger
import
AUTH
from
portal.service
import
errors
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -37,7 +38,6 @@ class AuthService:
raise
errors
.
PortalAPIError
(
400
,
message
=
"
Invalid login type.
"
)
identifier
=
data
.
get
(
'
identifier
'
,
None
)
secret
=
data
.
get
(
'
secret
'
,
None
)
return
types
[
login_type
](
identifier
,
secret
)
def
login_gitlab
(
self
,
identifier
:
str
,
secret
:
str
)
->
Client
:
...
...
@@ -50,12 +50,14 @@ class AuthService:
Returns(User): the authenticated user
"""
if
secret
is
None
:
AUTH
.
warning
(
f
"
[AUTH] Gitlab: No access token for
{
identifier
}
"
)
raise
errors
.
PortalAPIError
(
400
,
'
No gitlab access token found.
'
)
self
.
validate_gitlab_token
(
secret
,
username
=
identifier
)
user
=
self
.
_rest_service
.
find
.
user
(
identifier
,
throws
=
False
)
if
user
is
None
:
AUTH
.
warning
(
f
"
[AUTH] Gitlab: Invalid access token for
{
identifier
}
"
)
raise
errors
.
InvalidGitlabAccessTokenError
()
return
user
...
...
@@ -70,11 +72,13 @@ class AuthService:
"""
user
=
self
.
_rest_service
.
find
.
user
(
identifier
,
throws
=
False
)
if
user
is
None
or
secret
is
None
:
AUTH
.
warning
(
f
"
[AUTH] Login: Invalid user or secret for
{
identifier
}
"
)
raise
errors
.
IncorrectCredentialsError
()
if
user
.
verify_password
(
password
=
secret
):
AUTH
.
info
(
f
"
[AUTH] Login successful with password for
{
identifier
}
:
{
user
.
log_name
}
"
)
return
user
AUTH
.
warning
(
f
"
[AUTH] Login: Invalid credentials for
{
identifier
}
"
)
raise
errors
.
IncorrectCredentialsError
()
def
login_secret
(
self
,
identifier
:
str
,
secret
:
str
)
->
Client
:
...
...
@@ -89,7 +93,9 @@ class AuthService:
"""
client
=
self
.
_find_client_helper
(
identifier
)
if
client
.
verify_secret
(
secret
):
AUTH
.
info
(
f
"
[AUTH] Login successful with secret for
{
identifier
}
:
{
client
.
log_name
}
"
)
return
client
AUTH
.
warning
(
f
"
[AUTH] Login: Invalid credentials for
{
identifier
}
"
)
raise
errors
.
UnauthorizedError
(
f
"
[LOGIN] Invalid secret.
"
)
def
validate_gitlab_token
(
self
,
token
:
str
,
username
:
str
,
throws
:
bool
=
True
):
...
...
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