Skip to content

Commit

Permalink
Merge pull request #2976 from gargaroff/htc/dev/dmontada-session-file…
Browse files Browse the repository at this point in the history
…-env

feat(credential_manager): allow users to overwrite location of session file
  • Loading branch information
csordasmarton authored Oct 19, 2020
2 parents 69b9f14 + 7c1d983 commit eebefed
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/web/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ The location of the password file can be configured by the `CC_PASS_FILE`
environment variable. This environment variable can also be used to setup
different credential files to login to the same server with a different user.

Furthermore, the location of the session file can be configured by the
`CC_SESSION_FILE` environment variable. This can be useful if CodeChecker does
not have the permission to create a session file under the user's home
directory (e.g. in some CI environments).

### Automatic login <a name="automatic-login"></a>

If authentication is required by the server and the user hasn't logged in but
Expand Down
8 changes: 8 additions & 0 deletions docs/web/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ environment variables:
It can also be used to setup different credential files to
login to the same server with a different user.
CC_SESSION_FILE The location of the session file where valid sessions are
stored. This file will be automatically created by
CodeChecker. By default CodeChecker will use
'~/.codechecker.session.json'. This can be used if
restrictive permissions forbid CodeChecker from creating
files in the users home directory (e.g. in a CI
environment).
The results can be viewed by connecting to such a server in a Web browser or
via 'CodeChecker cmd'.
```
Expand Down
8 changes: 8 additions & 0 deletions web/client/codechecker_client/cmd/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ def get_argparser_ctor_args():
It can also be used to setup different credential files to
login to the same server with a different user.
CC_SESSION_FILE The location of the session file where valid sessions are
stored. This file will be automatically created by
CodeChecker. By default CodeChecker will use
'~/.codechecker.session.json'. This can be used if
restrictive permissions forbid CodeChecker from creating
files in the users home directory (e.g. in a CI
environment).
The results can be viewed by connecting to such a server in a Web browser or
via 'CodeChecker cmd'.""",
Expand Down
6 changes: 3 additions & 3 deletions web/client/codechecker_client/credential_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
tokens.
"""


import json
import os
import re
Expand All @@ -21,7 +20,8 @@
from codechecker_common.logger import get_logger
from codechecker_common.util import load_json_or_empty

from codechecker_web.shared.env import check_file_owner_rw, get_password_file
from codechecker_web.shared.env import check_file_owner_rw, get_password_file,\
get_session_file
from codechecker_web.shared.version import SESSION_COOKIE_NAME as _SCN

LOG = get_logger('system')
Expand Down Expand Up @@ -95,7 +95,7 @@ def __init__(self):
self.__save = scfg_dict
self.__autologin = scfg_dict.get('client_autologin', True)
# Check and load token storage for user.
self.token_file = os.path.join(user_home, ".codechecker.session.json")
self.token_file = get_session_file()
LOG.info("Checking for local valid sessions.")

if os.path.exists(self.token_file):
Expand Down
7 changes: 7 additions & 0 deletions web/codechecker_web/shared/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def get_password_file():
".codechecker.passwords.json"))


def get_session_file():
""" Return the location of the CodeChecker session file. """
return os.environ.get("CC_SESSION_FILE",
os.path.join(os.path.expanduser("~"),
".codechecker.session.json"))


def get_user_input(msg):
"""
Get the user input.
Expand Down
4 changes: 3 additions & 1 deletion web/server/vue-cli/e2e/init.db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const url = `http://${host}:${port}`;
const CC_DIR = path.join(__dirname, "__codechecker");
const REPORTS_DIR = path.join(CC_DIR, "reports");
const PASSWORD_FILE = path.join(CC_DIR, "codechecker.passwords.json");
const SESSION_FILE = path.join(CC_DIR, "codechecker.session.json");

// List of products which will be added to the server.
const PRODUCTS = [
Expand Down Expand Up @@ -73,7 +74,8 @@ async function login (username) {
stdio: "inherit",
env: {
...process.env,
"CC_PASS_FILE": PASSWORD_FILE
"CC_PASS_FILE": PASSWORD_FILE,
"CC_SESSION_FILE": SESSION_FILE
}
});
}
Expand Down

0 comments on commit eebefed

Please sign in to comment.