Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ch-59
Browse files Browse the repository at this point in the history
  • Loading branch information
condar-metacell committed Sep 16, 2024
2 parents ba176c9 + 7761fe5 commit c019423
Show file tree
Hide file tree
Showing 135 changed files with 1,091 additions and 988 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint Check

on:
push

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install autopep8
run: pip install autopep8

- name: Run lint-check.sh
run: bash lint-check.sh
3 changes: 1 addition & 2 deletions application-templates/base/test/api/test_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import schemathesis as st
from schemathesis.checks import response_schema_conformance, not_a_server_error

from cloudharness_test import apitest_init # include to perform default authorization
from cloudharness_test import apitest_init # include to perform default authorization

app_url = os.environ.get("APP_URL", "http://samples.ch.local/api")

Expand All @@ -15,4 +15,3 @@ def test_ping(case):
response = case.call()
pprint(response.__dict__)
assert response.status_code == 200, "this api errors on purpose"

5 changes: 3 additions & 2 deletions application-templates/django-app/api/test_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import schemathesis as st
from schemathesis.checks import response_schema_conformance, not_a_server_error

from cloudharness_test import apitest_init # include to perform default authorization
from cloudharness_test import apitest_init # include to perform default authorization

app_url = os.environ.get("APP_URL", "http://samples.ch.local/api")

Expand All @@ -20,8 +20,9 @@ def test_ping(case):
pprint(response.__dict__)
assert response.status_code == 200, "this api errors on purpose"


def test_state_machine():
schema.as_state_machine().run()
# APIWorkflow = schema.as_state_machine()
# APIWorkflow.run()
# TestAPI = APIWorkflow.TestCase
# TestAPI = APIWorkflow.TestCase
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import __APP_NAME__.controllers.test as test_controller
import __APP_NAME__.controllers.test as test_controller
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@
# ***********************************************************************
# * __APP_NAME__ settings
# ***********************************************************************
from cloudharness.applications import get_configuration
from cloudharness.utils.config import ALLVALUES_PATH, CloudharnessConfig
from cloudharness.applications import get_configuration # noqa E402
from cloudharness.utils.config import ALLVALUES_PATH, CloudharnessConfig # noqa E402

# ***********************************************************************
# * import base CloudHarness Django settings
# ***********************************************************************
from cloudharness_django.settings import *
from cloudharness_django.settings import * # noqa E402

