Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snyk] Security upgrade axios from 0.21.1 to 0.21.3 #49

Open
wants to merge 202 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
60d208a
Split the API into files with clearer role
arthur-flam Nov 1, 2020
2d399c2
Better performance
arthur-flam Nov 1, 2020
807d9bd
Refactor how we fix at Samsung Windows permissions after the runs
arthur-flam Nov 19, 2020
66c7fae
Make it possible to not cache the user. Useful for migrations.
arthur-flam Nov 24, 2020
6b1f0b1
Database path normalization to avoid common issues
arthur-flam Nov 24, 2020
824476a
Fix bit-accuray checks
arthur-flam Dec 1, 2020
22f3165
Pass the branch
arthur-flam Dec 8, 2020
26bb1de
created_date not nullable
arthur-flam Dec 8, 2020
a7a9b96
Permissions fix
arthur-flam Dec 8, 2020
74d4e1e
Add imports
arthur-flam Dec 8, 2020
fa04d06
Clearer code
arthur-flam Dec 8, 2020
763c81f
Add docs
arthur-flam Dec 8, 2020
b753b02
Fix env
arthur-flam Dec 8, 2020
546ab5e
Support matrix configs with deltas over base
arthur-flam Dec 16, 2020
14532f6
Avoid mutability issues
arthur-flam Dec 16, 2020
ed2408c
Check configs are expanded
arthur-flam Dec 20, 2020
f8e7a36
Avoid issues with special characters in file names
arthur-flam Dec 23, 2020
0d4f7cf
Redo failed runs
arthur-flam Dec 23, 2020
8f19ed3
Ignore bad input
arthur-flam Jan 4, 2021
217f7c8
Compare vs the origin
arthur-flam Jan 5, 2021
3928d76
Cast to str
arthur-flam Jan 5, 2021
cb278b9
Ignore None aliases
arthur-flam Jan 7, 2021
f0cc809
Show some info better
arthur-flam Jan 11, 2021
e30214f
Fixed link
arthur-flam Jan 12, 2021
05141d3
Shorter paths
arthur-flam Jan 19, 2021
a41c934
[SIRC] workaround if we use "user" in output dirs
arthur-flam Jan 19, 2021
79b4242
login button, User model
itamar87 Jan 20, 2021
4ec055f
add log-in dialog
itamar87 Jan 24, 2021
f31cbb5
Fail if pending jobs have failed
arthur-flam Feb 3, 2021
e3046d2
Change GitLab update to generic function and move QAQBoard-specific c…
Feb 8, 2021
535b7c8
Cosmetic changes
arthur-flam Feb 8, 2021
af29c2d
Wrong param name
arthur-flam Feb 8, 2021
035f0e7
Update qa.py
arthur-flam Feb 9, 2021
b307ee0
add SideUserMenu
itamar87 Feb 9, 2021
5d4d5ef
Remove extra print
arthur-flam Feb 10, 2021
c7ada98
Print the correct job
arthur-flam Feb 10, 2021
f3ce123
Avoid errors when some folders don't exist
arthur-flam Feb 10, 2021
d87037d
[SIRC] sircdevops fix
arthur-flam Feb 10, 2021
6ed1538
More flexible bit-accuracy ignores
arthur-flam Feb 10, 2021
9b073c8
Fix wrong Path.is_absolute() usage
arthur-flam Feb 11, 2021
a433ab3
login + logout on AppSider
itamar87 Feb 12, 2021
371459c
login + logout from ProjectsList page
itamar87 Feb 13, 2021
f208604
Add login packages
itamar87 Feb 14, 2021
8ffd57a
cleanup
itamar87 Feb 14, 2021
7cc426b
get ldap cfg from envs, save user full_name
itamar87 Feb 14, 2021
2056e00
Save the user than started each run
arthur-flam Feb 15, 2021
8676ff1
Supprt redoing outputs with non-default types
arthur-flam Feb 15, 2021
31592e6
Fix setTimeout fork bomb
arthur-flam Feb 15, 2021
5160988
Expose redo logs and improve error messages
arthur-flam Feb 15, 2021
a350480
Support globs
arthur-flam Feb 15, 2021
6ebe99b
Better error message
arthur-flam Feb 15, 2021
e718614
Dont use default configs when specifying configs via matrix batches
arthur-flam Feb 17, 2021
fbe767f
Expose redo logs more clearly
arthur-flam Feb 17, 2021
faaba67
Re-enabled redo
arthur-flam Feb 17, 2021
bb0000a
Finer grained use of GIT_COMMIT and GIT_BRANCH
arthur-flam Feb 17, 2021
639897d
update poetry.lock
itamar87 Feb 18, 2021
02786a3
add user state with redux
itamar87 Feb 18, 2021
155fe20
More flexible per-input configurations in batches
arthur-flam Feb 18, 2021
4d85c76
IS_LDAP env for authentication
itamar87 Feb 22, 2021
b251322
Ignore --share when CI=true
arthur-flam Feb 23, 2021
41e8075
Install by default scikit-optimize
arthur-flam Mar 2, 2021
bfe2e8a
Better error messages
arthur-flam Mar 2, 2021
9e239e3
Better error message
arthur-flam Mar 4, 2021
c9f9500
Fix API for save_artifacts if the repo storage changed
arthur-flam Mar 4, 2021
00af86f
Check that the manifest fiel exists before redirecting to it
arthur-flam Mar 4, 2021
3ca34d0
Add index
arthur-flam Mar 4, 2021
4a23daf
Add FIXME - currently redo is broken if we rely on CLI params
arthur-flam Mar 4, 2021
d940a4b
Workaround common filesystem issues
arthur-flam Mar 4, 2021
b4173ca
Better error message
arthur-flam Mar 4, 2021
e03d5b2
Split save_outputs_manifest in 2
arthur-flam Mar 4, 2021
a4804aa
Add default video viewer
arthur-flam Mar 4, 2021
8cbfd32
Don't ever disable tuning
arthur-flam Mar 4, 2021
1838b78
Show the real image values in color tooltips
arthur-flam Mar 8, 2021
a621b78
Avoid deleting if outputs remain
arthur-flam Mar 8, 2021
caf07cc
Support projects not configured with gitlab via an integration
arthur-flam Mar 8, 2021
ec0f508
Improve color tooltip
arthur-flam Mar 8, 2021
2e795c9
Sync formatting in tooltip
arthur-flam Mar 9, 2021
75fc328
Remove bug
arthur-flam Mar 9, 2021
113c262
Fix missing import
arthur-flam Mar 9, 2021
6a69339
Fix error message
arthur-flam Mar 9, 2021
203b425
Simple cache
arthur-flam Mar 9, 2021
0c7d1cb
Better help
arthur-flam Mar 9, 2021
e24fa45
Better caching
arthur-flam Mar 10, 2021
9c91bd1
better docs
arthur-flam Mar 10, 2021
4c66daa
Fix type
arthur-flam Mar 10, 2021
5176f6b
quickfix
arthur-flam Mar 10, 2021
7f688ff
Better tooltip caching
arthur-flam Mar 14, 2021
722d11d
Solve issues at startup due to copying the connection pool on fork
arthur-flam Mar 14, 2021
ea1e3a5
Solve permission issues during dev
arthur-flam Mar 14, 2021
aaf9160
Update deps
arthur-flam Mar 14, 2021
e5ceee4
Support both max_memory and memory
arthur-flam Mar 14, 2021
e5d4b12
Sent 1 tooltip req max until the server caches the image
arthur-flam Mar 14, 2021
6e47d7c
Fix syntax
arthur-flam Mar 15, 2021
07b583d
let's delay python3.8 syntax until the host supports it...
arthur-flam Mar 15, 2021
fb16ebd
<3 417MB images
arthur-flam Mar 15, 2021
a028886
[SIRC] add sudo
arthur-flam Mar 21, 2021
7b6fe90
Configure the uwsgi queue size
arthur-flam Mar 21, 2021
0a4c285
[SIRC] UWSGI_UID can sudo
arthur-flam Mar 21, 2021
a5f2fdf
Better uwsgi setup
arthur-flam Mar 21, 2021
86574dc
Use uswgi with the cheaper algo
arthur-flam Mar 21, 2021
4642a70
Always restart the cron container
arthur-flam Mar 21, 2021
e900bdd
Start the containers with net.core.somaxconn=1024
arthur-flam Mar 21, 2021
b1891b6
Update gitignore
arthur-flam Mar 21, 2021
3f0630c
Provide default for UWSGI_LISTEN_QUEUE_SIZE
arthur-flam Mar 21, 2021
efe8d45
Mount setup.py
arthur-flam Mar 21, 2021
643e196
More dev instructions
arthur-flam Mar 21, 2021
9b2eb5c
Less verbosity
arthur-flam Mar 21, 2021
0e4ca64
Formatting and less logs
arthur-flam Mar 21, 2021
7342d85
Better commented-out log options
arthur-flam Mar 21, 2021
9e8e0c4
Support GIT_MESSAGE and GIT_AUTHORED_DATETIME for easier usage outsi…
arthur-flam Mar 21, 2021
a9c06ae
Print URL and tentative parallel parameter sampling support
arthur-flam Mar 21, 2021
1759dc2
Fixup
arthur-flam Mar 21, 2021
6504b46
Update backup script
arthur-flam Mar 21, 2021
1af89b7
Update gitignore
arthur-flam Mar 21, 2021
010cdf5
Read pre-compressed gzip files
arthur-flam Mar 21, 2021
dbd35b7
Update SQL query
arthur-flam Mar 21, 2021
3b8b79e
Simpler user handling
arthur-flam Mar 21, 2021
b92483b
Remove strict uwsgi config until we figure it out
arthur-flam Mar 21, 2021
3006e58
Dont hardcode any port
arthur-flam Mar 21, 2021
2d7a33e
Better docs
arthur-flam Mar 22, 2021
f9f037f
Updated gitignore
arthur-flam Mar 22, 2021
62febce
Better help label
arthur-flam Mar 22, 2021
c9e876d
less obstrusive sign
arthur-flam Mar 22, 2021
6d48593
Fallback to sudo
arthur-flam Mar 31, 2021
03a7376
Remove filter
arthur-flam Mar 31, 2021
18a8d39
Add shm_size for the db
arthur-flam Apr 1, 2021
b669566
Parametrize PGHOST via ENV
arthur-flam Apr 1, 2021
2090bf0
Typo in docs
arthur-flam Apr 1, 2021
eadbdb6
Feature/jenkins integration
itamar87 Apr 1, 2021
7d0c485
Use SECRET_KEY
arthur-flam Apr 1, 2021
09fcc93
Formatting
arthur-flam Apr 1, 2021
eecc5ed
Refactor login
arthur-flam Apr 1, 2021
8cdb80d
WIP
arthur-flam Apr 1, 2021
1d7357e
Avoid startup errors
arthur-flam Apr 1, 2021
a72868f
Fix indentation
arthur-flam Apr 4, 2021
2e21d9f
Add missing prop, broke refresh on delete
arthur-flam Apr 4, 2021
d34f4a9
fix: syntax
arthur-flam Apr 5, 2021
0e41acc
Smarter redo using the original job parameters
arthur-flam Apr 5, 2021
f27d37d
Review actions/reducer
arthur-flam Apr 5, 2021
3681e60
Add instructions for development
arthur-flam Apr 5, 2021
be2e35d
Better UI
arthur-flam Apr 5, 2021
e5564f2
Auth API teweaks
arthur-flam Apr 5, 2021
e2eb31b
Added logout
arthur-flam Apr 5, 2021
b097b5c
Proxy image requests to gitlab servers. It avoid issues with mixed co…
arthur-flam Apr 7, 2021
c9aae43
Fixed default gitlab badge
arthur-flam Apr 7, 2021
a90ccf7
Highlight login menu
arthur-flam Apr 7, 2021
e51c26f
LDAP docs
arthur-flam Apr 7, 2021
2efaa8d
update poetry.lock with authentication packages
itamar87 Apr 8, 2021
6e00565
Fix LSF issues
arthur-flam Apr 8, 2021
4d4f4ed
if not user: user = create_user(user_info)
itamar87 Apr 8, 2021
730ec90
Pass GITLAB_AUTH to backend containers
arthur-flam Apr 11, 2021
66f7e8e
Remove debug pring
arthur-flam Apr 12, 2021
4afaa41
Remove debug pring
arthur-flam Apr 12, 2021
b7bfb40
allow Tuning for logged-in users only
itamar87 Apr 18, 2021
834da34
run tuning as logged-in user
itamar87 Apr 18, 2021
4695cc8
Fix remove undefined var
arthur-flam Apr 18, 2021
e57e459
Less strict jenkins integration
arthur-flam Apr 18, 2021
8cb8a01
Always add CORS headers, even on e.g. 404
arthur-flam Apr 19, 2021
c0441c0
Fix bad filter updates
arthur-flam Apr 20, 2021
a406da2
Filter milestones
arthur-flam Apr 20, 2021
80063f8
Show when identical files are compared
arthur-flam Apr 20, 2021
11a69d8
UI improvement
arthur-flam Feb 8, 2022
ae3d7e2
Toogle side-by-side / inline
arthur-flam Apr 21, 2021
3f9c401
Order matters
arthur-flam Apr 21, 2021
ffa323c
No animations to make the diff feel better
arthur-flam Apr 21, 2021
920fe67
Fix passing correct args
arthur-flam Apr 26, 2021
4f30d88
Fix support for --share
arthur-flam Apr 26, 2021
7519ae1
Fix optimizer with --parallel
arthur-flam Apr 26, 2021
b2e2203
Add support for parallel_sampling in the optim config file
arthur-flam Apr 27, 2021
c730975
Avoid bad redirects
arthur-flam Apr 27, 2021
99b9e6a
Fix GIT_MESSAGE / GIT_AUTHORED_DATETIME
arthur-flam Apr 27, 2021
6dca0b0
Improved tuning UX
arthur-flam Apr 29, 2021
38dfc57
better UX
arthur-flam Apr 29, 2021
2ccf571
better optim
arthur-flam Apr 29, 2021
45f5d51
Scroll to bottom button in logs
arthur-flam Apr 29, 2021
8be5024
Better error message
arthur-flam May 2, 2021
bd45674
Replace moment with luxon
arthur-flam May 4, 2021
bb2b4cd
Compare versus runs from different projects
arthur-flam May 6, 2021
a09cbae
Export supports ref-projects
arthur-flam May 6, 2021
fd94103
Use new_project instead of the default project as needed
arthur-flam May 6, 2021
9608bfd
more space
arthur-flam May 6, 2021
ca18828
Fix list of commits
arthur-flam May 9, 2021
37fa9ed
Added an API to update commits (PUT /output/:id)
arthur-flam May 9, 2021
a4bc0f0
Added a UI menu to mark pending runs as finished
arthur-flam May 9, 2021
fad10f6
Work with ref_project
arthur-flam May 9, 2021
8ea7bee
Move runs to an existing or new batch
arthur-flam May 9, 2021
a11764e
Better error message
arthur-flam May 10, 2021
32e90f8
Added soft delete
arthur-flam May 11, 2021
c08cfb7
Updated npm/build setup
arthur-flam May 11, 2021
24be8df
Don't ignore parsing errors
arthur-flam May 18, 2021
407407e
Don't do a layout with thirds if there diff but not reference
arthur-flam May 19, 2021
7db2dba
Support --strict bit accuracy checks and always write input manifests
arthur-flam May 19, 2021
b2f0811
fix
arthur-flam May 19, 2021
c35473c
Error when runs are missing, better logs, --share support
arthur-flam May 23, 2021
9219d6d
Remove unused imports
arthur-flam May 23, 2021
0309635
Better sort UI
arthur-flam May 23, 2021
dd2ea0a
Fix sort when metrics can have 0 as values
arthur-flam May 23, 2021
1fa7bb4
Remove useless columns in table view
arthur-flam May 23, 2021
3ce7227
Even better sort UI
arthur-flam May 23, 2021
e4321c0
Remoive useless components
arthur-flam May 24, 2021
a574cbf
Fix bit-accuracy check with run from multiple users
arthur-flam May 26, 2021
c79f1e1
fix: webapp/package.json & webapp/package-lock.json to reduce vulnera…
snyk-bot Feb 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
migration/
cache.*.json
user-quotas.json
build/
build_qadocs/
log.lsf.txt
log.txt
ssl/
commits/
user/
drafts/

