Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
shadowban-eu-backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
shadowban-eu-backend
Commits
ace9d1e1
Commit
ace9d1e1
authored
Aug 22, 2019
by
Raphael Beer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove/Change: --mongo-collection arg / hard coded db collection names
parent
0b038131
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
backend.py
backend.py
+0
-1
db.py
db.py
+14
-9
No files found.
backend.py
View file @
ace9d1e1
...
...
@@ -406,7 +406,6 @@ parser.add_argument('--port', type=int, default=8080, help='port which to listen
parser
.
add_argument
(
'--mongo-host'
,
type
=
str
,
default
=
'localhost'
,
help
=
'hostname or IP of mongoDB service to connect to'
)
parser
.
add_argument
(
'--mongo-port'
,
type
=
int
,
default
=
27017
,
help
=
'port of mongoDB service to connect to'
)
parser
.
add_argument
(
'--mongo-db'
,
type
=
str
,
default
=
'tester'
,
help
=
'name of mongo database to use'
)
parser
.
add_argument
(
'--mongo-collection'
,
type
=
str
,
default
=
'results'
,
help
=
'name of collection to save test results to'
)
args
=
parser
.
parse_args
()
db
=
connect
(
host
=
args
.
mongo_host
,
port
=
args
.
mongo_port
)
...
...
db.py
View file @
ace9d1e1
...
...
@@ -4,18 +4,23 @@ import sys
from
pymongo
import
MongoClient
,
errors
as
MongoErrors
class
Database
:
def
__init__
(
self
,
host
=
None
,
port
=
27017
,
db
=
'tester'
,
collection_name
=
'results'
):
def
__init__
(
self
,
host
=
None
,
port
=
27017
,
db
=
'tester'
):
# collection name definitions
RESULTS_COLLECTION
=
'results'
RATELIMIT_COLLECTION
=
'rate-limits'
try
:
print
(
'[mongoDB] Connecting to '
+
host
+
':'
+
str
(
port
))
print
(
'[mongoDB] Using Collection `'
+
collection_name
+
'` in Database `'
+
db
+
'`'
)
print
(
'[mongoDB] Using Database `'
+
db
+
'`'
)
# client and DB
self
.
client
=
MongoClient
(
host
,
port
,
serverSelectionTimeoutMS
=
3
)
self
.
db
=
self
.
client
[
db
]
# collection for test results
self
.
results
=
self
.
db
[
collection_name
]
# collection for rate limit monitoring
self
.
rate_limits
=
self
.
db
[
'rate-limits'
]
# test connection immediately, instead of
# collections
self
.
results
=
self
.
db
[
RESULTS_COLLECTION
]
self
.
rate_limits
=
self
.
db
[
RATELIMIT_COLLECTION
]
# Test connection immediately, instead of
# when trying to write in a request, later.
self
.
client
.
admin
.
command
(
'ismaster'
)
except
MongoErrors
.
ServerSelectionTimeoutError
:
...
...
@@ -33,8 +38,8 @@ class Database:
def
write_rate_limit
(
self
,
data
):
self
.
rate_limits
.
insert_one
(
data
)
def
connect
(
host
=
None
,
port
=
27017
,
db
=
'tester'
,
collection_name
=
'results'
):
def
connect
(
host
=
None
,
port
=
27017
,
db
=
'tester'
):
if
host
is
None
:
raise
ValueError
(
'[mongoDB] Database constructor needs a `host`name or ip!'
)
return
Database
(
host
=
host
,
port
=
port
,
db
=
db
,
collection_name
=
collection_name
)
return
Database
(
host
=
host
,
port
=
port
,
db
=
db
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment