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
208a9d57
Commit
208a9d57
authored
Oct 15, 2020
by
Raphael Beer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: mongodb authentication
parent
854c3ab7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
backend.py
backend.py
+8
-1
db.py
db.py
+4
-4
docker-entry.sh
docker-entry.sh
+5
-1
No files found.
backend.py
View file @
208a9d57
...
...
@@ -555,6 +555,8 @@ parser.add_argument('--host', type=str, default='127.0.0.1', help='hostname/ip w
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-username'
,
type
=
str
,
default
=
None
,
help
=
'user with read/write permissions to --mongo-db'
)
parser
.
add_argument
(
'--mongo-password'
,
type
=
str
,
default
=
None
,
help
=
'password for --mongo-username'
)
parser
.
add_argument
(
'--twitter-auth-key'
,
type
=
str
,
default
=
None
,
help
=
'auth key for twitter guest session'
,
required
=
True
)
parser
.
add_argument
(
'--cors-allow'
,
type
=
str
,
default
=
None
,
help
=
'value for Access-Control-Allow-Origin header'
)
args
=
parser
.
parse_args
()
...
...
@@ -588,7 +590,12 @@ if args.debug is not None:
def
run
():
global
db
db
=
connect
(
host
=
args
.
mongo_host
,
port
=
args
.
mongo_port
)
db
=
connect
(
host
=
args
.
mongo_host
,
port
=
args
.
mongo_port
,
username
=
args
.
mongo_username
,
password
=
args
.
mongo_password
)
loop
=
asyncio
.
get_event_loop
()
loop
.
run_until_complete
(
login_accounts
(
accounts
,
args
.
cookie_dir
))
loop
.
run_until_complete
(
login_guests
())
...
...
db.py
View file @
208a9d57
...
...
@@ -4,7 +4,7 @@ import sys
from
pymongo
import
MongoClient
,
errors
as
MongoErrors
,
DESCENDING
class
Database
:
def
__init__
(
self
,
host
=
None
,
port
=
27017
,
db
=
'tester'
):
def
__init__
(
self
,
host
=
None
,
port
=
27017
,
db
=
'tester'
,
username
=
None
,
password
=
None
):
# collection name definitions
RESULTS_COLLECTION
=
'results'
RATELIMIT_COLLECTION
=
'rate-limits'
...
...
@@ -13,7 +13,7 @@ class Database:
print
(
'[mongoDB] Connecting to '
+
host
+
':'
+
str
(
port
))
print
(
'[mongoDB] Using Database `'
+
db
+
'`'
)
# client and DB
self
.
client
=
MongoClient
(
host
,
port
,
serverSelectionTimeoutMS
=
3
)
self
.
client
=
MongoClient
(
host
,
port
,
serverSelectionTimeoutMS
=
3
,
username
=
username
,
password
=
password
)
self
.
db
=
self
.
client
[
db
]
# collections
...
...
@@ -41,8 +41,8 @@ class Database:
def
get_result_by_screen_name
(
self
,
screen_name
):
return
self
.
results
.
find_one
({
"profile.screen_name"
:
screen_name
},
sort
=
[(
"_id"
,
DESCENDING
)],
projection
=
{
"_id"
:
False
})
def
connect
(
host
=
None
,
port
=
27017
,
db
=
'tester'
):
def
connect
(
host
=
None
,
port
=
27017
,
db
=
'tester'
,
username
=
None
,
password
=
None
):
if
host
is
None
:
raise
ValueError
(
'[mongoDB] Database constructor needs a `host`name or ip!'
)
return
Database
(
host
=
host
,
port
=
port
,
db
=
db
)
return
Database
(
host
=
host
,
port
=
port
,
db
=
db
,
username
=
username
,
password
=
password
)
docker-entry.sh
View file @
208a9d57
...
...
@@ -10,7 +10,9 @@ echo "--host "$HOST""
echo
"--mongo-host
$MONGO_HOST
"
echo
"--mongo-port
$MONGO_PORT
"
echo
"--mongo-db
$MONGO_DB
"
echo
"--twitter-auth-key --NOT SHOWING--"
echo
"--mongo-username
$MONGO_USERNAME
"
echo
"--mongo-password --REDACTED--"
echo
"--twitter-auth-key --REDACTED--"
echo
"--cors-allow
$CORS_HOST
"
python3
-u
./backend.py
\
...
...
@@ -23,5 +25,7 @@ python3 -u ./backend.py \
--mongo-host
$MONGO_HOST
\
--mongo-port
$MONGO_PORT
\
--mongo-db
$MONGO_DB
\
--mongo-username
$MONGO_USERNAME
\
--mongo-password
$MONGO_PASSWORD
\
--twitter-auth-key
$TWITTER_AUTH_KEY
\
--cors-allow
$CORS_HOST
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