Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
minor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
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
Christian Knuchel
minor
Commits
a836433d
Commit
a836433d
authored
Sep 14, 2018
by
Fence
🌈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
what were they thinking - AVGN, circa 2006 AD
parent
5dc776ec
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
758 additions
and
24 deletions
+758
-24
LICENSE
LICENSE
+662
-0
add_major.py
add_major.py
+20
-0
gen_test_jwt.py
gen_test_jwt.py
+18
-0
minor.postman_collection.json
minor.postman_collection.json
+46
-8
minor/app.py
minor/app.py
+1
-1
minor/controller/music.py
minor/controller/music.py
+6
-5
minor/crypto_checker.py
minor/crypto_checker.py
+2
-7
minor/decorators.py
minor/decorators.py
+2
-2
minor/model.py
minor/model.py
+1
-1
No files found.
LICENSE
0 → 100644
View file @
a836433d
This diff is collapsed.
Click to expand it.
add_major.py
0 → 100644
View file @
a836433d
import
sys
from
mongoengine
import
connect
from
minor.model
import
MajorInstance
key
=
None
with
open
(
sys
.
argv
[
2
],
"r"
)
as
file
:
key
=
file
.
read
()
if
key
==
None
:
print
(
"oh no!"
)
exit
()
connect
(
"minor"
)
MajorInstance
(
issuer
=
sys
.
argv
[
1
],
key
=
key
).
save
()
print
(
"everything worked~"
)
gen_test_jwt.py
0 → 100644
View file @
a836433d
import
sys
import
jwt
from
datetime
import
datetime
,
timedelta
expires
=
15
payload
=
{
"song"
:
"5b9ae72fc0368e3b9c8a6027"
}
key
=
None
with
open
(
sys
.
argv
[
2
],
"r"
)
as
file
:
key
=
file
.
read
()
payload
[
"iss"
]
=
sys
.
argv
[
1
]
payload
[
"iat"
]
=
datetime
.
utcnow
()
payload
[
"exp"
]
=
datetime
.
utcnow
()
+
timedelta
(
expires
)
print
(
jwt
.
encode
(
payload
,
key
,
algorithm
=
'RS256'
))
minor.postman_collection.json
View file @
a836433d
{
"info"
:
{
"_postman_id"
:
"
47133917-aa5d-440f-ba7b-279ab5787a57
"
,
"name"
:
"minor"
,
"_postman_id"
:
"
b1cdfd5a-5601-4082-897a-1971d38f1315
"
,
"name"
:
"minor
copy
"
,
"schema"
:
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item"
:
[
...
...
@@ -30,7 +30,10 @@
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"body"
:
{},
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
""
},
"url"
:
{
"raw"
:
"{{url}}/api"
,
"host"
:
[
...
...
@@ -112,7 +115,10 @@
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"body"
:
{},
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
""
},
"url"
:
{
"raw"
:
"{{url}}/api/music/song/{{song_id}}/hasfile"
,
"host"
:
[
...
...
@@ -153,8 +159,8 @@
"formdata"
:
[
{
"key"
:
"file"
,
"
description"
:
"
"
,
"
type"
:
"file
"
"
type"
:
"file
"
,
"
value"
:
"
"
}
]
},
...
...
@@ -194,7 +200,10 @@
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"body"
:
{},
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
""
},
"url"
:
{
"raw"
:
"{{url}}/api/music/song/{{song_id}}/hasfile"
,
"host"
:
[
...
...
@@ -210,8 +219,30 @@
}
},
"response"
:
[]
},
{
"name"
:
"listen"
,
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"body"
:
{},
"url"
:
{
"raw"
:
""
}
},
"response"
:
[]
}
],
"auth"
:
{
"type"
:
"bearer"
,
"bearer"
:
[
{
"key"
:
"token"
,
"value"
:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJtaW5pd2EiLCJpYXQiOjE1MzY4NzgyNjIsImV4cCI6MTUzODE3NDI2Mn0.nw52vrtybuoiDa6fPUoMIaqAEUiqwVZcK6CR0U9dP9Q4P1-F6jADld3tLyQxIlX1P5J1oTh18pXywXcn3uikBNSjQNSzKhBW_0-HM2saBALuiP_gG_8hmCkfgPjItLTdJHe-bvCmerqc3lakMuPqKpZAxJmmi0PkbmsWNDmGEpnMkV5mWLXvaOF05yi1ayOdn2IzVDsgvy4TeV_2U2viaZ9D21MDBBEFqNiPMbLTpBBs68CgSn2eQa2w-wxuwDGyAh-UGUTPcjCv2DHmL0twxPEP3sOPMU0Lr9CYK0BSPL3igs1-GZ6dR5QAZTolgOgUw8CUbXNdIb89sP5lxgSdzA"
,
"type"
:
"string"
}
]
},
"event"
:
[
{
"listen"
:
"prerequest"
,
...
...
@@ -236,11 +267,18 @@
],
"variable"
:
[
{
"id"
:
"
c547da47-7193-43fd-ab64-435731330129
"
,
"id"
:
"
4d510edb-b692-4c37-b344-1999f25eaaaa
"
,
"key"
:
"url"
,
"value"
:
"http://127.0.0.1:5000/"
,
"type"
:
"string"
,
"description"
:
""
},
{
"id"
:
"1fc5d0c9-7320-4f4f-a2f4-2a0f4f7492a7"
,
"key"
:
"song_id"
,
"value"
:
"5b9ae72fc0368e3b9c8a6027"
,
"type"
:
"string"
,
"description"
:
""
}
]
}
\ No newline at end of file
minor/app.py
View file @
a836433d
...
...
@@ -6,7 +6,7 @@ from minor.controller import ApiController, MusicController
class
App
(
object
):
def
__init__
(
self
):
self
.
_flask
=
Flask
(
__name__
)
self
.
_flask
.
config
[
'MONGODB_SETTINGS'
]
=
{
'
DB'
:
'testing
'
}
self
.
_flask
.
config
[
'MONGODB_SETTINGS'
]
=
{
'
db'
:
'minor
'
}
from
minor.model
import
db
db
.
init_app
(
self
.
_flask
)
...
...
minor/controller/music.py
View file @
a836433d
...
...
@@ -13,13 +13,14 @@ from minor.util import get_ext
@
route
(
"/api/music"
)
class
MusicController
(
FlaskController
):
#
@auth_required
@
auth_required
@
route
(
"/listen"
)
def
listen
(
self
,
payload
=
None
):
if
"song"
in
payload
:
song
=
Song
.
objects
.
get
(
id
=
payload
[
"song"
])
if
song
is
not
None
:
filename
=
"./uploads/"
+
str
(
song
[
"_id"
])
+
".mp3"
print
(
dir
(
song
))
filename
=
"./uploads/"
+
str
(
song
.
id
)
+
".mp3"
print
(
filename
)
if
os
.
path
.
isfile
(
filename
):
def
generate
():
...
...
@@ -32,7 +33,7 @@ class MusicController(FlaskController):
else
:
return
jsonify
({
"code"
:
400
,
"message"
:
"bad_request"
}),
400
#
auth_required
#
@
auth_required
@
route
(
"/song/<id>"
)
def
song
(
self
,
id
,
payload
=
None
):
song
=
Song
.
objects
.
get
(
id
=
id
)
...
...
@@ -41,7 +42,7 @@ class MusicController(FlaskController):
else
:
return
jsonify
({
"code"
:
400
,
"message"
:
"bad_request"
}),
400
#
@auth_required
@
auth_required
@
route
(
"/song/<id>/hasfile"
)
def
song_has_file
(
self
,
id
,
payload
=
None
):
song
=
Song
.
objects
.
get
(
id
=
id
)
...
...
@@ -54,7 +55,7 @@ class MusicController(FlaskController):
else
:
return
jsonify
({
"code"
:
400
,
"message"
:
"bad_request"
}),
400
#
@auth_required
@
auth_required
@
json_required
@
route
(
"/song"
,
methods
=
[
"POST"
])
def
song_post
(
self
,
payload
=
None
):
...
...
minor/crypto_checker.py
View file @
a836433d
import
os
import
os.path
import
json
import
jwt
from
datetime
import
datetime
,
timedelta
import
requests
from
minor.model
import
MajorInstance
class
CryptoChecker
(
object
):
...
...
@@ -16,9 +11,9 @@ class CryptoChecker(object):
issuer
=
MajorInstance
.
objects
.
get
(
issuer
=
payload
[
"iss"
])
if
issuer
is
not
None
:
try
:
key
=
requests
.
get
(
issuer
[
"url"
]
+
"/auth/key"
).
text
key
=
issuer
.
key
checked_payload
=
jwt
.
decode
(
token
,
key
)
return
checked_payload
except
Exception
as
e
:
print
(
e
)
return
None
\ No newline at end of file
return
None
minor/decorators.py
View file @
a836433d
...
...
@@ -11,7 +11,7 @@ def auth_required(f):
auth
=
auth
.
split
(
" "
)
if
auth
[
0
]
==
"Bearer"
:
print
(
auth
[
1
])
payload
=
CryptoChecker
(
self
.
_db
).
check
(
auth
[
1
])
payload
=
CryptoChecker
(
"minor"
).
check
(
auth
[
1
])
if
payload
is
not
None
:
kwargs
[
"payload"
]
=
payload
return
f
(
self
,
*
args
,
**
kwargs
)
...
...
@@ -25,4 +25,4 @@ def json_required(f):
if
not
json_available
:
return
jsonify
({
"code"
:
400
,
"message"
:
"bad_request"
}),
400
return
f
(
*
args
,
**
kwargs
)
return
decorated_function
\ No newline at end of file
return
decorated_function
minor/model.py
View file @
a836433d
...
...
@@ -15,4 +15,4 @@ class Song(Document):
class
MajorInstance
(
Document
):
issuer
=
StringField
(
required
=
True
)
url
=
URLField
(
required
=
True
)
\ No newline at end of file
key
=
StringField
(
required
=
True
)
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