Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Run an instance of Girder worker, connected to rabbitmq. The rabbitmq
service must be running.
"""
broker = 'amqp://guest@127.0.0.1'
Setting().set(WorkerSettings.BROKER, broker)
Setting().set(WorkerSettings.BACKEND, broker)
env = os.environ.copy()
env['C_FORCE_ROOT'] = 'true'
proc = subprocess.Popen([
'celery', '-A', 'girder_worker.app', 'worker', '--broker', broker, '--concurrency=1'],
close_fds=True, env=env)
yield True
proc.terminate()
proc.wait()
Setting().unset(WorkerSettings.BROKER)
Setting().unset(WorkerSettings.BACKEND)
def testSetSentryDSN(server):
Setting().set(DSN, TEST_DSN)
assert Setting().get(DSN) == TEST_DSN
def testEmptyInitSentryDSN(server):
assert Setting().get(DSN) == ''
def testGetSentryDSN(server):
Setting().set(DSN, TEST_DSN)
resp = server.request('/sentry/dsn')
assertStatusOk(resp)
assert resp.json['sentry_dsn'] == TEST_DSN
Setting().set(DSN, '')
if sys.platform != 'darwin':
# Automatically unmount when we try to mount again
options['auto_unmount'] = True
if fuseOptions:
for opt in fuseOptions.split(','):
if '=' in opt:
key, value = opt.split('=', 1)
value = (False if value.lower() == 'false' else
True if value.lower() == 'true' else value)
else:
key, value = opt, True
if key in ('use_ino', 'ro', 'rw') and options.get(key) != value:
logprint.warning('Ignoring the %s=%r option' % (key, value))
continue
options[key] = value
Setting().set(SettingKey.GIRDER_MOUNT_INFORMATION,
{'path': path, 'mounttime': time.time()})
FUSELogError(opClass, path, **options)
Set CORS headers that should be passed back with either a preflight OPTIONS
or a simple CORS request. We set these headers anytime there is an Origin
header present since browsers will simply ignore them if the request is not
cross-origin.
"""
origin = cherrypy.request.headers.get('origin')
if not origin:
# If there is no origin header, this is not a cross origin request
return
allowed = Setting().get(SettingKey.CORS_ALLOW_ORIGIN)
if allowed:
setResponseHeader('Access-Control-Allow-Credentials', 'true')
setResponseHeader(
'Access-Control-Expose-Headers', Setting().get(SettingKey.CORS_EXPOSE_HEADERS))
allowedList = {o.strip() for o in allowed.split(',')}
if origin in allowedList:
setResponseHeader('Access-Control-Allow-Origin', origin)
elif '*' in allowedList:
setResponseHeader('Access-Control-Allow-Origin', '*')
def getWorkerApiUrl():
"""
Return the API base URL to which the worker should callback to
write output information back to the server. This is controlled
via a system setting, and the default is to use the core server
root setting.
"""
apiUrl = Setting().get(PluginSettings.API_URL)
return apiUrl or getApiUrl()
def getUrl(cls, state):
loginUrl = Setting().get(constants.PluginSettings.GIRDER_LOGIN_URL)
clientId = Setting().get(constants.PluginSettings.GIRDER_CLIENT_ID)
if clientId is None:
raise Exception('No Girder client ID setting is present.')
if loginUrl is None:
raise Exception('No Girder login URL setting is present.')
query = urllib.parse.urlencode({
'clientId': clientId,
'redirect': '/'.join((getApiUrl(), 'oauth', 'girder', 'callback')),
'state': state,
'scope': ' '.join(cls._AUTH_SCOPES)
})
return '%s?%s' % (loginUrl, query)
def getClientIdSetting(self):
return Setting().get(constants.PluginSettings.BITBUCKET_CLIENT_ID)
:param model: the type of resource (e.g., user or collection)
:param resource: the resource document.
:returns: the fileSizeQuota. None for no quota (unlimited), otherwise
a positive integer.
"""
useDefault = resource[QUOTA_FIELD].get('useQuotaDefault', True)
quota = resource[QUOTA_FIELD].get('fileSizeQuota', None)
if useDefault:
if model == 'user':
key = PluginSettings.DEFAULT_USER_QUOTA
elif model == 'collection':
key = PluginSettings.DEFAULT_COLLECTION_QUOTA
else:
key = None
if key:
quota = Setting().get(key)
if not quota or quota < 0 or not isinstance(quota, six.integer_types):
return None
return quota