image.batches.yaml
iter.batches.yaml
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ variables:
.deploy: &deploy
stage: deploy
script:
- ssh qa "bash -c \"cd $(pwd) && source .envrc && docker-compose -f docker-compose.yml -f production.yml -f sirc.yml up -d --build\""
- ssh $DOCKER_HOST "bash -c \"cd $(pwd) && source .envrc && ./at-sirc-before-up.py && docker-compose -f docker-compose.yml -f production.yml -f sirc.yml up -d --build\""

deploy:production:
<<: *deploy
Expand Down
7 changes: 6 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ RUN apt-get update -qq \
# https://www.psycopg.org/docs/install.html#install-from-source
# https://www.psycopg.org/docs/faq.html#faq-compile
RUN apt-get update \
# postgresql and toolchain
&& apt-get install -y libpq-dev gcc \
# login packages
&& apt-get install -y libsasl2-dev libldap2-dev libssl-dev \
&& apt-get clean

# At SIRC we need to be able to turn into any user to delete their output files
RUN apt-get update && apt-get install -y sudo

# If we want uwsgi's routing support
# https://uwsgi-docs.readthedocs.io/en/latest/InternalRouting.html
Expand Down Expand Up @@ -83,7 +88,7 @@ CMD ["/qaboard/backend/init.sh"]

