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
1f3b2fa3
Commit
1f3b2fa3
authored
9 years ago
by
Kevin S. Hahn
Browse files
Options
Downloads
Patches
Plain Diff
disables apps features if apps_path not defined
parent
bfb34763
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api.py
+6
-1
6 additions, 1 deletion
api.py
api.wsgi
+6
-1
6 additions, 1 deletion
api.wsgi
apps.py
+19
-3
19 additions, 3 deletions
apps.py
with
31 additions
and
5 deletions
api.py
+
6
−
1
View file @
1f3b2fa3
...
...
@@ -136,7 +136,7 @@ if __name__ == '__main__':
arg_parser
.
add_argument
(
'
--port
'
,
default
=
'
8080
'
,
help
=
'
TCP port to listen on [8080]
'
)
arg_parser
.
add_argument
(
'
--db_uri
'
,
help
=
'
SciTran DB URI
'
,
default
=
'
mongodb://localhost/scitran
'
)
arg_parser
.
add_argument
(
'
--data_path
'
,
help
=
'
path to storage area
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--apps_path
'
,
help
=
'
path to apps storage
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--apps_path
'
,
help
=
'
path to apps storage
'
)
arg_parser
.
add_argument
(
'
--log_level
'
,
help
=
'
log level [info]
'
,
default
=
'
info
'
)
arg_parser
.
add_argument
(
'
--ssl_cert
'
,
help
=
'
path to SSL certificate file, containing private key and certificate chain
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--site_id
'
,
help
=
'
site ID for Scitran Central [local]
'
,
default
=
'
local
'
)
...
...
@@ -163,6 +163,11 @@ if __name__ == '__main__':
os
.
makedirs
(
app
.
config
[
'
quarantine_path
'
])
if
not
os
.
path
.
exists
(
app
.
config
[
'
upload_path
'
]):
os
.
makedirs
(
app
.
config
[
'
upload_path
'
])
if
not
application
.
config
[
'
apps_path
'
]:
log
.
warning
(
'
apps_path is not defined. Apps functionality disabled
'
)
else
:
if
not
os
.
path
.
exists
(
application
.
config
[
'
apps_path
'
]):
os
.
makedirs
(
application
.
config
[
'
apps_path
'
])
db_client
=
pymongo
.
MongoReplicaSetClient
(
args
.
db_uri
)
if
'
replicaSet
'
in
args
.
db_uri
else
pymongo
.
MongoClient
(
args
.
db_uri
)
app
.
db
=
db_client
.
get_default_database
()
...
...
This diff is collapsed.
Click to expand it.
api.wsgi
+
6
−
1
View file @
1f3b2fa3
...
...
@@ -18,7 +18,7 @@ os.umask(0o022)
ap = argparse.ArgumentParser()
ap.add_argument('--db_uri', help='SciTran DB URI', required=True)
ap.add_argument('--data_path', help='path to storage area', required=True)
ap.add_argument('--apps_path', help='path to apps storage'
, required=True
)
ap.add_argument('--apps_path', help='path to apps storage')
ap.add_argument('--ssl_cert', help='path to SSL certificate file, containing private key and certificate chain', required=True)
ap.add_argument('--api_uri', help='api uri, with https:// prefix')
ap.add_argument('--site_id', help='site ID for Scitran Central [local]', default='local')
...
...
@@ -49,6 +49,11 @@ if not os.path.exists(application.config['quarantine_path']):
os.makedirs(application.config['quarantine_path'])
if not os.path.exists(application.config['upload_path']):
os.makedirs(application.config['upload_path'])
if not application.config['apps_path']:
log.warning('apps_path is not defined. Apps functionality disabled')
else:
if not os.path.exists(application.config['apps_path']):
os.makedirs(application.config['apps_path'])
# connect to db
application.db = None
...
...
This diff is collapsed.
Click to expand it.
apps.py
+
19
−
3
View file @
1f3b2fa3
...
...
@@ -20,6 +20,7 @@ log = logging.getLogger('nimsapi.jobs')
import
tempdir
as
tempfile
import
base
import
util
# TODO: create schemas to verify various json payloads
APP_SCHEMA
=
{
...
...
@@ -64,18 +65,27 @@ class Apps(base.RequestHandler):
"""
Return information about the all the apps.
"""
def
get
(
self
):
apps_path
=
self
.
app
.
config
.
get
(
'
apps_path
'
)
if
not
apps_path
:
self
.
abort
(
503
,
'
GET api/apps/<id> unavailable. apps_path not defined
'
)
return
list
(
self
.
app
.
db
.
apps
.
find
())
def
count
(
self
):
apps_path
=
self
.
app
.
config
.
get
(
'
apps_path
'
)
if
not
apps_path
:
self
.
abort
(
503
,
'
GET api/apps/<id> unavailable. apps_path not defined
'
)
return
self
.
app
.
db
.
apps
.
count
()
def
post
(
self
):
"""
Create a new App.
"""
# this handles receive and writing the file
# but the the json validation and database is handled by util.
apps_path
=
self
.
app
.
config
[
'
apps_path
'
]
if
not
apps_path
:
self
.
abort
(
503
,
'
POST api/apps unavailable. apps_path not defined
'
)
if
self
.
public_request
:
# TODO: how to handle auth during bootstrap?
self
.
abort
(
403
,
'
must be logged in to upload apps
'
)
apps_path
=
self
.
app
.
config
[
'
apps_path
'
]
app_meta
=
None
with
tempfile
.
TemporaryDirectory
(
prefix
=
'
.tmp
'
,
dir
=
apps_path
)
as
tempdir_path
:
hash_
=
hashlib
.
sha1
()
...
...
@@ -100,21 +110,27 @@ class Apps(base.RequestHandler):
except
(
ValueError
,
jsonschema
.
ValidationError
)
as
e
:
self
.
abort
(
400
,
str
(
e
))
util
.
insert_app
(
self
.
app
.
db
,
app_temp
,
apps_path
,
app_meta
=
app_meta
)
# pass meta info, prevent re-reading
log
.
debug
(
'
Recieved App: %s
'
%
app_
info
.
get
(
'
_id
'
))
log
.
debug
(
'
Recieved App: %s
'
%
app_
meta
.
get
(
'
_id
'
))
class
App
(
base
.
RequestHandler
):
def
get
(
self
,
_id
):
# TODO: auth? should viewing apps be restricted?
apps_path
=
self
.
app
.
config
.
get
(
'
apps_path
'
)
if
not
apps_path
:
self
.
abort
(
503
,
'
GET api/apps/<id> unavailable. apps_path not defined
'
)
return
self
.
app
.
db
.
apps
.
find_one
({
'
_id
'
:
_id
})
def
get_file
(
self
,
_id
):
apps_path
=
self
.
app
.
config
.
get
(
'
apps_path
'
)
if
not
apps_path
:
self
.
abort
(
503
,
'
GET api/apps/<id> unavailable. apps_path not defined
'
)
if
self
.
public_request
:
# this will most often be a drone request
self
.
abort
(
403
,
'
must be logged in to download apps
'
)
name
,
version
=
_id
.
split
(
'
:
'
)
fn
=
'
%s-%s.tar
'
%
(
name
,
version
)
fp
=
os
.
path
.
join
(
self
.
app
.
config
[
'
apps_path
'
]
,
name
,
fn
)
fp
=
os
.
path
.
join
(
apps_path
,
name
,
fn
)
self
.
response
.
app_iter
=
open
(
fp
,
'
rb
'
)
self
.
response
.
headers
[
'
Content-Length
'
]
=
str
(
os
.
path
.
getsize
(
fp
))
# must be set after setting app_iter
self
.
response
.
headers
[
'
Content-Type
'
]
=
'
application/octet-stream
'
...
...
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