# add the local apps
INSTALLED_APPS += [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import api.controllers.test as test_controller
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
application = get_asgi_application()

# init the auth service
from cloudharness_django.services import init_services
from cloudharness_django.services import init_services # noqa E402

init_services()

# start the kafka event listener
import cloudharness_django.services.events
import cloudharness_django.services.events # noqa E402
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

urlpatterns = [path("admin/", admin.site.urls)]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + \
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += [re_path(r"^(?P<path>.*)$", index, name="index")]

admin.site.site_header = "__APP_NAME__ Admin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
application = get_wsgi_application()

# init the auth service
from cloudharness_django.services import init_services
from cloudharness_django.services import init_services # noqa E402

init_services()

# start the kafka event listener
import cloudharness_django.services.events
import cloudharness_django.services.events # noqa E402
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@

if __name__ == '__main__':
main()

1 change: 0 additions & 1 deletion application-templates/flask-server/backend/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
__APP_NAME__
"""
)

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@

if __name__ == '__main__':
main()

19 changes: 0 additions & 19 deletions application-templates/webapp/frontend/.eslintrc.cjs

This file was deleted.

56 changes: 56 additions & 0 deletions application-templates/webapp/frontend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'


export default tseslint.config(
{
ignores: [
'dist',
'node_modules',
'.yalc',
'src/rest/*' // do not lint generated code
]
},
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx,js,jsx}'],
languageOptions: {
ecmaVersion: "latest",
globals: globals.browser,
sourceType: "module"
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
indent: ["error", 2, {
SwitchCase: 1,
}],
curly: "error", // enforce braces for one-line blocks
"no-tabs": "error", // enforce no tabs
"no-console": ["warn", {
allow: ["warn", "error", "debug"],
}],
"@typescript-eslint/no-explicit-any": "off", // No strict typing (annoying especially with React elements and events callbacks)
"consistent-return": "warn", // https://eslint.org/docs/latest/rules/consistent-return
"prefer-arrow-callback": ["warn"],
"object-curly-spacing": ["warn", "always"], // enforce consistent spacing inside braces
"func-style": "off", // function expressions or arrow functions are equally valid
"no-unneeded-ternary": "warn", // disallow unnecessary ternary expressions
// React rules: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules
"react/prop-types": "off", // PropTypes are not forced
"react/forbid-prop-types": "off", // all PropTypes are allowed
"react-hooks/rules-of-hooks": "error", // https://react.dev/reference/rules/rules-of-hooks
"react-hooks/exhaustive-deps": "warn", // Hooks dependency array, sometimes it's better to ignore
},
}
)
3 changes: 2 additions & 1 deletion application-templates/webapp/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start:dev": "DOMAIN=https://test.ch.metacell.us vite",
"start:local": "DOMAIN=http://samples.ch vite",
"prebuild": "eslint .",
"build": "vite build"
"build": "vite build",
"lint": "eslint src --report-unused-disable-directives --fix"
}
}
2 changes: 1 addition & 1 deletion applications/common/server/common/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from common.controllers.sentry_controller import global_dsn



def init_fn(app):
log.info("initializing database from app")
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
if not global_dsn:
open_db(app)


app = init_flask(init_app_fn=init_fn)

if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion applications/common/server/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Config(object):
log.error("Cannot configure SENTRY")



class ProductionConfig(Config):
DEBUG = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cloudharness import applications
from cloudharness.utils.config import CloudharnessConfig


def get_config(): # noqa: E501
"""
Gets the config for logging in into accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cloudharness.utils.config import CloudharnessConfig
from cloudharness_model.models import HarnessMainConfig


def get_version(): # noqa: E501
"""get_version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from typing import List


Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
except:
global_dsn = None


def getdsn(appname): # noqa: E501
"""
Gets the Sentry DSN for a given application or returns the global dsn when set
Expand Down
2 changes: 1 addition & 1 deletion applications/common/server/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def __init__(self, url, result_all, result_no_stop_words):
self.result_no_stop_words = result_no_stop_words

def __repr__(self):
return '<id {}>'.format(self.id)
return '<id {}>'.format(self.id)
34 changes: 19 additions & 15 deletions applications/common/server/common/repository/sentry.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@

import sqlalchemy
import sqlalchemy
from sqlalchemy.sql import text

from cloudharness.utils.env import get_service_public_address

from .db import get_db


class SentryProjectNotFound(Exception):
pass


def _get_api_token():
# ToDo: may be we can use here a dynamic token, but for now let's use a hard coded one
api_token = 'afe75d802007405dbc0c2fb1db4cc8b06b981017f58944d0afac700f743ee06a'
s = text('''
select token from sentry_apitoken
where token=:api_token
''')
token = get_db().engine.execute(s,
api_token=api_token
).fetchall()
token = get_db().engine.execute(s,
api_token=api_token
).fetchall()
if len(token) == 0:
# token is not present in the Sentry database, let's create it
s = text('''
insert into sentry_apitoken(user_id, token, scopes, date_added, scope_list)
values (1, :api_token, 0, now(), :scope_list)
''')
get_db().engine.execute(s,
api_token=api_token,
scope_list='{event:admin,event:read,'
'member:read,member:admin,'
'project:read,project:releases,project:admin,project:write,'
'team:read,team:write,team:admin,'
'org:read,org:write,org:admin}'
)
get_db().engine.execute(s,
api_token=api_token,
scope_list='{event:admin,event:read,'
'member:read,member:admin,'
'project:read,project:releases,project:admin,project:write,'
'team:read,team:write,team:admin,'
'org:read,org:write,org:admin}'
)
return _get_api_token()
else:
# return the first column from the first row of the query result
return token[0][0]


def get_token():
return _get_api_token()


def get_dsn(appname):
s = text('''
select public_key, p.id
Expand All @@ -49,9 +53,9 @@ def get_dsn(appname):
where p.slug=:project_slug
''')
try:
public_key = get_db().engine.execute(s,
project_slug=appname
).fetchall()
public_key = get_db().engine.execute(s,
project_slug=appname
).fetchall()
except sqlalchemy.exc.OperationalError:
raise SentryProjectNotFound('Sentry is not initialized.')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_getdsn(self):
Gets the Sentry DSN for a given application
"""
headers = {
headers = {
'Accept': 'application/json',
}
response = self.client.open(
Expand Down
8 changes: 4 additions & 4 deletions applications/common/server/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def deserialize_date(string):
:rtype: date
"""
if string is None:
return None
return None

try:
from dateutil.parser import parse
return parse(string).date()
Expand All @@ -88,8 +88,8 @@ def deserialize_datetime(string):
:rtype: datetime
"""
if string is None:
return None
return None

try:
from dateutil.parser import parse
return parse(string)
Expand Down
1 change: 0 additions & 1 deletion applications/common/server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
Cloud Harness Platform - Reference CH service API
"""
)

Loading

0 comments on commit c019423

Please sign in to comment.