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

feat: import resources from git repo or archive file #628

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ed01570
feat: import resources from git repo or archive file
keithmanville Oct 18, 2024
fa23b1c
feat: add json schema to validate dioptra toml
keithmanville Sep 24, 2024
f0a49e9
feat: implement overwrite name conflict resolution strategy
keithmanville Oct 18, 2024
919295e
feat: implement readOnly flag for import workflow
keithmanville Oct 18, 2024
30d33cd
docs: added resource import toml reference
keithmanville Sep 24, 2024
42f0817
fix: bug related to using newly created plugin param type
keithmanville Sep 25, 2024
a87bda5
feat: updated example to use new plugin param type
keithmanville Sep 25, 2024
4d8364d
tests: test resource import workflow
keithmanville Dec 24, 2024
e02f943
fix: revert overwrite and readonly
keithmanville Oct 25, 2024
c97fe20
tests: added tests
keithmanville Dec 24, 2024
f5ad53a
refactor: refactor resource import workflow
keithmanville Oct 30, 2024
0210432
docs: added docstrings and type annotations
keithmanville Oct 31, 2024
c5a6a36
refactor: placed files needed for tests under tests dir
keithmanville Oct 31, 2024
f641e2a
bug: properly handle temporary file and file cleanup
keithmanville Oct 31, 2024
e665d8a
fix: bug where data_key was not used for form data
keithmanville Nov 13, 2024
832bedb
docs: updated import workflow reference to match example
keithmanville Nov 13, 2024
6001ea3
chore: removed commented code
keithmanville Nov 13, 2024
2736644
fix: prevent git clone from prompting for credentials
keithmanville Nov 13, 2024
318e7ab
fix: handle file upload and git clone errors
keithmanville Nov 13, 2024
3d75674
tests: fix missing decorator after rebase
keithmanville Dec 24, 2024
96fb3f2
feat(restapi): add custom errors for import workflow
keithmanville Dec 24, 2024
32e06d9
feat(client): wip on updating client for import workflow
keithmanville Dec 24, 2024
9fdc6d6
build: add types-toml to mypy tox environment
keithmanville Jan 15, 2025
51c022b
feat(client): add resource import workflow to client
keithmanville Jan 15, 2025
fc97c56
feat: add support for multi-file uploads to resource import workflow
keithmanville Jan 15, 2025
81b398a
fix: updated paths to resource files used in tests
keithmanville Jan 16, 2025
b53f9f7
fix: fix path for windows
keithmanville Jan 16, 2025
c9e02a3
fix: handle tmp file deletion manually
keithmanville Jan 16, 2025
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
37 changes: 37 additions & 0 deletions dioptra.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[[plugins]]
path = "plugins/hello_world"
description = "A simple plugin used for testing and demonstration purposes."


[[plugins.tasks]]
filename = "tasks.py"
name = "hello"
input_params = [ { name = "name", type = "string", required = true} ]
output_params = [ { name = "greeting", type = "message" } ]

[[plugins.tasks]]
filename = "tasks.py"
name = "greet"
input_params = [
{ name = "greeting", type = "string", required = true },
{ name = "name", type = "string", required = true },
]
output_params = [ { name = "greeting", type = "message" } ]

[[plugins.tasks]]
filename = "tasks.py"
name = "shout"
input_params = [ { name = "greeting", type = "message", required = true} ]
output_params = [ { name = "loud_greeting", type = "message" } ]

[[plugin_param_types]]
name = "message"

[[entrypoints]]
path = "examples/hello-world.yaml"
name = "Hello World"
description = "A simple example using the hello_world plugin."
params = [
{ name = "name", type = "string", default_value = "World" }
]
plugins = [ "hello_world" ]
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Email us: [email protected]
:caption: Reference

reference/task-engine-reference
reference/resource-import-reference
reference/api-reference-restapi
.. reference/api-reference-sdk
reference/api-reference-client
Expand Down
207 changes: 207 additions & 0 deletions docs/source/reference/resource-import-reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
===========================
Resource Import Reference
===========================

This document describes the contract for importing resources into a Dioptra instance.

.. contents::

Overview
========

Dioptra provides functionality for importing Plugins, Entrypoints, and
PluginParameterTypes. This allows users to easily publish and share
resources across Dioptra instances. It is also the mechanism used to
distribute core plugins and examples developed by the Dioptra maintainers.

Resources are described via a combination of a TOML configuration file,
Python source code (for plugins), and YAML task graphs (for entrypoints).
The TOML file is the central configuration that references required sources
and includes metadata for fully registering the resources in Dioptra (such
as plugin task specifications, and entrypoint parameters).

Collections of resources can be distributed via git repositories or by sharing
files manually. The resourceImport workflow can import from a repository or
archive file. See the API Reference for details.

TOML Configuration Format
=========================

The TOML format consists of three arrays of tables, one for each of the
importable resource types: Plugins, PluginParameterTypes, and Entrypoints.
This allows for importing of zero or more of each of these resources.

Example
-------

The following example illustrates how to configure a collection of resources
including a Plugin, PluginParameterType, and Entrypoint.

.. code:: TOML
keithmanville marked this conversation as resolved.
Show resolved Hide resolved

# Plugins point to a python package and include metadata for registering them in Dioptra
[[plugins]]
# the path to the Python plugin relative to the root directory
path = "plugins/hello_world"
# an optional description
description = "A simple plugin used for testing and demonstration purposes."

# an array of plugin task definitions
[[plugins.tasks]]
# the name of the file relative to the root plugin directory
filename = "tasks.py"
# the name must match the name of the function
name = "hello"
# input parameter names must match the Python function definition
# types are plugin parameter types and are matched by name
input_params = [ { name = "name", type = "string", required = true} ]
output_params = [ { name = "message", type = "message" } ]