# Where we keep a cache of application data (e.g. git clones)
VOLUME /var/qaboard

RUN mkdir -p /var/qaboard && chmod -R 777 /var/qaboard


# TODO:
Expand Down
17 changes: 17 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@
QA-Board's backend built as a [flask](https://flask.pocoo.org) application. It exposes an HTTP API used to read/write all the metadata on QA-Board's runs.

## How to start a development backend
1. First get the code:
```bash
git clone git@gitlab-srv:common-infrastructure/qaboard.git
cd qaboard
```

2. If you want to run a frontend, [go to the README](../webapp/README.md) and without docker run `npm install`.

3. Edit at the top-level of the repository _development.yml_, and replace `arthurf` with your user. Edit _services/backend/passwd_ and add a line with your user, looking like `arthurf:*:11611:10:Arthur Flam:/home/arthurf:/bin/tcsh`. You can get it with `getent passwd | grep arthurf`.

4. Start the server:

```bash
docker-compose -f docker-compose.yml -f development.yml up -d

# for more build logs
export BUILDKIT_PROGRESS=plain
```

> **Tip:** If you called `npm install` in the *webapp/*, (see the [README](../webapp)), a frontend connected to the dev backend will also be up on port 3000.
Expand All @@ -23,6 +36,10 @@ Consult also:
- [Troubleshooting Guide](https://samsung.github.io/qaboard/docs/backend-admin/troubleshooting).
- To learn how to restore from a backup, read the [upgrade guide](https://samsung.github.io/qaboard/docs/backend-admin/host-upgrades).

At SIRC:
```bash
sudo sysctl -w net.core.somaxconn=65536
```

## Overview
[sqlalchemy](http://docs.sqlalchemy.org/en/latest/orm/tutorial.html) maps our classes (defined in [/models](models/)) to database tables:
Expand Down
20 changes: 16 additions & 4 deletions backend/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from flask_cors import CORS
app = Flask(__name__)

# This would be needed to use flask's sessions (e.g. display flash messages after redirects...)
# However we never used this feature as (1) the backend is stateless and (2) the client uses an API, now generated views.
# app.secret_key = os.environ.get('QABOARD_FLASK_SECRET_KEY', 'xxxxxxxxxxx')
# This key will be used to sign session cookies
# To generate a key: python -c 'import os; print(os.urandom(16))'
app.secret_key = os.environ.get('SECRET_KEY', 'please-generate-your-own-secret-key')

# Provide easy access to our git repositories
from .git_utils import Repos
Expand All @@ -24,15 +24,27 @@ def shutdown_session(exception=None):
db_session.remove()

import backend.api.api
import backend.api.commit
import backend.api.batch
import backend.api.outputs
import backend.api.webhooks
import backend.api.integrations
import backend.api.tuning
import backend.api.export_to_folder
import backend.api.auto_rois
import backend.api.milestones
import backend.api.auth

# Enable cross-origin requests to avoid development headcaches
# cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
CORS(app)

Base.metadata.create_all(engine)
Base.metadata.create_all(engine)

# Avoids errors
# > sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) lost synchronization with server: got message type " "
# https://docs.sqlalchemy.org/en/13/core/pooling.html#pooling-multiprocessing
# https://stackoverflow.com/questions/43648075/uwsgi-flask-sqlalchemy-intermittent-postgresql-errors-with-warning-there-is-al
# https://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#preforking-vs-lazy-apps-vs-lazy
# https://stackoverflow.com/questions/41279157/connection-problems-with-sqlalchemy-and-multiple-processes
engine.dispose()
202 changes: 32 additions & 170 deletions backend/backend/api/api.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
"""
Simple REST API to list the objects in our database.
Access data related to Projects.
"""
import sys
import datetime
import pytz
import subprocess
import json
from pathlib import Path
import datetime

import ujson
from gitdb.exc import BadName
from flask import request, jsonify, make_response, redirect
from flask import request, jsonify, make_response

from sqlalchemy import func, and_, asc, or_
from sqlalchemy.orm import joinedload, selectinload
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from sqlalchemy.orm import selectinload

from sqlalchemy.orm.attributes import flag_modified
from sqlalchemy.sql import label

from backend import app, db_session
from ..models import Project, CiCommit, Batch, Output
from ..models import latest_successful_commit

from ..utils import profiled


to_datetime = lambda s: timezone.localize(datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%fZ'))
Expand Down Expand Up @@ -61,17 +56,20 @@ def get_commits(branch=None):
from_date = min(latest_authored_datetime - (to_date - from_date), from_date)
from_date = from_date - datetime.timedelta(hours=3) # timezones as above


ci_commits = (db_session
.query(CiCommit)
.options(selectinload(CiCommit.batches).selectinload(Batch.outputs))
.filter(
CiCommit.authored_datetime >= from_date,
CiCommit.authored_datetime <= to_date,
CiCommit.project_id == project_id,
)
.order_by(CiCommit.authored_datetime.desc())
)
with_outputs = False if request.args.get('with_outputs', 'false')=='false' else True
ci_commits = db_session.query(CiCommit)
if True: # with_outputs: do this when we pre-aggregated counts of Outputs per status...
ci_commits = ci_commits.options(selectinload(CiCommit.batches).selectinload(Batch.outputs))
else:
ci_commits = ci_commits.options(selectinload(CiCommit.batches))
ci_commits = (ci_commits
.filter(
CiCommit.authored_datetime >= from_date,
CiCommit.authored_datetime <= to_date,
CiCommit.project_id == project_id,
)
.order_by(CiCommit.authored_datetime.desc())
)

if committer_name:
ci_commits = ci_commits.filter_by(committer_name=committer_name)
Expand All @@ -80,6 +78,9 @@ def get_commits(branch=None):


metrics_to_aggregate = json.loads(request.args.get('metrics', '{}'))
if project_id.startswith("CDE-Users/HW_ALG"): # too many results to be fast...
with_aggregation = {}

with_batches = None
batch = request.args.get('batch', None)
if batch:
Expand All @@ -88,11 +89,16 @@ def get_commits(branch=None):
only_ci_batches = False if request.args.get('only_ci_batches', 'false')=='false' else True
if only_ci_batches:
with_batches = ['default']
with_outputs = False if request.args.get('with_outputs', 'false')=='false' else True
# from ..utils import profiled
serializable_commits = []
# with profiled():
serializable_commits = [c.to_dict(with_aggregation=metrics_to_aggregate, with_batches=with_batches, with_outputs=with_outputs)
for c in ci_commits]
for c in ci_commits.limit(1000):
if not c.batches:
continue
serializable_commits.append(c.to_dict(
with_aggregation=metrics_to_aggregate,
with_batches=with_batches,
with_outputs=with_outputs
))
response = make_response(ujson.dumps(serializable_commits))
response.headers['Content-Type'] = 'application/json'
return response
Expand All @@ -110,7 +116,6 @@ def get_branches():
return jsonify([b[0] for b in branches])



@app.route("/api/v1/projects")
def get_projects():
projects = (db_session
Expand Down Expand Up @@ -151,147 +156,4 @@ def get_project():
return jsonify(project.data)


@app.route("/api/v1/output/<output_id>", methods=['GET', 'DELETE'])
@app.route("/api/v1/output/<output_id>/", methods=['GET', 'DELETE'])
def crud_output(output_id):
output = Output.query.filter(Output.id==output_id).one()
if request.method == 'GET':
return jsonify(output.to_dict())
if request.method == 'DELETE':
if output.is_pending:
return {"error": "Please wait for the Output to finish running before deleting it"}, 500
output.delete(soft=False)
db_session.delete(output)
db_session.commit()
return {"status": "OK"}


@app.route("/api/v1/output/<output_id>/manifest", methods=['GET'])
@app.route("/api/v1/output/<output_id>/manifest/", methods=['GET'])
def get_output_manifest(output_id):
output = Output.query.filter(Output.id==output_id).one()
if output.is_running or request.args.get('refresh'):
manifest = output.update_manifest(compute_hashes=False)
return jsonify(manifest)
else:
return redirect(f"{output.output_dir_url}/manifest.outputs.json", code=302)





@app.route("/api/v1/commit", methods=['GET', 'POST'])
@app.route("/api/v1/commit/", methods=['GET', 'POST'])
@app.route("/api/v1/commit/<path:commit_id>", methods=['GET', 'POST'])
def api_ci_commit(commit_id=None):
if request.method == 'POST':
hexsha = request.json.get('commit_sha', request.json['git_commit_sha']) if not commit_id else commit_id
try:
commit = CiCommit.get_or_create(
session=db_session,
hexsha=hexsha,
project_id=request.json['project'],
data=request.json,
)
except:
return f"404 ERROR:\n ({request.json['project']}): There is an issue with your commit id ({request.json['git_commit_sha']})", 404
if not commit.data:
commit.data = {}
# Clients can store any metadata with each commit.
# We've been using it to store code quality metrics per subproject in our monorepo,
# Then we use other tools (e.g. metabase) to create dashboards.
commit_data = request.json.get('data', {})
commit.data = {**commit.data, **commit_data}
flag_modified(commit, "data")
if commit.deleted:
commit.deleted = False
db_session.add(commit)
db_session.commit()
return jsonify({"status": "OK"})


project_id = request.args['project']
if not commit_id:
commit_id = request.args.get('commit', None)
try:
project = Project.query.filter(Project.id==project_id).one()
default_branch = project.data['qatools_config']['project']['reference_branch']
except:
default_branch = 'master'
branch = request.args.get('branch', default_branch)
ci_commit = latest_successful_commit(db_session, project_id=project_id, branch=branch, batch_label=request.args.get('batch'))
if not ci_commit:
return jsonify({'error': f'Sorry, we cant find any commit with results for the {project_id} on {branch}.'}), 404
else:
try:
ci_commit = (db_session
.query(CiCommit)
.options(
joinedload(CiCommit.batches).
joinedload(Batch.outputs)
)
.filter(
CiCommit.project_id==project_id,
CiCommit.hexsha.startswith(commit_id),
)
.one()
)
except NoResultFound:
try:
# TODO: This is a valid use case for having read-rights to the repo,
# we can identify a commit by the tag/branch
# To replace this without read rights, we should listen for push events and build a database
project = Project.query.filter(Project.id==project_id).one()
commit = project.repo.tags[commit_id].commit
try:
commit = project.repo.commit(commit_id)
except:
try:
commit = project.repo.refs[commit_id].commit
except:
commit = project.repo.tags[commit_id].commit
ci_commit = CiCommit(commit, project=project)
db_session.add(ci_commit)
db_session.commit()
except:
return jsonify({'error': f'Sorry, we could not find any data on commit {commit_id} in project {project_id}.'}), 404
except BadName:
return jsonify({f'error': f'Sorry, we could not understand the commid ID {commit_id} for project {project_id}.'}), 404
except Exception as e:
raise(e)
return jsonify({'error': 'Sorry, the request failed.'}), 500

batch = request.args.get('batch', None)
with_batches = [batch] if batch else None # by default we show all batches
with_aggregation = json.loads(request.args.get('metrics', '{}'))
response = make_response(ujson.dumps(ci_commit.to_dict(with_aggregation, with_batches=with_batches, with_outputs=True)))
response.headers['Content-Type'] = 'application/json'
return response


@app.route("/api/v1/commit/save-artifacts/", methods=['POST'])
@app.route("/api/v1/commit/save-artifacts", methods=['POST'])
def commit_save_artifacts():
hexsha = request.json.get('hexsha')
try:
ci_commits = (db_session
.query(CiCommit)
.filter(
CiCommit.hexsha == hexsha,
)
)
except:
return f"404 ERROR:\n ({request.json['project']}): There is an issue with your commit id ({hexsha})", 404
for ci_commit in ci_commits.all():
if not request.json['project'].startswith(ci_commit.project_id):
print(f'skip {ci_commit.project_id}')
continue
print(f"[save-artifacts] {ci_commit}")
# FIXME: in the clean crontab we remove commits without runs
# if we rely on artifacts from a subproject without runs, it will cause issues...
# we should use the git info to find the qatools.yaml
ci_commit.save_artifacts()
ci_commit.deleted = False
db_session.add(ci_commit)
db_session.commit()
return 'OK'
Loading