Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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 JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
e64faa67
Commit
e64faa67
authored
9 years ago
by
Gunnar Schaefer
Committed by
Renzo Frigato
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fail gracefully on uninitialized DB
parent
fb9a61a1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/base.py
+6
-2
6 additions, 2 deletions
api/base.py
api/config.py
+1
-1
1 addition, 1 deletion
api/config.py
api/mongo.py
+1
-1
1 addition, 1 deletion
api/mongo.py
with
8 additions
and
4 deletions
api/base.py
+
6
−
2
View file @
e64faa67
...
...
@@ -34,6 +34,10 @@ class RequestHandler(webapp2.RequestHandler):
access_token
=
self
.
request
.
headers
.
get
(
'
Authorization
'
,
None
)
drone_secret
=
self
.
request
.
headers
.
get
(
'
X-SciTran-Auth
'
,
None
)
site_id
=
config
.
site_id
()
if
site_id
is
None
:
self
.
abort
(
503
,
'
Database not initialized
'
)
# User (oAuth) authentication
if
access_token
and
self
.
app
.
config
[
'
oauth2_id_endpoint
'
]:
cached_token
=
self
.
app
.
db
.
authtokens
.
find_one
({
'
_id
'
:
access_token
})
...
...
@@ -63,7 +67,7 @@ class RequestHandler(webapp2.RequestHandler):
u
=
u
.
_replace
(
query
=
urllib
.
urlencode
(
query
,
True
))
provider_avatar
=
urlparse
.
urlunparse
(
u
)
else
:
headers
=
{
'
WWW-Authenticate
'
:
'
Bearer realm=
"
%s
"
, error=
"
invalid_token
"
, error_description=
"
Invalid OAuth2 token.
"'
%
config
.
site_id
()
}
headers
=
{
'
WWW-Authenticate
'
:
'
Bearer realm=
"
%s
"
, error=
"
invalid_token
"
, error_description=
"
Invalid OAuth2 token.
"'
%
site_id
}
self
.
abort
(
401
,
'
invalid oauth2 token
'
,
headers
=
headers
)
# 'Debug' (insecure) setting: allow request to act as requested user
...
...
@@ -87,7 +91,7 @@ class RequestHandler(webapp2.RequestHandler):
self
.
abort
(
402
,
remote_instance
+
'
is not an authorized remote instance
'
)
else
:
self
.
abort
(
401
,
'
no valid SSL client certificate
'
)
self
.
user_site
=
self
.
source_site
or
config
.
site_id
()
self
.
user_site
=
self
.
source_site
or
site_id
self
.
public_request
=
not
drone_request
and
not
self
.
uid
...
...
This diff is collapsed.
Click to expand it.
api/config.py
+
1
−
1
View file @
e64faa67
...
...
@@ -10,7 +10,7 @@ def _get_item(item):
global
last_update
,
latest_config
now
=
datetime
.
datetime
.
utcnow
()
if
now
-
last_update
>
datetime
.
timedelta
(
seconds
=
120
)
or
latest_config
is
None
:
latest_config
=
mongo
.
db
.
config
.
find_one
({
'
latest
'
:
True
})
latest_config
=
mongo
.
db
.
config
.
find_one
({
'
latest
'
:
True
})
or
{}
last_update
=
now
return
latest_config
.
get
(
item
)
...
...
This diff is collapsed.
Click to expand it.
api/mongo.py
+
1
−
1
View file @
e64faa67
...
...
@@ -4,4 +4,4 @@ db = None
def
configure_db
(
db_uri
):
global
db
db
=
pymongo
.
MongoClient
(
db_uri
,
j
=
True
).
get_default_database
()
db
=
pymongo
.
MongoClient
(
db_uri
,
j
=
True
,
connectTimeoutMS
=
2000
,
serverSelectionTimeoutMS
=
3000
).
get_default_database
()
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