[[plugins.tasks]]
filename = "tasks.py"
name = "greet"
input_params = [
{ name = "greeting", type = "string", required = true },
{ name = "name", type = "string", required = true },
]
output_params = [ { name = "message", type = "message" } ]

[[plugins.tasks]]
filename = "tasks.py"
name = "shout"
input_params = [ { name = "message", type = "message", required = true} ]
output_params = [ { name = "message", type = "message" } ]

# PluginParameterTypes are fully described in the TOML
[[plugin_param_types]]
name = "message"

# Entrypoints point to a task graph yaml and include metadata for registering them in Dioptra
[[entrypoints]]
# path to the task graph yaml
path = "examples/hello-world.yaml"
# the name to register the entrypoint under (the task graph filename is use if not provided)
name = "Hello World"
# an optional description
description = "A simple example using the hello_world plugin."
# entrypoint parameters to register that should match the task graph
# here, type is an entrypoint parameter type, NOT a plugin parameter type
params = [
{ name = "name", type = "string", default_value = "World" }
]
# plugins to register with the entrypoint (matched by name)
plugins = [ "hello_world" ]


JSON Schema
-----------

The following JSON schema fully describes the Dioptra resource TOML.
It is used to validate Dioptra TOML files in the resource import workflow.

.. code:: JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/usnistgov/dioptra",
"title": "Dioptra Resource Schema",
"description": "A schema defining objects that can be imported into a Dioptra instance.",
"type": "object",
"properties": {
"plugins": {
"type": "array",
"description": "An array of Dioptra plugins",
"items": {
"type": "object",
"description": "A Dioptra plugin",
"properties": {
"path": { "type": "string" },
"description": { "type": "string" },
"tasks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"name": { "type": "string" },
"input_params": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" },
"required": { "type": "boolean" }
},
"required": [ "name", "type" ],
"additionalProperties": false
}
},
"output_params": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" }
},
"required": [ "name", "type" ],
"additionalProperties": false
}
}
},
"required": [ "filename", "name", "input_params", "output_params" ],
"additionalProperties": false
}
}
},
"required": [ "path" ],
"additionalProperties": false
}
},
"plugin_param_types": {
"type": "array",
"description": "An array of Dioptra plugin parameter types",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"structure": { "type": "object" }
},
"required": [ "name" ],
"additionalProperties": false
}
},
"entrypoints": {
"type": "array",
"description": "An array of Dioptra entrypoints",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"name": { "type": "string" },
"description": { "type": "string" },
"params": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" },
"default_value": { "type": [ "string", "number", "boolean", "null" ] }
},
"required": [ "name", "type" ],
"additionalProperties": false
}
},
"plugins": {
"type": "array",
"items": { "type": "string" }
}
},
"required": [ "path" ],
"additionalProperties": false
}
}
}
}
10 changes: 10 additions & 0 deletions examples/hello-world.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
hello_step:
hello:
name: $name
goodbye_step:
greet:
greeting: Goodbye
name: $name
shout_step:
shout:
greeting: $goodbye_step.greeting
16 changes: 16 additions & 0 deletions plugins/hello_world/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This Software (Dioptra) is being made available as a public service by the
# National Institute of Standards and Technology (NIST), an Agency of the United
# States Department of Commerce. This software was developed in part by employees of
# NIST and in part by NIST contractors. Copyright in portions of this software that
# were developed by NIST contractors has been licensed or assigned to NIST. Pursuant
# to Title 17 United States Code Section 105, works of NIST employees are not
# subject to copyright protection in the United States. However, NIST may hold
# international copyright in software created by its employees and domestic
# copyright (or licensing rights) in portions of software that were assigned or
# licensed to NIST. To the extent that NIST holds copyright in this software, it is
# being made available under the Creative Commons Attribution 4.0 International
# license (CC BY 4.0). The disclaimers of the CC BY 4.0 license apply to all parts
# of the software developed or licensed by NIST.
#
# ACCESS THE FULL CC BY 4.0 LICENSE HERE:
# https://creativecommons.org/licenses/by/4.0/legalcode
41 changes: 41 additions & 0 deletions plugins/hello_world/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This Software (Dioptra) is being made available as a public service by the
# National Institute of Standards and Technology (NIST), an Agency of the United
# States Department of Commerce. This software was developed in part by employees of
# NIST and in part by NIST contractors. Copyright in portions of this software that
# were developed by NIST contractors has been licensed or assigned to NIST. Pursuant
# to Title 17 United States Code Section 105, works of NIST employees are not
# subject to copyright protection in the United States. However, NIST may hold
# international copyright in software created by its employees and domestic
# copyright (or licensing rights) in portions of software that were assigned or
# licensed to NIST. To the extent that NIST holds copyright in this software, it is
# being made available under the Creative Commons Attribution 4.0 International
# license (CC BY 4.0). The disclaimers of the CC BY 4.0 license apply to all parts
# of the software developed or licensed by NIST.
#
# ACCESS THE FULL CC BY 4.0 LICENSE HERE:
# https://creativecommons.org/licenses/by/4.0/legalcode
import structlog
from dioptra import pyplugs

LOGGER = structlog.get_logger()


@pyplugs.register()
def hello(name: str) -> str:
message = f"Hello, {name}"
LOGGER.info(message)
return message


@pyplugs.register()
def greet(greeting: str, name: str) -> str:
message = f"{greeting}, {name}"
LOGGER.info(message)
return message


@pyplugs.register()
def shout(greeting: str) -> str:
loud_greeting = greeting.upper()
LOGGER.info(loud_greeting)
return loud_greeting
Loading
Loading