Skip to content

Commit

Permalink
Run storage limit
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Jan 18, 2018
1 parent 62e4a27 commit a54adef
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/server_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"max_run_count": 200,
"authentication": {
"enabled" : false,
"realm_name" : "CodeChecker Privileged server",
Expand Down
24 changes: 24 additions & 0 deletions docs/server_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CodeChecker server configuration
====================================

The server's configuration is stored in the server's *workspace* folder, in
`server_config.json`. This file is created, at the first start of the server,
using the package's installed `config/server_config.json` as a template.

> **NOTICE!** `session_config.json` file has been deprecated.
Table of Contents
=================
* [Run limitation](#run-limitations)
* [Authentication](#authentication)

## Run limitation
The `max_run_count` section of the config file controls how many runs can be
stored on the server for a product.

If this field is not present in the config file or the value of this field is a
negative value, run storage becomes unlimited.

## Authentication
For authentication configuration options see the
[Authentication](authentication.md) documentation.
20 changes: 20 additions & 0 deletions libcodechecker/server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ class ThriftRequestHandler(object):
"""

def __init__(self,
manager,
Session,
product,
auth_session,
Expand All @@ -514,6 +515,7 @@ def __init__(self,
raise ValueError("Cannot initialize request handler without "
"a product to serve.")

self.__manager = manager
self.__product = product
self.__auth_session = auth_session
self.__config_database = config_database
Expand Down Expand Up @@ -1840,6 +1842,24 @@ def massStoreRun(self, name, tag, version, b64zip, force):
shared.ttypes.ErrorCode.GENERAL,
'Storage of ' + name + ' is already going!')

max_run_count = self.__manager.get_max_run_count()
# If max_run_count is not set in the config file, it will allow
# the user to upload unlimited runs.
if max_run_count:
run_count = session.query(Run.id).count()

# If we are not updating a run or the run count is reached the
# limit it will throw an exception.
if not run and run_count >= max_run_count:
remove_run_count = run_count - max_run_count + 1
raise shared.ttypes.RequestFailed(
shared.ttypes.ErrorCode.GENERAL,
'You reached the maximum number of allowed runs '
'({0}/{1})! Please remove at least {2} run(s) before '
'you try it again.'.format(run_count,
max_run_count,
remove_run_count))

with util.TemporaryDirectory() as zip_dir:
# Unzip sent data.
unzip(b64zip, zip_dir)
Expand Down
1 change: 1 addition & 0 deletions libcodechecker/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def do_POST(self):
self.__check_prod_db(product)

acc_handler = ReportHandler_v6(
self.server.manager,
product.session_factory,
product,
auth_session,
Expand Down
10 changes: 10 additions & 0 deletions libcodechecker/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def __init__(self, root_sha, force_auth=False):
scfg_dict = {'authentication': {'enabled': False}}
scfg_dict.update(load_server_cfg(server_cfg_file))

self.__max_run_count = scfg_dict["max_run_count"] \
if "max_run_count" in scfg_dict else None

self.__auth_config = scfg_dict["authentication"]

if force_auth:
Expand Down Expand Up @@ -406,6 +409,13 @@ def is_valid(self, token, access=False):
return any(_sess.token == token and _sess.still_valid(access)
for _sess in SessionManager.__valid_sessions)

def get_max_run_count(self):
"""
Returns the maximum storable run count. If the value is None it means
we can upload unlimited number of runs.
"""
return self.__max_run_count

def get_session(self, token, access=False):
"""Gets the privileged session object based
based on the token.
Expand Down

0 comments on commit a54adef

Please sign in to comment.