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

File upload #50

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 17 additions & 1 deletion bg_utils/mongo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
StringField,
CASCADE,
PULL,
FileField,
)
from mongoengine.errors import DoesNotExist

Expand All @@ -39,6 +40,7 @@
Instance as BrewtilsInstance,
Parameter as BrewtilsParameter,
Request as BrewtilsRequest,
RequestFile as BrewtilsRequestFile,
System as BrewtilsSystem,
Event as BrewtilsEvent,
Principal as BrewtilsPrincipal,
Expand All @@ -62,6 +64,7 @@
"Role",
"RefreshToken",
"Job",
"RequestFile",
"RequestTemplate",
"DateTrigger",
"CronTrigger",
Expand Down Expand Up @@ -131,7 +134,7 @@ def clean(self):


class Parameter(EmbeddedDocument, BrewtilsParameter):
"""Mongo-Backed BREWMASTER Parameter Object"""
"""Mongo-Backed brewtils parameter object"""

key = StringField(required=True)
type = StringField(required=True, default="Any", choices=BrewtilsParameter.TYPES)
Expand All @@ -149,6 +152,7 @@ class Parameter(EmbeddedDocument, BrewtilsParameter):
required=False, choices=BrewtilsParameter.FORM_INPUT_TYPES
)
parameters = ListField(EmbeddedDocumentField("Parameter"))
type_info = DictField(required=False)

# If no display name was set, it will default it to the same thing as the key
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -409,6 +413,18 @@ def find_or_none(system_id):
return None


class RequestFile(Document, BrewtilsRequestFile):
"""Mongo backed request file resource"""

STORAGE_ENGINES = ["gridfs"]

storage_type = StringField(required=True, default="gridfs")
filename = StringField(required=True)
body = FileField(required=True)
created_at = DateTimeField(default=datetime.datetime.utcnow, required=True)
request = ReferenceField("Request", reverse_delete_rule=CASCADE)


class System(Document, BrewtilsSystem):
"""Mongo-Backed BREWMASTER System Object"""

Expand Down
2 changes: 2 additions & 0 deletions bg_utils/mongo/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
RefreshToken,
Job,
RequestTemplate,
RequestFile,
DateTrigger,
IntervalTrigger,
CronTrigger,
Expand All @@ -34,6 +35,7 @@ class MongoParser(SchemaParser):
"CommandSchema": Command,
"ParameterSchema": Parameter,
"RequestSchema": Request,
"RequestFileSchema": RequestFile,
"RequestTemplateSchema": RequestTemplate,
"ChoicesSchema": Choices,
"EventSchema": Event,
Expand Down
1 change: 1 addition & 0 deletions bg_utils/mongo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def _ensure_roles():
name="bg-plugin",
description="Allows actions necessary for plugins to function",
permissions=[
"bg-file-read",
"bg-instance-update",
"bg-job-create",
"bg-job-update",
Expand Down
6 changes: 3 additions & 3 deletions test/unit/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def test_correctness(self, tmpdir, spec):
config_file = os.path.join(str(tmpdir), "config.yaml")
logging_config_file = os.path.join(str(tmpdir), "logging.json")

bg_utils.generate_config_file(spec, [
"-c", config_file, "-l", logging_config_file
])
bg_utils.generate_config_file(
spec, ["-c", config_file, "-l", logging_config_file]
)

spec.add_source(label="config_file", source_type="yaml", filename=config_file)
config = spec.load_config("config_file")
Expand Down