Code cleanup

This commit is contained in:
allegroai 2024-03-18 15:52:22 +02:00
parent 5749ff0454
commit e8ee6ce72e
5 changed files with 24 additions and 16 deletions

View File

@ -374,7 +374,7 @@ class EventBLL(object):
if invalid_iterations_count:
raise BulkIndexError(
f"{invalid_iterations_count} document(s) failed to index.",
[invalid_iteration_error],
[{"_index": invalid_iteration_error}],
)
if not added:

View File

@ -869,7 +869,7 @@ class ProjectBLL:
company,
project_ids: Sequence[str],
user_ids: Optional[Sequence[str]] = None,
) -> Set[str]:
) -> Set[Union[str, type(None)]]:
"""
Get the set of user ids that created tasks/models in the given projects
If project_ids is empty then all projects are examined

View File

@ -1297,7 +1297,6 @@ class GetMixin(PropsMixin):
return result
class UpdateMixin(object):
__user_set_allowed_fields = None
__locked_when_published_fields = None

View File

@ -113,7 +113,7 @@ class TestProjectTags(TestService):
new_tags = ["New model tag"]
self.api.models.update_tags(ids=[model], add_tags=new_tags)
data = self.api.projects.get_model_tags(projects=[p])
self.assertEqual(set(data.tags), set([*new_tags, *initial_tags]))
self.assertEqual(set(data.tags), {*new_tags, *initial_tags})
def new_task(self, **kwargs):
self.update_missing(

View File

@ -7,13 +7,17 @@ from humanfriendly import parse_timespan
def setup():
from apiserver.database import db
db.initialize()
def gen_token(args):
from apiserver.bll.auth import AuthBLL
resp = AuthBLL.get_token_for_user(args.user_id, args.company_id, parse_timespan(args.expiration))
print('Token:\n%s' % resp.token)
resp = AuthBLL.get_token_for_user(
args.user_id, args.company_id, int(parse_timespan(args.expiration))
)
print("Token:\n%s" % resp.token)
def safe_get(obj, glob, default=None, separator="/"):
@ -23,19 +27,24 @@ def safe_get(obj, glob, default=None, separator="/"):
return default
if __name__ == '__main__':
if __name__ == "__main__":
top_parser = ArgumentParser(__doc__)
subparsers = top_parser.add_subparsers(title='Sections')
subparsers = top_parser.add_subparsers(title="Sections")
token = subparsers.add_parser('token')
token_commands = token.add_subparsers(title='Commands')
token_create = token_commands.add_parser('generate', description='Generate a new token')
token_create.add_argument('--user-id', '-u', help='User ID', required=True)
token_create.add_argument('--company-id', '-c', help='Company ID', required=True)
token_create.add_argument('--expiration', '-exp',
help="Token expiration (time span, shorthand suffixes are supported, default 1m)",
default=parse_timespan('1m'))
token = subparsers.add_parser("token")
token_commands = token.add_subparsers(title="Commands")
token_create = token_commands.add_parser(
"generate", description="Generate a new token"
)
token_create.add_argument("--user-id", "-u", help="User ID", required=True)
token_create.add_argument("--company-id", "-c", help="Company ID", required=True)
token_create.add_argument(
"--expiration",
"-exp",
help="Token expiration (time span, shorthand suffixes are supported, default 1m)",
default=parse_timespan("1m"),
)
token_create.set_defaults(_func=gen_token)
args = top_parser.parse_args()